Skip to content

Commit 5a49c6a

Browse files
committed
feat(modules/asg): enable launch template versioning
1 parent 63817ed commit 5a49c6a

File tree

9 files changed

+34
-10
lines changed

9 files changed

+34
-10
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ No resources.
4343
| <a name="input_asg_instances_tags"></a> [asg\_instances\_tags](#input\_asg\_instances\_tags) | Resources Tags to propagate to the Instances | `map(string)` | `{}` | no |
4444
| <a name="input_asg_launch_template"></a> [asg\_launch\_template](#input\_asg\_launch\_template) | Launch Template to use with the Autoscaling group | <pre>object({<br> name = optional(string, null)<br> block_device_mappings = optional(list(object({<br> device_name = string<br> ebs = optional(object({<br> delete_on_termination = optional(bool, null)<br> snapshot_id = optional(string, null)<br> volume_size = optional(number, null)<br> volume_type = optional(string, null)<br> }))<br> no_device = optional(any, null)<br> virtual_name = optional(string, null)<br> })), [])<br> image_id = optional(string, null)<br> instance_type = optional(string, null)<br> vpc_security_group_ids = optional(list(string), [])<br> key_name = optional(string, null)<br> user_data = optional(string, null)<br> tags = optional(map(string), {})<br> })</pre> | `{}` | no |
4545
| <a name="input_asg_launch_template_id"></a> [asg\_launch\_template\_id](#input\_asg\_launch\_template\_id) | Identifier of the Launch Template | `string` | `null` | no |
46+
| <a name="input_asg_launch_template_version"></a> [asg\_launch\_template\_version](#input\_asg\_launch\_template\_version) | (Optional) Template version. | `string` | `null` | no |
4647
| <a name="input_asg_max_size"></a> [asg\_max\_size](#input\_asg\_max\_size) | Maximum size of the Auto Scaling Group | `number` | n/a | yes |
4748
| <a name="input_asg_min_size"></a> [asg\_min\_size](#input\_asg\_min\_size) | Minimum size of the Auto Scaling Group | `number` | n/a | yes |
4849
| <a name="input_asg_name"></a> [asg\_name](#input\_asg\_name) | (Optional) Name of the Auto Scaling Group. | `string` | n/a | yes |

examples/complete/locals.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ locals {
3333
key_name = "test-atlantis"
3434
security_group_ids = []
3535
}
36+
asg_launch_template_version = "$Latest"
3637

3738
# IAM Role Variables
3839
asg_iam_role_name = "my-asg-role"

examples/complete/main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ module "ecs" {
1515
asg_tags = local.asg_tags
1616

1717
# Launch Template
18-
asg_create_launch_template = local.asg_create_launch_template
19-
asg_launch_template = local.asg_launch_template
18+
asg_create_launch_template = local.asg_create_launch_template
19+
asg_launch_template = local.asg_launch_template
20+
asg_launch_template_version = local.asg_launch_template_version
2021

2122
# IAM Role
2223
asg_iam_role_name = local.asg_iam_role_name

main.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ module "asg" {
2929
tags = var.asg_tags
3030

3131
# Launch Template
32-
create_launch_template = var.asg_create_launch_template
33-
launch_template_id = var.asg_launch_template_id
34-
launch_template = var.asg_launch_template
32+
create_launch_template = var.asg_create_launch_template
33+
launch_template_id = var.asg_launch_template_id
34+
launch_template = var.asg_launch_template
35+
launch_template_version = var.asg_launch_template_version
3536

3637
# IAM Role
3738
iam_role_name = var.asg_iam_role_name

modules/asg/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ No modules.
4444
| <a name="input_iam_role_tags"></a> [iam\_role\_tags](#input\_iam\_role\_tags) | Key-value mapping of tags for the IAM role. | `map(string)` | `{}` | no |
4545
| <a name="input_instances_tags"></a> [instances\_tags](#input\_instances\_tags) | Resources Tags to propagate to the Instances | `map(string)` | `{}` | no |
4646
| <a name="input_launch_template"></a> [launch\_template](#input\_launch\_template) | Launch Template to use with the Autoscaling group | <pre>object({<br> name = optional(string, null)<br> block_device_mappings = optional(list(object({<br> device_name = string<br> ebs = optional(object({<br> delete_on_termination = optional(bool, null)<br> snapshot_id = optional(string, null)<br> volume_size = optional(number, null)<br> volume_type = optional(string, null)<br> }))<br> no_device = optional(any, null)<br> virtual_name = optional(string, null)<br> })), [])<br> image_id = optional(string, null)<br> instance_type = optional(string, null)<br> vpc_security_group_ids = optional(list(string), [])<br> key_name = optional(string, null)<br> user_data = optional(string, null)<br> tags = optional(map(string), {})<br> })</pre> | `{}` | no |
47-
| <a name="input_launch_template_id"></a> [launch\_template\_id](#input\_launch\_template\_id) | Identifier of the Launch Template | `string` | `null` | no |
47+
| <a name="input_launch_template_id"></a> [launch\_template\_id](#input\_launch\_template\_id) | (Optional) ID of the launch template. | `string` | `null` | no |
48+
| <a name="input_launch_template_version"></a> [launch\_template\_version](#input\_launch\_template\_version) | (Optional) Template version. | `string` | `"$Latest"` | no |
4849
| <a name="input_max_size"></a> [max\_size](#input\_max\_size) | Maximum size of the Auto Scaling Group | `number` | n/a | yes |
4950
| <a name="input_min_size"></a> [min\_size](#input\_min\_size) | Minimum size of the Auto Scaling Group | `number` | n/a | yes |
5051
| <a name="input_name"></a> [name](#input\_name) | (Optional) Name of the Auto Scaling Group. | `string` | `null` | no |

modules/asg/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ resource "aws_autoscaling_group" "this" {
1010
health_check_type = var.health_check_type
1111

1212
launch_template {
13-
id = var.create_launch_template ? aws_launch_template.this[0].id : var.launch_template_id
13+
id = var.create_launch_template ? aws_launch_template.this[0].id : var.launch_template_id
14+
version = var.launch_template_version != null ? var.launch_template_version : null
1415
}
1516

1617
dynamic "tag" {

modules/asg/variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,17 @@ variable "create_launch_template" {
8484
}
8585

8686
variable "launch_template_id" {
87-
description = "Identifier of the Launch Template"
87+
description = "(Optional) ID of the launch template."
8888
type = string
8989
default = null
9090
}
9191

92+
variable "launch_template_version" {
93+
description = "(Optional) Template version."
94+
type = string
95+
default = "$Latest"
96+
}
97+
9298
################################################################################
9399
# IAM Role
94100
################################################################################

tests/asg_unit_tests.tftest.hcl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ run "asg_attributes_match" {
2323
max_size = 10
2424
health_check_type = "ELB"
2525

26-
create_launch_template = false
27-
launch_template_id = "lt-068f72b729example"
26+
create_launch_template = false
27+
launch_template_id = "lt-068f72b729example"
28+
launch_template_version = "$Default"
2829

2930
iam_role_policy_attachments = [
3031
"arn:aws:iam::aws:policy/abcd/efgh"
@@ -78,6 +79,11 @@ run "asg_attributes_match" {
7879
error_message = "Launch template id mismatch"
7980
}
8081

82+
assert {
83+
condition = aws_autoscaling_group.this.launch_template[0].version == var.launch_template_version
84+
error_message = "Launch template version mismatch"
85+
}
86+
8187
assert {
8288
condition = length(aws_launch_template.this) == 0
8389
error_message = "Launch template was created"

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ variable "asg_launch_template_id" {
131131
}
132132
}
133133

134+
variable "asg_launch_template_version" {
135+
description = "(Optional) Template version."
136+
type = string
137+
default = null
138+
}
139+
134140
################################################################################
135141
### IAM Role
136142
################################################################################

0 commit comments

Comments
 (0)