Skip to content

Commit 40a4ba9

Browse files
committed
Add http_protocol_ipv6 option, make variable not nullable, add unit tests
1 parent 089aeea commit 40a4ba9

File tree

5 files changed

+67
-0
lines changed

5 files changed

+67
-0
lines changed

asg.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ resource "aws_launch_template" "cluster" {
3535
http_tokens = lookup(var.cluster_instance_metadata_options, "http_tokens", null)
3636
http_put_response_hop_limit = lookup(var.cluster_instance_metadata_options, "http_put_response_hop_limit", null)
3737
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)
3839
}
3940

4041
user_data = base64encode(local.cluster_user_data)

spec/unit/infra/root/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ module "ecs_cluster" {
2929
cluster_instance_enable_ebs_volume_encryption = var.cluster_instance_enable_ebs_volume_encryption
3030
cluster_instance_ebs_volume_kms_key_id = var.cluster_instance_ebs_volume_kms_key_id
3131

32+
cluster_instance_metadata_options = var.cluster_instance_metadata_options
33+
3234
cluster_minimum_size = var.cluster_minimum_size
3335
cluster_maximum_size = var.cluster_maximum_size
3436
cluster_desired_capacity = var.cluster_desired_capacity

spec/unit/infra/root/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ variable "cluster_instance_root_block_device_path" {
2828
default = null
2929
}
3030

31+
variable "cluster_instance_metadata_options" {
32+
type = map
33+
default = null
34+
}
35+
3136
variable "cluster_minimum_size" {
3237
default = null
3338
}

spec/unit/launch_template_spec.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,62 @@
236236
))
237237
end
238238
end
239+
240+
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
255+
expect(@plan)
256+
.to(include_resource_creation(type: 'aws_launch_template')
257+
.with_attribute_value(
258+
:metadata_options,
259+
including(
260+
including({
261+
http_protocol_ipv6: 'disabled',
262+
instance_metadata_tags: 'disabled'
263+
})
264+
)
265+
))
266+
end
267+
268+
context 'when cluster_instance_metadata_options is provided' do
269+
before(:context) do
270+
@plan = plan(role: :root) do |vars|
271+
vars.cluster_instance_metadata_options = {
272+
http_endpoint: 'enabled',
273+
http_tokens: 'optional',
274+
http_protocol_ipv6: 'enabled',
275+
instance_metadata_tags: 'enabled',
276+
http_put_response_hop_limit: 15
277+
}
278+
end
279+
end
280+
281+
it 'uses provided metadata options' do
282+
expect(@plan)
283+
.to(include_resource_creation(type: 'aws_launch_template')
284+
.with_attribute_value(
285+
:metadata_options,
286+
including(including({
287+
http_endpoint: 'enabled',
288+
http_tokens: 'optional',
289+
http_protocol_ipv6: 'enabled',
290+
instance_metadata_tags: 'enabled',
291+
http_put_response_hop_limit: 15
292+
}))
293+
))
294+
end
295+
end
296+
end
239297
end

variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ variable "cluster_instance_metadata_options" {
8383
default = {
8484
http_tokens = "required" # AWS Recommended default: IMDSv2 required
8585
}
86+
nullable = false
8687
}
8788
variable "cluster_service_iam_policy_contents" {
8889
description = "The contents of the cluster service IAM policy."

0 commit comments

Comments
 (0)