Skip to content

Commit 85821a7

Browse files
authored
Merge pull request #12 from DNXLabs/11-update-to-terraform-0.12-syntax
Updates to terraform 0.12 syntax
2 parents 1850811 + c3ba5d1 commit 85821a7

20 files changed

+142
-142
lines changed

_outputs.tf

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,67 @@
11
output "alb_id" {
2-
value = "${aws_lb.ecs.*.id}"
2+
value = aws_lb.ecs.*.id
33
}
44

55
output "alb_arn" {
6-
value = "${aws_lb.ecs.*.arn}"
6+
value = aws_lb.ecs.*.arn
77
}
88

99
output "alb_dns_name" {
10-
value = "${aws_lb.ecs.*.dns_name}"
10+
value = aws_lb.ecs.*.dns_name
1111
}
1212

1313
output "alb_zone_id" {
14-
value = "${aws_lb.ecs.*.zone_id}"
14+
value = aws_lb.ecs.*.zone_id
1515
}
1616

1717
output "ecs_iam_role_arn" {
18-
value = "${aws_iam_role.ecs.arn}"
18+
value = aws_iam_role.ecs.arn
1919
}
2020

2121
output "ecs_iam_role_name" {
22-
value = "${aws_iam_role.ecs.name}"
22+
value = aws_iam_role.ecs.name
2323
}
2424

2525
output "ecs_service_iam_role_arn" {
26-
value = "${aws_iam_role.ecs_service.arn}"
26+
value = aws_iam_role.ecs_service.arn
2727
}
2828

2929
output "ecs_service_iam_role_name" {
30-
value = "${aws_iam_role.ecs_service.name}"
30+
value = aws_iam_role.ecs_service.name
3131
}
3232

3333
output "ecs_task_iam_role_arn" {
34-
value = "${aws_iam_role.ecs_task.arn}"
34+
value = aws_iam_role.ecs_task.arn
3535
}
3636

3737
output "ecs_task_iam_role_name" {
38-
value = "${aws_iam_role.ecs_task.name}"
38+
value = aws_iam_role.ecs_task.name
3939
}
4040

4141
output "ecs_id" {
42-
value = "${aws_ecs_cluster.ecs.id}"
42+
value = aws_ecs_cluster.ecs.id
4343
}
4444

4545
output "ecs_arn" {
46-
value = "${aws_ecs_cluster.ecs.arn}"
46+
value = aws_ecs_cluster.ecs.arn
4747
}
4848

4949
output "ecs_name" {
50-
value = "${aws_ecs_cluster.ecs.name}"
50+
value = aws_ecs_cluster.ecs.name
5151
}
5252

5353
output "alb_listener_https_arn" {
54-
value = "${aws_lb_listener.ecs_https.*.arn}"
54+
value = aws_lb_listener.ecs_https.*.arn
5555
}
5656

5757
output "ecs_nodes_secgrp_id" {
58-
value = "${aws_security_group.ecs_nodes.id}"
58+
value = aws_security_group.ecs_nodes.id
5959
}
6060

6161
output "alb_secgrp_id" {
62-
value = "${aws_security_group.alb.*.id}"
62+
value = aws_security_group.alb.*.id
6363
}
6464

6565
output "alb_cloudfront_key" {
66-
value = "${random_string.alb_cloudfront_key.result}"
66+
value = random_string.alb_cloudfront_key.result
6767
}

_variables.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ variable "vpc_id" {
3131
}
3232

3333
variable "private_subnet_ids" {
34-
type = "list"
34+
type = list(string)
3535
description = "List of private subnet IDs for ECS instances"
3636
}
3737

3838
variable "public_subnet_ids" {
39-
type = "list"
39+
type = list(string)
4040
description = "List of public subnet IDs for ECS ALB"
4141
}
4242

4343
variable "secure_subnet_ids" {
44-
type = "list"
44+
type = list(string)
4545
description = "List of secure subnet IDs for EFS"
4646
}
4747

@@ -50,7 +50,7 @@ variable "certificate_arn" {}
5050
# == OPTIONAL VARS
5151

5252
variable "security_group_ids" {
53-
type = "list"
53+
type = list(string)
5454
default = []
5555
description = "Extra security groups for instances"
5656
}
@@ -97,7 +97,7 @@ variable "expire_backup_efs" {
9797

9898
variable "target_group_arns" {
9999
default = []
100-
type = "list"
100+
type = list(string)
101101
description = "List of target groups for ASG to register"
102102
}
103103

alb.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "aws_lb" "ecs" {
2-
count = "${var.alb ? 1 : 0}"
2+
count = var.alb ? 1 : 0
33

44
load_balancer_type = "application"
55
internal = false
@@ -18,13 +18,13 @@ resource "aws_lb" "ecs" {
1818
}
1919

2020
resource "aws_lb_listener" "ecs_https" {
21-
count = "${var.alb ? 1 : 0}"
21+
count = var.alb ? 1 : 0
2222

2323
load_balancer_arn = aws_lb.ecs[0].arn
2424
port = "443"
2525
protocol = "HTTPS"
2626
ssl_policy = "ELBSecurityPolicy-2016-08"
27-
certificate_arn = "${var.certificate_arn}"
27+
certificate_arn = var.certificate_arn
2828

2929
default_action {
3030
type = "forward"
@@ -33,7 +33,7 @@ resource "aws_lb_listener" "ecs_https" {
3333
}
3434

3535
resource "aws_lb_listener" "ecs_http_redirect" {
36-
count = "${var.alb ? 1 : 0}"
36+
count = var.alb ? 1 : 0
3737

3838
load_balancer_arn = aws_lb.ecs[0].arn
3939
port = "80"
@@ -51,19 +51,19 @@ resource "aws_lb_listener" "ecs_http_redirect" {
5151
}
5252

5353
resource "aws_lb_target_group" "ecs_default_http" {
54-
count = "${var.alb ? 1 : 0}"
54+
count = var.alb ? 1 : 0
5555

5656
name = "ecs-${var.name}-default-http"
5757
port = 80
5858
protocol = "HTTP"
59-
vpc_id = "${var.vpc_id}"
59+
vpc_id = var.vpc_id
6060
}
6161

6262
resource "aws_lb_target_group" "ecs_default_https" {
63-
count = "${var.alb ? 1 : 0}"
63+
count = var.alb ? 1 : 0
6464

6565
name = "ecs-${var.name}-default-https"
6666
port = 80
6767
protocol = "HTTP"
68-
vpc_id = "${var.vpc_id}"
68+
vpc_id = var.vpc_id
6969
}

asg.tf

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,37 @@ resource "aws_autoscaling_group" "ecs" {
44
mixed_instances_policy {
55
launch_template {
66
launch_template_specification {
7-
launch_template_id = "${aws_launch_template.ecs.id}"
7+
launch_template_id = aws_launch_template.ecs.id
88
version = "$Latest"
99
}
1010

1111
override {
12-
instance_type = "${var.instance_type_1}"
12+
instance_type = var.instance_type_1
1313
}
1414

1515
override {
16-
instance_type = "${var.instance_type_2}"
16+
instance_type = var.instance_type_2
1717
}
1818

1919
override {
20-
instance_type = "${var.instance_type_3}"
20+
instance_type = var.instance_type_3
2121
}
2222
}
2323

2424
instances_distribution {
2525
spot_instance_pools = 3
26-
on_demand_base_capacity = "${var.on_demand_base_capacity}"
27-
on_demand_percentage_above_base_capacity = "${var.on_demand_percentage}"
26+
on_demand_base_capacity = var.on_demand_base_capacity
27+
on_demand_percentage_above_base_capacity = var.on_demand_percentage
2828
}
2929
}
3030

3131
vpc_zone_identifier = var.private_subnet_ids
3232

33-
min_size = "${var.asg_min}"
34-
max_size = "${var.asg_max}"
33+
min_size = var.asg_min
34+
max_size = var.asg_max
3535

3636
tags = [
37-
"${map("key", "Name", "value", "ecs-node-${var.name}", "propagate_at_launch", true)}",
37+
map("key", "Name", "value", "ecs-node-${var.name}", "propagate_at_launch", true)
3838
]
3939

4040
target_group_arns = var.target_group_arns
@@ -48,14 +48,14 @@ resource "aws_autoscaling_group" "ecs" {
4848
resource "aws_autoscaling_policy" "ecs_memory_tracking" {
4949
name = "ecs-${var.name}-memory"
5050
policy_type = "TargetTrackingScaling"
51-
autoscaling_group_name = "${aws_autoscaling_group.ecs.name}"
51+
autoscaling_group_name = aws_autoscaling_group.ecs.name
5252
estimated_instance_warmup = "180"
5353

5454
target_tracking_configuration {
5555
customized_metric_specification {
5656
metric_dimension {
5757
name = "ClusterName"
58-
value = "${aws_ecs_cluster.ecs.name}"
58+
value = aws_ecs_cluster.ecs.name
5959
}
6060

6161
metric_name = "MemoryReservation"
@@ -64,6 +64,6 @@ resource "aws_autoscaling_policy" "ecs_memory_tracking" {
6464
unit = "Percent"
6565
}
6666

67-
target_value = "${var.asg_memory_target}"
67+
target_value = var.asg_memory_target
6868
}
6969
}

cf-exports.tf

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ resource "aws_cloudformation_stack" "tf_exports" {
44
template_body = templatefile("${path.module}/cf-exports.yml", {
55
"name" = var.name,
66
"vars" = {
7-
"AlbId" = "${aws_lb.ecs.*.id[0]}",
8-
"AlbArn" = "${aws_lb.ecs.*.arn[0]}",
9-
"AlbDnsName" = "${aws_lb.ecs.*.dns_name[0]}",
10-
"AlbZoneId" = "${aws_lb.ecs.*.zone_id[0]}",
11-
"AlbSecgrpId" = "${aws_security_group.alb.*.id[0]}"
12-
"EcsIamRoleArn" = "${aws_iam_role.ecs.arn}",
13-
"EcsIamRoleName" = "${aws_iam_role.ecs.name}",
14-
"EcsServiceIamRoleArn" = "${aws_iam_role.ecs_service.arn}",
15-
"EcsServiceIamRoleName" = "${aws_iam_role.ecs_service.name}",
16-
"EcsTaskIamRoleArn" = "${aws_iam_role.ecs_task.arn}",
17-
"EcsTaskIamRoleName" = "${aws_iam_role.ecs_task.name}",
18-
"EcsId" = "${aws_ecs_cluster.ecs.*.id[0]}",
19-
"EcsName" = "${aws_ecs_cluster.ecs.*.name[0]}",
20-
"EcsArn" = "${aws_ecs_cluster.ecs.*.arn[0]}",
21-
"AlbListenerHttpsArn" = "${aws_lb_listener.ecs_https.*.arn[0]}",
22-
"EcsNodesSecGrpId" = "${aws_security_group.ecs_nodes.id}",
23-
"VpcId" = "${var.vpc_id}"
7+
"AlbId" = aws_lb.ecs.*.id[0],
8+
"AlbArn" = aws_lb.ecs.*.arn[0],
9+
"AlbDnsName" = aws_lb.ecs.*.dns_name[0],
10+
"AlbZoneId" = aws_lb.ecs.*.zone_id[0],
11+
"AlbSecgrpId" = aws_security_group.alb.*.id[0]
12+
"EcsIamRoleArn" = aws_iam_role.ecs.arn,
13+
"EcsIamRoleName" = aws_iam_role.ecs.name,
14+
"EcsServiceIamRoleArn" = aws_iam_role.ecs_service.arn,
15+
"EcsServiceIamRoleName" = aws_iam_role.ecs_service.name,
16+
"EcsTaskIamRoleArn" = aws_iam_role.ecs_task.arn,
17+
"EcsTaskIamRoleName" = aws_iam_role.ecs_task.name,
18+
"EcsId" = aws_ecs_cluster.ecs.*.id[0],
19+
"EcsName" = aws_ecs_cluster.ecs.*.name[0],
20+
"EcsArn" = aws_ecs_cluster.ecs.*.arn[0],
21+
"AlbListenerHttpsArn" = aws_lb_listener.ecs_https.*.arn[0],
22+
"EcsNodesSecGrpId" = aws_security_group.ecs_nodes.id,
23+
"VpcId" = var.vpc_id
2424
}
2525
})
26-
}
26+
}

cloutwatch-alarms.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "aws_cloudwatch_metric_alarm" "high_memory" {
2-
count = "${length(var.alarm_sns_topics) > 0 ? 1 : 0}"
2+
count = length(var.alarm_sns_topics) > 0 ? 1 : 0
33

44
alarm_name = "${data.aws_iam_account_alias.current.account_alias}-ecs-${var.name}-high-memory"
55
comparison_operator = "GreaterThanOrEqualToThreshold"
@@ -14,12 +14,12 @@ resource "aws_cloudwatch_metric_alarm" "high_memory" {
1414
ok_actions = var.alarm_sns_topics
1515

1616
dimensions = {
17-
ClusterName = "${aws_ecs_cluster.ecs.name}"
17+
ClusterName = aws_ecs_cluster.ecs.name
1818
}
1919
}
2020

2121
resource "aws_cloudwatch_metric_alarm" "high_cpu" {
22-
count = "${length(var.alarm_sns_topics) > 0 ? 1 : 0}"
22+
count = length(var.alarm_sns_topics) > 0 ? 1 : 0
2323

2424
alarm_name = "${data.aws_iam_account_alias.current.account_alias}-ecs-${var.name}-high-cpu"
2525
comparison_operator = "GreaterThanOrEqualToThreshold"
@@ -34,6 +34,6 @@ resource "aws_cloudwatch_metric_alarm" "high_cpu" {
3434
ok_actions = var.alarm_sns_topics
3535

3636
dimensions = {
37-
ClusterName = "${aws_ecs_cluster.ecs.name}"
37+
ClusterName = aws_ecs_cluster.ecs.name
3838
}
3939
}

ec2-launch-template.tf

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
data "template_file" "userdata" {
2-
template = "${file("${path.module}/userdata.tpl")}"
2+
template = file("${path.module}/userdata.tpl")
33

44
vars = {
5-
tf_cluster_name = "${aws_ecs_cluster.ecs.name}"
6-
tf_efs_id = "${aws_efs_file_system.ecs.id}"
7-
userdata_extra = "${var.userdata}"
5+
tf_cluster_name = aws_ecs_cluster.ecs.name
6+
tf_efs_id = aws_efs_file_system.ecs.id
7+
userdata_extra = var.userdata
88
}
99
}
1010

1111
resource "aws_launch_template" "ecs" {
1212
name_prefix = "ecs-${var.name}-"
13-
image_id = "${data.aws_ami.amzn.image_id}"
14-
instance_type = "${var.instance_type_1}"
13+
image_id = data.aws_ami.amzn.image_id
14+
instance_type = var.instance_type_1
1515

1616
iam_instance_profile {
17-
name = "${aws_iam_instance_profile.ecs.name}"
17+
name = aws_iam_instance_profile.ecs.name
1818
}
1919

2020
block_device_mappings {
2121
device_name = "/dev/xvda"
2222

2323
ebs {
24-
volume_size = "${var.instance_volume_size_root}"
24+
volume_size = var.instance_volume_size_root
2525
}
2626
}
2727

2828
block_device_mappings {
2929
device_name = "/dev/xvdcz"
3030

3131
ebs {
32-
volume_size = "${var.instance_volume_size}"
32+
volume_size = var.instance_volume_size
3333
}
3434
}
3535

3636
vpc_security_group_ids = concat(list(aws_security_group.ecs_nodes.id), var.security_group_ids)
3737

38-
user_data = "${base64encode(data.template_file.userdata.rendered)}"
38+
user_data = base64encode(data.template_file.userdata.rendered)
3939

4040
lifecycle {
4141
create_before_destroy = true

ecs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
resource "aws_ecs_cluster" "ecs" {
2-
name = "${var.name}"
2+
name = var.name
33
}

0 commit comments

Comments
 (0)