Skip to content

Commit 21f918a

Browse files
authored
fix: remove awscc references from provider (#103)
* fix: remove awscc references from provider * heredoc to jsonencode
1 parent f98feb3 commit 21f918a

File tree

10 files changed

+136
-149
lines changed

10 files changed

+136
-149
lines changed

.header.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The following is a basic example, see examples folder for more complete examples
2121

2222
```hcl
2323
module "ec2-image-builder" {
24-
source = "aws-ia/ec2-image-builder/aws"
24+
source = "aws-ia/ec2-image-builder/aws"
2525
name = "basic-ec2-image"
2626
vpc_id = "<ENTER_VPC_ID>"
2727
subnet_id = "<ENTER_SUBNET_ID>"

CONTRIBUTING.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ It is a best practice to perform these checks locally prior to submitting a pull
3030
- tfsec
3131
- Markdown Lint
3232
- Checkov
33-
- Terratest
33+
- Terraform test
3434

3535
> :bangbang: The readme.md file will be created after all checks have completed successfuly, it is recommended that you install terraform-docs locally in order to preview your readme.md file prior to publication.
3636
@@ -76,18 +76,6 @@ terraform plan -out tf.plan
7676
terraform show -json tf.plan > tf.json
7777
checkov
7878
```
79-
### Terratest
80-
81-
Include tests to validate your examples/<> root modules, at a minimum. This can be accomplished with usually only slight modifications to the [boilerplate test provided in this template](./test/examples\_basic\_test.go)
82-
83-
```
84-
# from the root of the repository
85-
cd test
86-
go mod init github.com/aws-ia/terraform-project-ephemeral
87-
go mod tidy
88-
go install github.com/gruntwork-io/terratest/modules/terraform
89-
go test -timeout 45m
90-
```
9179

9280
## Documentation
9381

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The following is a basic example, see examples folder for more complete examples
2222

2323
```hcl
2424
module "ec2-image-builder" {
25-
source = "aws-ia/ec2-image-builder/aws"
25+
source = "aws-ia/ec2-image-builder/aws"
2626
name = "basic-ec2-image"
2727
vpc_id = "<ENTER_VPC_ID>"
2828
subnet_id = "<ENTER_SUBNET_ID>"

examples/linux/README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,33 @@ This example creates the following resources:
2525

2626
## How to Deploy
2727

28-
### Prerequisites:
28+
### Prerequisites
29+
2930
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
3031

3132
1. [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html)
3233
2. [Terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli)
3334

3435
### Deployment Steps
36+
3537
#### Step 1: Clone the repo using the command below
3638

3739
```sh
3840
git clone https://github.com/aws-ia/terraform-aws-ec2-image-builder.git
3941
```
4042

4143
#### Step 2: Run Terraform INIT
44+
4245
Initialize a working directory with configuration files
4346

4447
```sh
4548
cd examples/linux/
49+
4650
terraform init
4751
```
4852

4953
#### Step 3: Run Terraform PLAN
54+
5055
Verify the resources created by this execution
5156

5257
```sh
@@ -55,6 +60,7 @@ terraform plan
5560
```
5661

5762
#### Step 4: Finally, Terraform APPLY
63+
5864
Create the resources
5965

6066
```sh
@@ -67,21 +73,20 @@ Enter `yes` to apply.
6773

6874
Output of Terraform apply should look similar
6975

70-
```
76+
```sh
7177
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]
7278
```
7379

7480
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:
7581

76-
EC2 Image Builder > Images > myfirstpipeline-image-recipe | 0.0.2 > myfirstpipeline-image-recipe | 0.0.2/1
82+
EC2 Image Builder > Images > "myfirstpipeline-image-recipe 0.0.2" > "myfirstpipeline-image-recipe 0.0.2/1"
7783

7884
You can see the AMI ID on the output resources:
7985

80-
<p align="center">
81-
<img src="../../images/outputresources.png" alt="AMI generated by EC2 Image Builder" width="100%">
82-
</p>
86+
![AMI generated by EC2 Image Builder](../../images/outputresources.png)
8387

8488
## Cleanup
89+
8590
To clean up your environment, destroy the Terraform module.
8691

8792
*NOTE:* Empty the S3 bucket created by this module before executing the `terraform destroy`
@@ -92,15 +97,19 @@ terraform destroy -auto-approve
9297

9398
## Requirements
9499

95-
No requirements.
100+
| Name | Version |
101+
|------|---------|
102+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.4.0 |
103+
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.0.0, < 4.0.0 |
104+
| <a name="requirement_tls"></a> [tls](#requirement\_tls) | >= 4.0.0, < 5.0.0 |
96105

97106
## Providers
98107

99108
| Name | Version |
100109
|------|---------|
101110
| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a |
102-
| <a name="provider_random"></a> [random](#provider\_random) | n/a |
103-
| <a name="provider_tls"></a> [tls](#provider\_tls) | n/a |
111+
| <a name="provider_random"></a> [random](#provider\_random) | >= 3.0.0, < 4.0.0 |
112+
| <a name="provider_tls"></a> [tls](#provider\_tls) | >= 4.0.0, < 5.0.0 |
104113

105114
## Modules
106115

examples/linux/main.tf

Lines changed: 97 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,23 @@ module "ec2-image-builder" {
7373
resource "aws_kms_key" "imagebuilder_image_recipe_kms_key" {
7474
description = "Imagebuilder Image Recipe KMS key"
7575
enable_key_rotation = true
76-
policy = <<POLICY
77-
{
78-
"Version": "2012-10-17",
79-
"Id": "default",
80-
"Statement": [
81-
{
82-
"Sid": "DefaultAllow",
83-
"Effect": "Allow",
84-
"Principal": {
85-
"AWS": "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
86-
},
87-
"Action": "kms:*",
88-
"Resource": "*"
89-
}
90-
]
91-
}
92-
POLICY
76+
policy = jsonencode(
77+
{
78+
"Version" : "2012-10-17",
79+
"Id" : "default",
80+
"Statement" : [
81+
{
82+
"Sid" : "DefaultAllow",
83+
"Effect" : "Allow",
84+
"Principal" : {
85+
"AWS" : "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
86+
},
87+
"Action" : "kms:*",
88+
"Resource" : "*"
89+
}
90+
]
91+
}
92+
)
9393
}
9494

9595
resource "aws_s3_object" "upload_scripts" {
@@ -105,23 +105,23 @@ resource "aws_s3_object" "upload_scripts" {
105105
resource "aws_kms_key" "aws_imagebuilder_component_kms_key" {
106106
description = "Imagebuilder Component KMS key"
107107
enable_key_rotation = true
108-
policy = <<POLICY
109-
{
110-
"Version": "2012-10-17",
111-
"Id": "default",
112-
"Statement": [
113-
{
114-
"Sid": "DefaultAllow",
115-
"Effect": "Allow",
116-
"Principal": {
117-
"AWS": "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
118-
},
119-
"Action": "kms:*",
120-
"Resource": "*"
121-
}
122-
]
123-
}
124-
POLICY
108+
policy = jsonencode(
109+
{
110+
"Version" : "2012-10-17",
111+
"Id" : "default",
112+
"Statement" : [
113+
{
114+
"Sid" : "DefaultAllow",
115+
"Effect" : "Allow",
116+
"Principal" : {
117+
"AWS" : "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
118+
},
119+
"Action" : "kms:*",
120+
"Resource" : "*"
121+
}
122+
]
123+
}
124+
)
125125
}
126126

127127
resource "aws_imagebuilder_component" "linuxbuild" {
@@ -216,36 +216,36 @@ data "aws_iam_policy_document" "iam_policy_document" {
216216
resource "aws_s3_bucket_policy" "bucket_policy" {
217217
bucket = aws_s3_bucket.ec2_image_builder_components.id
218218

219-
policy = <<EOF
220-
{
221-
"Version": "2012-10-17",
222-
"Statement": [
223-
{
224-
"Effect": "Allow",
225-
"Principal": {
226-
"AWS": "${data.aws_caller_identity.current.account_id}"
227-
},
228-
"Action": [ "s3:*" ],
229-
"Resource": [
230-
"${aws_s3_bucket.ec2_image_builder_components.arn}",
231-
"${aws_s3_bucket.ec2_image_builder_components.arn}/*"
232-
]
233-
},
219+
policy = jsonencode(
234220
{
235-
"Sid": "Deny non-HTTPS access",
236-
"Effect": "Deny",
237-
"Principal": "*",
238-
"Action": [ "s3:*" ],
239-
"Resource": "${aws_s3_bucket.ec2_image_builder_components.arn}/*",
240-
"Condition": {
241-
"Bool": {
242-
"aws:SecureTransport": "false"
221+
"Version" : "2012-10-17",
222+
"Statement" : [
223+
{
224+
"Effect" : "Allow",
225+
"Principal" : {
226+
"AWS" : "${data.aws_caller_identity.current.account_id}"
227+
},
228+
"Action" : ["s3:*"],
229+
"Resource" : [
230+
"${aws_s3_bucket.ec2_image_builder_components.arn}",
231+
"${aws_s3_bucket.ec2_image_builder_components.arn}/*"
232+
]
233+
},
234+
{
235+
"Sid" : "Deny non-HTTPS access",
236+
"Effect" : "Deny",
237+
"Principal" : "*",
238+
"Action" : ["s3:*"],
239+
"Resource" : "${aws_s3_bucket.ec2_image_builder_components.arn}/*",
240+
"Condition" : {
241+
"Bool" : {
242+
"aws:SecureTransport" : "false"
243243
}
244-
}
245-
}
246-
]
247-
}
248-
EOF
244+
}
245+
}
246+
]
247+
}
248+
)
249249
}
250250

251251
resource "random_uuid" "random_uuid" {
@@ -254,23 +254,23 @@ resource "random_uuid" "random_uuid" {
254254
resource "aws_kms_key" "aws_s3_bucket_kms_key" {
255255
description = "S3 Bucket KMS key"
256256
enable_key_rotation = true
257-
policy = <<POLICY
258-
{
259-
"Version": "2012-10-17",
260-
"Id": "default",
261-
"Statement": [
262-
{
263-
"Sid": "DefaultAllow",
264-
"Effect": "Allow",
265-
"Principal": {
266-
"AWS": "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
267-
},
268-
"Action": "kms:*",
269-
"Resource": "*"
270-
}
271-
]
272-
}
273-
POLICY
257+
policy = jsonencode(
258+
{
259+
"Version" : "2012-10-17",
260+
"Id" : "default",
261+
"Statement" : [
262+
{
263+
"Sid" : "DefaultAllow",
264+
"Effect" : "Allow",
265+
"Principal" : {
266+
"AWS" : "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
267+
},
268+
"Action" : "kms:*",
269+
"Resource" : "*"
270+
}
271+
]
272+
}
273+
)
274274
}
275275

276276
#tfsec:ignore:aws-s3-enable-bucket-logging
@@ -325,23 +325,23 @@ resource "aws_s3_bucket_public_access_block" "block_public_access" {
325325
resource "aws_kms_key" "aws_ssm_parameter_kms_key" {
326326
description = "SSM Parameter KMS key"
327327
enable_key_rotation = true
328-
policy = <<POLICY
329-
{
330-
"Version": "2012-10-17",
331-
"Id": "default",
332-
"Statement": [
333-
{
334-
"Sid": "DefaultAllow",
335-
"Effect": "Allow",
336-
"Principal": {
337-
"AWS": "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
338-
},
339-
"Action": "kms:*",
340-
"Resource": "*"
341-
}
342-
]
343-
}
344-
POLICY
328+
policy = jsonencode(
329+
{
330+
"Version" : "2012-10-17",
331+
"Id" : "default",
332+
"Statement" : [
333+
{
334+
"Sid" : "DefaultAllow",
335+
"Effect" : "Allow",
336+
"Principal" : {
337+
"AWS" : "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
338+
},
339+
"Action" : "kms:*",
340+
"Resource" : "*"
341+
}
342+
]
343+
}
344+
)
345345
}
346346

347347
resource "tls_private_key" "imagebuilder" {
@@ -393,4 +393,4 @@ module "vpc" {
393393
single_nat_gateway = true
394394

395395
tags = local.tags
396-
}
396+
}

examples/linux/providers.tf

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ terraform {
22
required_version = ">= 1.4.0"
33
required_providers {
44
aws = {
5-
source = "hashicorp/aws"
6-
}
7-
awscc = {
8-
source = "hashicorp/awscc"
9-
version = ">= 0.24.0"
5+
source = "hashicorp/aws"
106
}
117
tls = {
128
source = "hashicorp/tls"
@@ -21,4 +17,4 @@ terraform {
2117

2218
provider "aws" {
2319
region = local.aws_region
24-
}
20+
}

0 commit comments

Comments
 (0)