Skip to content

Commit 4612040

Browse files
committed
Updated Terraform 0.12
1 parent 820e5f5 commit 4612040

File tree

11 files changed

+49
-50
lines changed

11 files changed

+49
-50
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
repos:
22
- repo: git://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.11.0
3+
rev: v1.12.0
44
hooks:
55
- id: terraform_fmt
6-
- id: terraform_docs
6+
# - id: terraform_docs
77
- repo: git://github.com/pre-commit/pre-commit-hooks
8-
rev: v2.1.0
8+
rev: v2.2.3
99
hooks:
1010
- id: check-merge-conflict

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ Sometimes you need to have a way to create ECS resources conditionally but Terra
3232
```hcl
3333
# ECS cluster will not be created
3434
module "ecs" {
35-
source = "terraform-aws-modules/ecs/aws"
35+
source = "terraform-aws-modules/ecs/aws"
36+
version = "~> 2.0"
3637
3738
create_ecs = false
3839
# ... omitted

examples/complete-ecs/main.tf

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ provider "aws" {
22
region = "eu-west-1"
33
}
44

5-
provider "terraform" {}
6-
75
locals {
86
name = "complete-ecs"
97
environment = "dev"
@@ -14,40 +12,40 @@ locals {
1412

1513
module "vpc" {
1614
source = "terraform-aws-modules/vpc/aws"
15+
version = "~> 2.0"
1716

18-
name = "${local.name}"
17+
name = local.name
1918

2019
cidr = "10.1.0.0/16"
2120

2221
azs = ["eu-west-1a", "eu-west-1b"]
2322
private_subnets = ["10.1.1.0/24", "10.1.2.0/24"]
2423
public_subnets = ["10.1.11.0/24", "10.1.12.0/24"]
2524

26-
enable_nat_gateway = true
27-
single_nat_gateway = true
25+
enable_nat_gateway = false # this is faster, but should be "true" for real
2826

2927
tags = {
30-
Environment = "${local.environment}"
31-
Name = "${local.name}"
28+
Environment = local.environment
29+
Name = local.name
3230
}
3331
}
3432

3533
#----- ECS --------
3634
module "ecs" {
3735
source = "../../"
38-
name = "${local.name}"
36+
name = local.name
3937
}
4038

4139
module "ec2-profile" {
4240
source = "../../modules/ecs-instance-profile"
43-
name = "${local.name}"
41+
name = local.name
4442
}
4543

4644
#----- ECS Services--------
4745

4846
module "hello-world" {
49-
source = "service-hello-world"
50-
cluster_id = "${module.ecs.this_ecs_cluster_id}"
47+
source = "./service-hello-world"
48+
cluster_id = module.ecs.this_ecs_cluster_id
5149
}
5250

5351
#----- ECS Resources--------
@@ -56,6 +54,8 @@ module "hello-world" {
5654
data "aws_ami" "amazon_linux_ecs" {
5755
most_recent = true
5856

57+
owners = ["amazon"]
58+
5959
filter {
6060
name = "name"
6161
values = ["amzn-ami-*-amazon-ecs-optimized"]
@@ -68,46 +68,47 @@ data "aws_ami" "amazon_linux_ecs" {
6868
}
6969

7070
module "this" {
71-
source = "terraform-aws-modules/autoscaling/aws"
71+
source = "terraform-aws-modules/autoscaling/aws"
72+
version = "~> 3.0"
7273

73-
name = "${local.ec2_resources_name}"
74+
name = local.ec2_resources_name
7475

7576
# Launch configuration
76-
lc_name = "${local.ec2_resources_name}"
77+
lc_name = local.ec2_resources_name
7778

78-
image_id = "${data.aws_ami.amazon_linux_ecs.id}"
79+
image_id = data.aws_ami.amazon_linux_ecs.id
7980
instance_type = "t2.micro"
80-
security_groups = ["${module.vpc.default_security_group_id}"]
81-
iam_instance_profile = "${module.ec2-profile.this_iam_instance_profile_id}"
82-
user_data = "${data.template_file.user_data.rendered}"
81+
security_groups = [module.vpc.default_security_group_id]
82+
iam_instance_profile = module.ec2-profile.this_iam_instance_profile_id
83+
user_data = data.template_file.user_data.rendered
8384

8485
# Auto scaling group
85-
asg_name = "${local.ec2_resources_name}"
86-
vpc_zone_identifier = "${module.vpc.private_subnets}"
86+
asg_name = local.ec2_resources_name
87+
vpc_zone_identifier = module.vpc.private_subnets
8788
health_check_type = "EC2"
8889
min_size = 0
8990
max_size = 1
90-
desired_capacity = 1
91+
desired_capacity = 0
9192
wait_for_capacity_timeout = 0
9293

9394
tags = [
9495
{
9596
key = "Environment"
96-
value = "${local.environment}"
97+
value = local.environment
9798
propagate_at_launch = true
9899
},
99100
{
100101
key = "Cluster"
101-
value = "${local.name}"
102+
value = local.name
102103
propagate_at_launch = true
103104
},
104105
]
105106
}
106107

107108
data "template_file" "user_data" {
108-
template = "${file("${path.module}/templates/user-data.sh")}"
109+
template = file("${path.module}/templates/user-data.sh")
109110

110-
vars {
111-
cluster_name = "${local.name}"
111+
vars = {
112+
cluster_name = local.name
112113
}
113114
}

examples/complete-ecs/service-hello-world/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ EOF
2828

2929
resource "aws_ecs_service" "hello_world" {
3030
name = "hello_world"
31-
cluster = "${var.cluster_id}"
32-
task_definition = "${aws_ecs_task_definition.hello_world.arn}"
31+
cluster = var.cluster_id
32+
task_definition = aws_ecs_task_definition.hello_world.arn
3333

3434
desired_count = 1
3535

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
variable "cluster_id" {
22
description = "The ECS cluster ID"
3+
type = string
34
}

main.tf

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
terraform {
2-
required_version = ">= 0.11.7"
3-
}
4-
5-
provider "template" {
6-
version = ">= 1.0.0"
7-
}
8-
91
resource "aws_ecs_cluster" "this" {
10-
count = "${var.create_ecs ? 1 : 0}"
2+
count = var.create_ecs ? 1 : 0
113

12-
name = "${var.name}"
13-
tags = "${var.tags}"
4+
name = var.name
5+
tags = var.tags
146
}

modules/ecs-instance-profile/instance-policy.tf renamed to modules/ecs-instance-profile/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ EOF
2020

2121
resource "aws_iam_instance_profile" "this" {
2222
name = "${var.name}_ecs_instance_profile"
23-
role = "${aws_iam_role.this.name}"
23+
role = aws_iam_role.this.name
2424
}
2525

2626
resource "aws_iam_role_policy_attachment" "ecs_ec2_role" {
27-
role = "${aws_iam_role.this.id}"
27+
role = aws_iam_role.this.id
2828
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"
2929
}
3030

3131
resource "aws_iam_role_policy_attachment" "ecs_ec2_cloudwatch_role" {
32-
role = "${aws_iam_role.this.id}"
32+
role = aws_iam_role.this.id
3333
policy_arn = "arn:aws:iam::aws:policy/CloudWatchLogsFullAccess"
3434
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
output "this_iam_instance_profile_id" {
2-
value = "${aws_iam_instance_profile.this.id}"
2+
value = aws_iam_instance_profile.this.id
33
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
variable "name" {
22
description = "Name to be used on all the resources as identifier"
3+
type = string
34
}

outputs.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
output "this_ecs_cluster_id" {
2-
value = "${element(concat(aws_ecs_cluster.this.*.id, list("")), 0)}"
2+
value = concat(aws_ecs_cluster.this.*.id, [""])[0]
33
}
44

55
output "this_ecs_cluster_arn" {
6-
value = "${element(concat(aws_ecs_cluster.this.*.arn, list("")), 0)}"
6+
value = concat(aws_ecs_cluster.this.*.arn, [""])[0]
77
}
88

99
output "this_ecs_cluster_name" {
1010
description = "The name of the ECS cluster"
11-
value = "${var.name}"
11+
value = var.name
1212
}

0 commit comments

Comments
 (0)