Skip to content

Commit b0c9b59

Browse files
author
Steven Nemetz
committed
Update label module. Switch to using tags from label module. Remove old tags_ag. Update examples.
1 parent 8f36845 commit b0c9b59

File tree

5 files changed

+42
-52
lines changed

5 files changed

+42
-52
lines changed

examples/disabled/main.tf

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,7 @@ module "example" {
9494
desired_capacity = 1
9595
wait_for_capacity_timeout = 0
9696

97-
tags_ag = [
98-
{
99-
key = "Project"
100-
value = "megasecret"
101-
propagate_at_launch = true
102-
},
103-
]
97+
tags = {
98+
Project = "megasecret"
99+
}
104100
}

examples/ec2/main.tf

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,7 @@ module "example" {
9393
desired_capacity = 1
9494
wait_for_capacity_timeout = 0
9595

96-
tags_ag = [
97-
{
98-
key = "Project"
99-
value = "megasecret"
100-
propagate_at_launch = true
101-
},
102-
]
96+
tags = {
97+
Project = "megasecret"
98+
}
10399
}

examples/elb/main.tf

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,17 @@ data "aws_vpc" "vpc" {
77
}
88
}
99

10-
data "aws_subnet_ids" "all" {
10+
data "aws_subnet_ids" "private_subnet_ids" {
1111
vpc_id = "${data.aws_vpc.vpc.id}"
12+
13+
tags {
14+
Network = "Private"
15+
}
16+
}
17+
18+
data "aws_subnet" "private_subnets" {
19+
count = "${length(data.aws_subnet_ids.private_subnet_ids.ids)}"
20+
id = "${data.aws_subnet_ids.private_subnet_ids.ids[count.index]}"
1221
}
1322

1423
data "aws_security_group" "default" {
@@ -74,36 +83,30 @@ module "example_asg" {
7483

7584
# Auto scaling group
7685
asg_name = "example-asg"
77-
vpc_zone_identifier = ["${data.aws_subnet_ids.all.ids}"]
86+
vpc_zone_identifier = ["${data.aws_subnet_ids.private_subnet_ids.ids}"]
7887
health_check_type = "EC2"
7988
min_size = 0
8089
max_size = 1
8190
desired_capacity = 1
8291
wait_for_capacity_timeout = 0
8392

84-
tags_ag = [
85-
{
86-
key = "Environment"
87-
value = "dev"
88-
propagate_at_launch = true
89-
},
90-
{
91-
key = "Project"
92-
value = "megasecret"
93-
propagate_at_launch = true
94-
},
95-
]
93+
tags = {
94+
Environment = "dev"
95+
Project = "megasecret"
96+
}
9697
}
9798

99+
# TODO: Convert to lb module
98100
######
99101
# ELB
100102
######
101103
module "elb" {
102-
source = "terraform-aws-modules/elb/aws"
104+
source = "terraform-aws-modules/elb/aws"
105+
version = "1.2.0"
103106

104107
name = "elb-example"
105108

106-
subnets = ["${data.aws_subnet_ids.all.ids}"]
109+
subnets = ["${data.aws_subnet_ids.private_subnet_ids.ids}"]
107110
security_groups = ["${data.aws_security_group.default.id}"]
108111
internal = false
109112

main.tf

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module "enabled" {
2020
# Define composite variables for resources
2121
module "label" {
2222
source = "devops-workflow/label/local"
23-
version = "0.2.0"
23+
version = "0.2.1"
2424
attributes = "${var.attributes}"
2525
component = "${var.component}"
2626
delimiter = "${var.delimiter}"
@@ -37,6 +37,21 @@ module "label" {
3737
team = "${var.team}"
3838
}
3939

40+
# Terraform converts true to 1. Can it be prevented?
41+
data "null_data_source" "tags_asg" {
42+
count = "${module.enabled.value ? length(keys(module.label.tags)) : 0}"
43+
44+
inputs = "${map(
45+
"key", "${element(keys(module.label.tags), count.index)}",
46+
"value", "${element(values(module.label.tags), count.index)}",
47+
"propagate_at_launch", "true"
48+
)}"
49+
}
50+
51+
locals {
52+
tags_asg = ["${data.null_data_source.tags_asg.*.outputs}"]
53+
}
54+
4055
#######################
4156
# Launch configuration
4257
#######################
@@ -111,27 +126,12 @@ resource "aws_autoscaling_group" "this" {
111126
placement_group = "${var.placement_group}"
112127
protect_from_scale_in = "${var.protect_from_scale_in}"
113128
suspended_processes = "${var.suspended_processes}"
129+
tags = ["${local.tags_asg}"]
114130
target_group_arns = ["${var.target_group_arns}"]
115131
termination_policies = "${var.termination_policies}"
116132
wait_for_capacity_timeout = "${var.wait_for_capacity_timeout}"
117133
wait_for_elb_capacity = "${var.wait_for_elb_capacity}"
118134

119-
tags = ["${ concat(
120-
list(
121-
map("key", "Component", "value", var.component, "propagate_at_launch", true),
122-
map("key", "Environment", "value", module.label.environment, "propagate_at_launch", true),
123-
map("key", "Monitor", "value", var.monitor, "propagate_at_launch", true),
124-
map("key", "Name", "value", module.label.id, "propagate_at_launch", true),
125-
map("key", "Organization", "value", var.organization, "propagate_at_launch", true),
126-
map("key", "Owner", "value", var.owner, "propagate_at_launch", true),
127-
map("key", "Product", "value", var.product, "propagate_at_launch", true),
128-
map("key", "Service", "value", var.service, "propagate_at_launch", true),
129-
map("key", "Team", "value", var.team, "propagate_at_launch", true),
130-
map("key", "Terraform", "value", "true", "propagate_at_launch", true)
131-
),
132-
var.tags_ag
133-
)}"]
134-
135135
lifecycle {
136136
create_before_destroy = true
137137
}

variables.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,6 @@ variable "protect_from_scale_in" {
261261
default = false
262262
}
263263

264-
variable "tags_ag" {
265-
description = "Additional tags for Autoscaling group. A list of tag blocks. Each element is a map with key, value, and propagate_at_launch."
266-
default = []
267-
}
268-
269264
variable "vpc_zone_identifier" {
270265
description = "A list of subnet IDs to launch resources in"
271266
type = "list"

0 commit comments

Comments
 (0)