Skip to content

Commit 6a051b9

Browse files
committed
Remove breaking changes.
1 parent fd440ba commit 6a051b9

File tree

5 files changed

+39
-50
lines changed

5 files changed

+39
-50
lines changed

CHANGELOG.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22

33
BACKWARDS INCOMPATIBILITIES / NOTES:
44

5-
6-
* IMDSv2 support is now on by default, this can be changed via the new
7-
`cluster_instance_metadata_options` variable which mirrors
8-
aws_launch_template's [metadata_options](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template#metadata-options)
95
* The `cluster_desired_capacity` is now ignored after the first `apply` of the
106
module since, in the case of autoscaling or manual scaling, the value may have
117
changed between `apply`s.
128

9+
IMPROVEMENTS:
10+
11+
* A `cluster_instance_metadata_options` variable has been added which mirrors
12+
the [metadata_options](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template#metadata-options)
13+
exposed on the `aws_launch_template` resource. Among other things, this allows
14+
users of this module to require that IMDSv2 be used by containers in the
15+
cluster. By default, IMDSv2 is not required in this version of the module but
16+
a future major release of the module may enforce IMDSv2 usage.
17+
18+
1319
## 6.0.0 (February 22th 2023)
1420

1521
BACKWARDS INCOMPATIBILITIES / NOTES:

README.md

+19-21
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ The ECS cluster consists of:
1717
instances
1818
* An SSH key to connect to the ECS container instances
1919
* A security group for the container instances optionally allowing:
20-
* Outbound internet access for all containers
21-
* Inbound TCP access on any port from the VPC network
20+
* Outbound internet access for all containers
21+
* Inbound TCP access on any port from the VPC network
2222
* An IAM role and policy for the container instances allowing:
23-
* ECS interactions
24-
* ECR image pulls
25-
* S3 object fetches
26-
* Logging to cloudwatch
23+
* ECS interactions
24+
* ECR image pulls
25+
* S3 object fetches
26+
* Logging to cloudwatch
2727
* An IAM role and policy for ECS services allowing:
28-
* Elastic load balancer registration / deregistration
29-
* EC2 describe actions and security group ingress rule creation
28+
* Elastic load balancer registration / deregistration
29+
* EC2 describe actions and security group ingress rule creation
3030
* A CloudWatch log group
3131

3232
![Diagram of infrastructure managed by this module](https://raw.githubusercontent.com/infrablocks/terraform-aws-ecs-cluster/main/docs/architecture.png)
@@ -39,25 +39,25 @@ configuration:
3939

4040
```hcl-terraform
4141
module "ecs_cluster" {
42-
source = "infrablocks/ecs-cluster/aws"
42+
source = "infrablocks/ecs-cluster/aws"
4343
version = "5.0.0"
4444
45-
region = "eu-west-2"
46-
vpc_id = "vpc-fb7dc365"
45+
region = "eu-west-2"
46+
vpc_id = "vpc-fb7dc365"
4747
subnet_ids = [
48-
"subnet-eb32c271",
49-
"subnet-64872d1f"
48+
"subnet-eb32c271",
49+
"subnet-64872d1f"
5050
]
5151
52-
component = "important-component"
52+
component = "important-component"
5353
deployment_identifier = "production"
5454
55-
cluster_name = "services"
55+
cluster_name = "services"
5656
cluster_instance_ssh_public_key_path = "~/.ssh/id_rsa.pub"
57-
cluster_instance_type = "t3.small"
57+
cluster_instance_type = "t3.small"
5858
59-
cluster_minimum_size = 2
60-
cluster_maximum_size = 10
59+
cluster_minimum_size = 2
60+
cluster_maximum_size = 10
6161
cluster_desired_capacity = 4
6262
}
6363
```
@@ -91,9 +91,9 @@ for more details.
9191
| cluster_instance_root_block_device_type | The type of the root block device on cluster instances ('standard', 'gp2', or 'io1') | standard | yes |
9292
| cluster_instance_user_data_template | The contents of a template for container instance user data | see user-data | no |
9393
| cluster_instance_ami | AMI for the container instances | ECS optimised AMI | yes |
94+
| cluster_instance_metadata_options | A map of metadata options for cluster instances. | - | no |
9495
| cluster_instance_iam_policy_contents | The contents of the cluster instance IAM policy | see policies | no |
9596
| cluster_service_iam_policy_contents | The contents of the cluster service IAM policy | see policies | no |
96-
| cluster_instance_metadata_options | Map of metadata_options for cluster instances. | { http_tokens = "required" } | no |
9797
| cluster_minimum_size | The minimum size of the ECS cluster | 1 | yes |
9898
| cluster_maximum_size | The maximum size of the ECS cluster | 10 | yes |
9999
| cluster_desired_capacity | The desired capacity of the ECS cluster | 3 | yes |
@@ -119,7 +119,6 @@ for more details.
119119
Notes:
120120

121121
* By default, the latest available Amazon Linux 2 AMI is used.
122-
* By default, [IMDSv2](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html) is now required for [security reasons](https://aws.amazon.com/blogs/security/defense-in-depth-open-firewalls-reverse-proxies-ssrf-vulnerabilities-ec2-instance-metadata-service/)
123122
* For Amazon Linux 1 AMIs use version <= 0.6.0 of this module for terraform 0.11
124123
or version = 1.0.0 for terraform 0.12.
125124
* When a specific AMI is provided via `cluster_instance_ami`, only the root
@@ -204,7 +203,6 @@ Terraform 1.0.
204203
* logs:ListTagsLogGroup
205204
* logs:DeleteLogGroup
206205

207-
208206
Development
209207
-----------
210208

asg.tf

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ locals {
88
cluster_user_data = replace(
99
local.cluster_user_data_template,
1010
"$${cluster_name}", local.cluster_full_name)
11+
cluster_instance_metadata_options = var.cluster_instance_metadata_options == null ? {} : var.cluster_instance_metadata_options
1112
}
1213

1314
data "aws_ami" "amazon_linux_2" {
@@ -31,11 +32,11 @@ resource "aws_launch_template" "cluster" {
3132
}
3233

3334
metadata_options {
34-
http_endpoint = lookup(var.cluster_instance_metadata_options, "http_endpoint", null)
35-
http_tokens = lookup(var.cluster_instance_metadata_options, "http_tokens", null)
36-
http_put_response_hop_limit = lookup(var.cluster_instance_metadata_options, "http_put_response_hop_limit", null)
37-
instance_metadata_tags = lookup(var.cluster_instance_metadata_options, "instance_metadata_tags", null)
38-
http_protocol_ipv6 = lookup(var.cluster_instance_metadata_options, "http_protocol_ipv6", null)
35+
http_endpoint = lookup(local.cluster_instance_metadata_options, "http_endpoint", null)
36+
http_tokens = lookup(local.cluster_instance_metadata_options, "http_tokens", null)
37+
http_put_response_hop_limit = lookup(local.cluster_instance_metadata_options, "http_put_response_hop_limit", null)
38+
instance_metadata_tags = lookup(local.cluster_instance_metadata_options, "instance_metadata_tags", null)
39+
http_protocol_ipv6 = lookup(local.cluster_instance_metadata_options, "http_protocol_ipv6", null)
3940
}
4041

4142
user_data = base64encode(local.cluster_user_data)

spec/unit/launch_template_spec.rb

+3-16
Original file line numberDiff line numberDiff line change
@@ -238,20 +238,7 @@
238238
end
239239

240240
describe 'metadata options' do
241-
it 'requires http_tokens (IMDSv2) by default' do
242-
expect(@plan)
243-
.to(include_resource_creation(type: 'aws_launch_template')
244-
.with_attribute_value(
245-
:metadata_options,
246-
including(
247-
including({
248-
http_tokens: 'required'
249-
})
250-
)
251-
))
252-
end
253-
254-
it 'http_protocol_ipv6 and instance_metadata_tags disabled by default' do
241+
it 'disables http_protocol_ipv6 and instance_metadata_tags by default' do
255242
expect(@plan)
256243
.to(include_resource_creation(type: 'aws_launch_template')
257244
.with_attribute_value(
@@ -270,7 +257,7 @@
270257
@plan = plan(role: :root) do |vars|
271258
vars.cluster_instance_metadata_options = {
272259
http_endpoint: 'enabled',
273-
http_tokens: 'optional',
260+
http_tokens: 'required',
274261
http_protocol_ipv6: 'enabled',
275262
instance_metadata_tags: 'enabled',
276263
http_put_response_hop_limit: 15
@@ -285,7 +272,7 @@
285272
:metadata_options,
286273
including(including({
287274
http_endpoint: 'enabled',
288-
http_tokens: 'optional',
275+
http_tokens: 'required',
289276
http_protocol_ipv6: 'enabled',
290277
instance_metadata_tags: 'enabled',
291278
http_put_response_hop_limit: 15

variables.tf

+1-4
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@ variable "cluster_instance_iam_policy_contents" {
8080
variable "cluster_instance_metadata_options" {
8181
description = "The metadata_options for cluster instances."
8282
type = map
83-
default = {
84-
http_tokens = "required" # AWS Recommended default: IMDSv2 required
85-
}
86-
nullable = false
83+
default = null
8784
}
8885
variable "cluster_service_iam_policy_contents" {
8986
description = "The contents of the cluster service IAM policy."

0 commit comments

Comments
 (0)