Skip to content

Commit f98feb3

Browse files
authored
Merge pull request #102 from maiconrocha/main
Add Linux Example + overall enhancements
2 parents 8292d72 + 84900d7 commit f98feb3

25 files changed

+828
-109
lines changed

.project_automation/functional_tests/entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ fi
4747
post_entrypoint
4848

4949
#********** Exit Code *************
50-
exit $EXIT_CODE
50+
exit $EXIT_CODE

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,14 @@ Apache-2.0 Licensed. See [LICENSE](https://github.com/aws-ia/terraform-aws-ec2-i
7979

8080
| Name | Version |
8181
|------|---------|
82-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.7 |
83-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0.0, < 5.0.0 |
84-
| <a name="requirement_awscc"></a> [awscc](#requirement\_awscc) | >= 0.24.0 |
82+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.4.0 |
83+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0.0 |
8584

8685
## Providers
8786

8887
| Name | Version |
8988
|------|---------|
90-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.0.0, < 5.0.0 |
89+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0.0 |
9190

9291
## Modules
9392

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.0.0
1+
v0.0.1

examples/basic/.header.md

Whitespace-only changes.

examples/basic/README.md

Lines changed: 0 additions & 29 deletions
This file was deleted.

examples/basic/main.tf

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/basic/outputs.tf

Whitespace-only changes.

examples/basic/providers.tf

Lines changed: 0 additions & 21 deletions
This file was deleted.

examples/basic/variables.tf

Whitespace-only changes.

examples/linux/.header.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
2+
# Using the EC2 Image Builder Terraform Module to create an Linux AMI
3+
4+
This example will use the EC2 Image Builder Terraform Module to create an Amazon Linux 2023 Custom AMI.
5+
6+
The build components are currently all in a single file: linuxbuild.yaml
7+
The tests components are currently all in a single file: linuxtest.yaml
8+
9+
However the module supports providing multiple files, given the parameters build_component_arn and test_component_arn are of list of strings type.
10+
11+
The module cover the creation of the core components of the EC2 Image Builder, like Image Pipeline, Image Recipe, Distribution Configuration,
12+
Infrastructure Configuration, etc, but there are components which needs to be created outside of the module and provide as input, which are basically
13+
what it is going to be executed during the build and test process, and also custom IAM Policy with permissions required to interact with
14+
AWS services related to your build and test components.
15+
16+
This example creates the following resources:
17+
18+
- S3 Bucket
19+
- EC2 Image Builder Build Component, which executes the hello world powershell script
20+
- EC2 Image Builder Test Component, which executes the pester script which tests the output of the powershell hello world script
21+
- S3 Objects, which uploads the build and Test YAML Files to S3
22+
- IAM Policy with permissions to read/write to the S3 Bucket
23+
- VPC/Subnets/Route Tables/Nat Gateway/etc
24+
25+
## How to Deploy
26+
27+
### Prerequisites
28+
29+
Ensure that you have installed the following tools in your Mac or Windows Laptop before start working with this module and run Terraform Plan and Apply
30+
31+
1. [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html)
32+
2. [Terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli)
33+
34+
### Deployment Steps
35+
36+
#### Step 1: Clone the repo using the command below
37+
38+
```sh
39+
git clone https://github.com/aws-ia/terraform-aws-ec2-image-builder.git
40+
```
41+
42+
#### Step 2: Run Terraform INIT
43+
44+
Initialize a working directory with configuration files
45+
46+
```sh
47+
cd examples/linux/
48+
49+
terraform init
50+
```
51+
52+
#### Step 3: Run Terraform PLAN
53+
54+
Verify the resources created by this execution
55+
56+
```sh
57+
export AWS_REGION=<ENTER YOUR REGION> # default set to `us-west-2`
58+
terraform plan
59+
```
60+
61+
#### Step 4: Finally, Terraform APPLY
62+
63+
Create the resources
64+
65+
```sh
66+
terraform apply
67+
```
68+
69+
Enter `yes` to apply.
70+
71+
#### Step 5: Verify the AMI on AWS Console
72+
73+
Output of Terraform apply should look similar
74+
75+
```sh
76+
module.ec2-image-builder.aws_imagebuilder_image.imagebuilder_image[0]: Creation complete after 1h3m56s [id=arn:aws:imagebuilder:ap-southeast-2:XXXXXXXX:image/myfirstpipeline-image-recipe/0.0.2/1]
77+
```
78+
79+
Login to AWS Console, go to the AWS Region where resources are deployed, and go to the location showed on the Terraform output, for example:
80+
81+
EC2 Image Builder > Images > "myfirstpipeline-image-recipe 0.0.2" > "myfirstpipeline-image-recipe 0.0.2/1"
82+
83+
You can see the AMI ID on the output resources:
84+
85+
![AMI generated by EC2 Image Builder](../../images/outputresources.png)
86+
87+
## Cleanup
88+
89+
To clean up your environment, destroy the Terraform module.
90+
91+
*NOTE:* Empty the S3 bucket created by this module before executing the `terraform destroy`
92+
93+
```sh
94+
terraform destroy -auto-approve
95+
```

0 commit comments

Comments
 (0)