Skip to content
This repository was archived by the owner on Jul 20, 2024. It is now read-only.

Commit a2b4a4c

Browse files
authored
Use launch template for instance tagging (#30)
1 parent 5d2abcd commit a2b4a4c

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

main.tf

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ resource "aws_launch_template" "this" {
7979
delete_on_termination = true
8080
}
8181

82+
tag_specifications {
83+
resource_type = "instance"
84+
tags = local.common_tags
85+
}
86+
8287
user_data = base64encode(join("\n", [
8388
"#cloud-config",
8489
yamlencode({
@@ -106,9 +111,7 @@ resource "aws_launch_template" "this" {
106111
]))
107112

108113
description = "Launch template for NAT instance ${var.name}"
109-
tags = {
110-
Name = "nat-instance-${var.name}"
111-
}
114+
tags = local.common_tags
112115
}
113116

114117
resource "aws_autoscaling_group" "this" {
@@ -137,23 +140,15 @@ resource "aws_autoscaling_group" "this" {
137140
}
138141
}
139142

140-
// Generate asg tags from default tag list
141143
dynamic "tag" {
142-
for_each = var.tags
144+
for_each = local.common_tags
143145
content {
144146
key = tag.key
145147
value = tag.value
146-
propagate_at_launch = true
148+
propagate_at_launch = false
147149
}
148150
}
149151

150-
// Tag for name
151-
tag {
152-
key = "Name"
153-
value = "nat-instance-${var.name}"
154-
propagate_at_launch = true
155-
}
156-
157152
lifecycle {
158153
create_before_destroy = true
159154
}

0 commit comments

Comments
 (0)