Skip to content

Commit d86fa97

Browse files
authored
Merge pull request #62 from maiconrocha/main
Update Module
2 parents a57771d + d60a08e commit d86fa97

File tree

6 files changed

+38
-55
lines changed

6 files changed

+38
-55
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,10 @@ No modules.
133133
| <a name="input_ami_regions_kms_key"></a> [ami\_regions\_kms\_key](#input\_ami\_regions\_kms\_key) | (Optional) A list of AWS Regions to share the AMI with and also target KMS Key in each region | `map(string)` | `{}` | no |
134134
| <a name="input_attach_custom_policy"></a> [attach\_custom\_policy](#input\_attach\_custom\_policy) | (Required) Attach custom policy to the EC2 Instance Profile, if true, ARN of the custom policy needs to be specified on the variable custom\_policy\_arn | `bool` | `false` | no |
135135
| <a name="input_build_component_arn"></a> [build\_component\_arn](#input\_build\_component\_arn) | (Required) List of ARNs for the Build EC2 Image Builder Build Components | `list(string)` | `[]` | no |
136-
| <a name="input_create_security_group"></a> [create\_security\_group](#input\_create\_security\_group) | (Optional) Create security group for EC2 Image Builder instances | `bool` | `true` | no |
136+
| <a name="input_create_security_group"></a> [create\_security\_group](#input\_create\_security\_group) | (Optional) Create security group for EC2 Image Builder instances. Please note this security group will be created with default egress rule to 0.0.0.0/0 CIDR Block. In case you want to have a more restrict set of rules, please provide your own security group id on security\_group\_ids variable | `bool` | `true` | no |
137137
| <a name="input_custom_policy_arn"></a> [custom\_policy\_arn](#input\_custom\_policy\_arn) | (Optional) ARN of the custom policy to be attached to the EC2 Instance Profile | `string` | `null` | no |
138138
| <a name="input_imagebuilder_image_recipe_kms_key_arn"></a> [imagebuilder\_image\_recipe\_kms\_key\_arn](#input\_imagebuilder\_image\_recipe\_kms\_key\_arn) | (Required) KMS Key ARN(CMK) for encrypting Imagebuilder Image Recipe Block Device Mapping | `string` | `null` | no |
139139
| <a name="input_instance_key_pair"></a> [instance\_key\_pair](#input\_instance\_key\_pair) | (Optional) EC2 key pair to add to the default user on the builder(In case existent EC2 Key Pair is provided) | `string` | `null` | no |
140-
| <a name="input_instance_metadata_http_put_hop_limit"></a> [instance\_metadata\_http\_put\_hop\_limit](#input\_instance\_metadata\_http\_put\_hop\_limit) | The number of hops that an instance can traverse to reach its metadata. | `number` | `null` | no |
141-
| <a name="input_instance_metadata_http_tokens"></a> [instance\_metadata\_http\_tokens](#input\_instance\_metadata\_http\_tokens) | (Optional) Whether a signed token is required for instance metadata retrieval requests. Valid values: required, optional. | `string` | `"optional"` | no |
142140
| <a name="input_instance_types"></a> [instance\_types](#input\_instance\_types) | (Optional) Instance type for the EC2 Image Builder Instances. <br>Will be set by default to c5.large. Please check the AWS Pricing for more information about the instance types. | `list(string)` | <pre>[<br> "c5.large"<br>]</pre> | no |
143141
| <a name="input_managed_components"></a> [managed\_components](#input\_managed\_components) | (Optional) Specify the name and version of the AWS managed components that are going to be part of the image recipe | <pre>list(object({<br> name = string,<br> version = string<br> }))</pre> | `[]` | no |
144142
| <a name="input_recipe_version"></a> [recipe\_version](#input\_recipe\_version) | (Required) The semantic version of the image recipe. This version follows the semantic version syntax. e.g.: 0.0.1 | `string` | `"0.0.1"` | no |

examples/.DS_Store

-6 KB
Binary file not shown.

examples/windows/.DS_Store

-6 KB
Binary file not shown.

examples/windows/main.tf

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,27 @@ locals {
2626

2727
module "ec2-image-builder" {
2828
# source = "aws-ia/ec2-image-builder/aws"
29-
source = "../.."
30-
name = local.name
31-
aws_region = local.aws_region
32-
vpc_id = module.vpc.vpc_id
33-
subnet_id = module.vpc.private_subnets[0]
34-
source_cidr = [local.vpc_cidr] #["<ENTER your IP here to access EC2 Image Builder Instances through RDP or SSH>]"
35-
create_security_group = true
36-
instance_types = ["c5.large"]
37-
instance_key_pair = aws_key_pair.imagebuilder.key_name
38-
source_ami_name = "Windows_Server-2022-English-Core-Base-*"
39-
ami_name = "Windows 2022 core AMI"
40-
ami_description = "Windows 2022 core AMI provided by AWS"
41-
recipe_version = "0.0.1"
42-
build_component_arn = [aws_imagebuilder_component.win2022build.arn]
43-
test_component_arn = [aws_imagebuilder_component.win2022test.arn]
44-
s3_bucket_name = aws_s3_bucket.ec2_image_builder_components.id
45-
attach_custom_policy = true
46-
custom_policy_arn = aws_iam_policy.policy.arn
47-
platform = "Windows"
48-
imagebuilder_image_recipe_kms_key_arn = aws_kms_key.imagebuilder_image_recipe_kms_key.arn
49-
tags = local.tags
29+
source = "../.."
30+
name = local.name
31+
aws_region = local.aws_region
32+
vpc_id = module.vpc.vpc_id
33+
subnet_id = module.vpc.private_subnets[0]
34+
source_cidr = [local.vpc_cidr] #["<ENTER your IP here to access EC2 Image Builder Instances through RDP or SSH>]"
35+
create_security_group = true
36+
instance_types = ["c5.large"]
37+
instance_key_pair = aws_key_pair.imagebuilder.key_name
38+
source_ami_name = "Windows_Server-2022-English-Core-Base-*"
39+
ami_name = "Windows 2022 core AMI"
40+
ami_description = "Windows 2022 core AMI provided by AWS"
41+
recipe_version = "0.0.1"
42+
build_component_arn = [aws_imagebuilder_component.win2022build.arn]
43+
test_component_arn = [aws_imagebuilder_component.win2022test.arn]
44+
s3_bucket_name = aws_s3_bucket.ec2_image_builder_components.id
45+
attach_custom_policy = true
46+
custom_policy_arn = aws_iam_policy.policy.arn
47+
platform = "Windows"
48+
imagebuilder_image_recipe_kms_key_arn = aws_kms_key.imagebuilder_image_recipe_kms_key.arn
49+
tags = local.tags
5050

5151
managed_components = [{
5252
name = "powershell-windows",
@@ -196,7 +196,19 @@ resource "aws_s3_bucket_policy" "bucket_policy" {
196196
"${aws_s3_bucket.ec2_image_builder_components.arn}",
197197
"${aws_s3_bucket.ec2_image_builder_components.arn}/*"
198198
]
199-
}
199+
},
200+
{
201+
"Sid": "Deny non-HTTPS access",
202+
"Effect": "Deny",
203+
"Principal": "*",
204+
"Action": [ "s3:*" ],
205+
"Resource": "${aws_s3_bucket.ec2_image_builder_components.arn}/*",
206+
"Condition": {
207+
"Bool": {
208+
"aws:SecureTransport": "false"
209+
}
210+
}
211+
}
200212
]
201213
}
202214
EOF

main.tf

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -143,21 +143,6 @@ data "aws_iam_policy_document" "aws_policy" {
143143
resources = ["arn:aws:iam::*:role/EC2ImageBuilderDistributionCrossAccountRole"]
144144
}
145145

146-
statement {
147-
effect = "Allow"
148-
#checkov:skip=CKV_AWS_111:The policy must allow *
149-
#checkov:skip=CKV_AWS_290:The policy must allow *
150-
#checkov:skip=CKV_AWS_355:The policy must allow *
151-
actions = [
152-
"ec2messages:GetMessages",
153-
"ec2:MetadataHttpEndpoint",
154-
"ec2:MetadataHttpPutResponseHopLimit",
155-
"ec2:MetadataHttpTokens",
156-
"ssm:SendCommand"
157-
]
158-
resources = ["*"]
159-
}
160-
161146
}
162147

163148
# ---------------------------------------------------------------------------------------------------------------------
@@ -175,8 +160,8 @@ resource "aws_imagebuilder_infrastructure_configuration" "imagebuilder_infrastru
175160
subnet_id = var.subnet_id
176161

177162
instance_metadata_options {
178-
http_tokens = var.instance_metadata_http_tokens
179-
http_put_response_hop_limit = var.instance_metadata_http_put_hop_limit
163+
http_tokens = "required"
164+
http_put_response_hop_limit = 2
180165
}
181166

182167
terminate_instance_on_failure = var.terminate_on_failure

variables.tf

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,26 +154,14 @@ variable "imagebuilder_image_recipe_kms_key_arn" {
154154
type = string
155155
}
156156

157-
variable "instance_metadata_http_put_hop_limit" {
158-
default = null
159-
description = "The number of hops that an instance can traverse to reach its metadata."
160-
type = number
161-
}
162-
163-
variable "instance_metadata_http_tokens" {
164-
default = "optional"
165-
description = "(Optional) Whether a signed token is required for instance metadata retrieval requests. Valid values: required, optional."
166-
type = string
167-
}
168-
169157
variable "terminate_on_failure" {
170158
default = true
171159
description = "(Optional) Change to false if you want to connect to a builder for debugging after failure"
172160
type = bool
173161
}
174162

175163
variable "create_security_group" {
176-
description = "(Optional) Create security group for EC2 Image Builder instances"
164+
description = "(Optional) Create security group for EC2 Image Builder instances. Please note this security group will be created with default egress rule to 0.0.0.0/0 CIDR Block. In case you want to have a more restrict set of rules, please provide your own security group id on security_group_ids variable"
177165
type = bool
178166
default = true
179167
}

0 commit comments

Comments
 (0)