From e277007c6eb0e095809a124a890dc1fe32cc5688 Mon Sep 17 00:00:00 2001 From: diodonfrost Date: Fri, 20 Sep 2019 21:05:24 +0200 Subject: [PATCH] add terraform 0.12 support for 05 example --- 05-autoscaling-group/00-params.tf | 9 +++--- 05-autoscaling-group/010-ssh-key.tf | 1 + 05-autoscaling-group/020-network.tf | 31 ++++++++++---------- 05-autoscaling-group/030-security-group.tf | 19 +++++++------ 05-autoscaling-group/060-instance-http.tf | 33 ++++++++++++---------- 05-autoscaling-group/061-instance-db.tf | 33 ++++++++++++---------- 05-autoscaling-group/071-routing-table.tf | 13 +++++---- 05-autoscaling-group/100-outputs.tf | 5 ++-- 05-autoscaling-group/versions.tf | 4 +++ 9 files changed, 82 insertions(+), 66 deletions(-) create mode 100644 05-autoscaling-group/versions.tf diff --git a/05-autoscaling-group/00-params.tf b/05-autoscaling-group/00-params.tf index 0dd5b02..1f76d76 100644 --- a/05-autoscaling-group/00-params.tf +++ b/05-autoscaling-group/00-params.tf @@ -16,8 +16,8 @@ variable "vpc_cidr" { #### HTTP PARAMS variable "network_http" { default = { - subnet_name = "subnet_http" - cidr = "192.168.1.0/24" + subnet_name = "subnet_http" + cidr = "192.168.1.0/24" } } @@ -33,8 +33,8 @@ variable "autoscaling_http" { #### DB PARAMS variable "network_db" { default = { - subnet_name = "subnet_db" - cidr = "192.168.2.0/24" + subnet_name = "subnet_db" + cidr = "192.168.2.0/24" } } @@ -46,3 +46,4 @@ variable "autoscaling_db" { min_size = "1" } } + diff --git a/05-autoscaling-group/010-ssh-key.tf b/05-autoscaling-group/010-ssh-key.tf index 2a3c326..9862c16 100644 --- a/05-autoscaling-group/010-ssh-key.tf +++ b/05-autoscaling-group/010-ssh-key.tf @@ -5,3 +5,4 @@ resource "aws_key_pair" "user_key" { key_name = "user-key" public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 email@example.com" } + diff --git a/05-autoscaling-group/020-network.tf b/05-autoscaling-group/020-network.tf index 7b84532..551dfbf 100644 --- a/05-autoscaling-group/020-network.tf +++ b/05-autoscaling-group/020-network.tf @@ -2,37 +2,38 @@ # VPC creation resource "aws_vpc" "terraform" { - cidr_block = "${var.vpc_cidr}" + cidr_block = var.vpc_cidr enable_dns_hostnames = true - tags = { - Name = "vpc_http" + tags = { + Name = "vpc_http" } } # http subnet configuration resource "aws_subnet" "http" { - vpc_id = "${aws_vpc.terraform.id}" - cidr_block = "${var.network_http["cidr"]}" - tags = { - Name = "subnet_http" + vpc_id = aws_vpc.terraform.id + cidr_block = var.network_http["cidr"] + tags = { + Name = "subnet_http" } - depends_on = ["aws_internet_gateway.gw"] + depends_on = [aws_internet_gateway.gw] } # db subnet configuration resource "aws_subnet" "db" { - vpc_id = "${aws_vpc.terraform.id}" - cidr_block = "${var.network_db["cidr"]}" - tags = { - Name = "subnet_db" + vpc_id = aws_vpc.terraform.id + cidr_block = var.network_db["cidr"] + tags = { + Name = "subnet_db" } - depends_on = ["aws_internet_gateway.gw"] + depends_on = [aws_internet_gateway.gw] } # External gateway configuration resource "aws_internet_gateway" "gw" { - vpc_id = "${aws_vpc.terraform.id}" - tags = { + vpc_id = aws_vpc.terraform.id + tags = { Name = "internet_gateway" } } + diff --git a/05-autoscaling-group/030-security-group.tf b/05-autoscaling-group/030-security-group.tf index 2ac88ea..d2b0734 100644 --- a/05-autoscaling-group/030-security-group.tf +++ b/05-autoscaling-group/030-security-group.tf @@ -4,9 +4,9 @@ resource "aws_security_group" "administration" { name = "administration" description = "Allow default administration service" - vpc_id = "${aws_vpc.terraform.id}" - tags = { - Name = "administration" + vpc_id = aws_vpc.terraform.id + tags = { + Name = "administration" } # Open ssh port @@ -38,9 +38,9 @@ resource "aws_security_group" "administration" { resource "aws_security_group" "web" { name = "web" description = "Allow web incgress trafic" - vpc_id = "${aws_vpc.terraform.id}" - tags = { - Name = "web" + vpc_id = aws_vpc.terraform.id + tags = { + Name = "web" } # http port @@ -72,9 +72,9 @@ resource "aws_security_group" "web" { resource "aws_security_group" "db" { name = "db" description = "Allow db incgress trafic" - vpc_id = "${aws_vpc.terraform.id}" - tags = { - Name = "db" + vpc_id = aws_vpc.terraform.id + tags = { + Name = "db" } # db port @@ -93,3 +93,4 @@ resource "aws_security_group" "db" { cidr_blocks = ["0.0.0.0/0"] } } + diff --git a/05-autoscaling-group/060-instance-http.tf b/05-autoscaling-group/060-instance-http.tf index c6e9a89..73d8cbf 100644 --- a/05-autoscaling-group/060-instance-http.tf +++ b/05-autoscaling-group/060-instance-http.tf @@ -3,7 +3,7 @@ # Create load balancer resource "aws_elb" "http" { name = "http-lb" - subnets = ["${aws_subnet.http.id}"] + subnets = [aws_subnet.http.id] listener { instance_port = 80 @@ -19,7 +19,7 @@ resource "aws_elb" "http" { target = "HTTP:80/" interval = 30 } - tags { + tags = { Name = "http-lb" } } @@ -27,26 +27,29 @@ resource "aws_elb" "http" { # Create autoscaling group resource "aws_autoscaling_group" "http" { name = "http-autoscaling-group" - max_size = "${var.autoscaling_http["max_size"]}" - min_size = "${var.autoscaling_http["min_size"]}" - desired_capacity = "${var.autoscaling_http["desired_capacity"]}" + max_size = var.autoscaling_http["max_size"] + min_size = var.autoscaling_http["min_size"] + desired_capacity = var.autoscaling_http["desired_capacity"] health_check_type = "ELB" default_cooldown = "30" health_check_grace_period = "120" force_delete = true - launch_configuration = "${aws_launch_configuration.http.name}" - load_balancers = ["${aws_elb.http.name}"] + launch_configuration = aws_launch_configuration.http.name + load_balancers = [aws_elb.http.name] termination_policies = ["OldestLaunchConfiguration"] - vpc_zone_identifier = ["${aws_subnet.http.id}"] + vpc_zone_identifier = [aws_subnet.http.id] } # Configure instance launching configuration resource "aws_launch_configuration" "http" { - name_prefix = "http" - image_id = "${var.ami}" - instance_type = "t2.micro" - key_name = "${aws_key_pair.user_key.key_name}" - security_groups = ["${aws_security_group.administration.id}", - "${aws_security_group.web.id}"] - user_data = "${file("scripts/first-boot-http.sh")}" + name_prefix = "http" + image_id = var.ami + instance_type = "t2.micro" + key_name = aws_key_pair.user_key.key_name + security_groups = [ + aws_security_group.administration.id, + aws_security_group.web.id, + ] + user_data = file("scripts/first-boot-http.sh") } + diff --git a/05-autoscaling-group/061-instance-db.tf b/05-autoscaling-group/061-instance-db.tf index 5f4dcfb..356d79b 100644 --- a/05-autoscaling-group/061-instance-db.tf +++ b/05-autoscaling-group/061-instance-db.tf @@ -3,7 +3,7 @@ # Create load balancer resource "aws_elb" "db" { name = "db-lb" - subnets = ["${aws_subnet.db.id}"] + subnets = [aws_subnet.db.id] internal = "true" listener { @@ -20,7 +20,7 @@ resource "aws_elb" "db" { target = "TCP:3306" interval = 30 } - tags { + tags = { Name = "db-lb" } } @@ -28,26 +28,29 @@ resource "aws_elb" "db" { # Create autoscaling group resource "aws_autoscaling_group" "db" { name = "db-autoscaling-group" - max_size = "${var.autoscaling_db["max_size"]}" - min_size = "${var.autoscaling_db["min_size"]}" - desired_capacity = "${var.autoscaling_db["desired_capacity"]}" + max_size = var.autoscaling_db["max_size"] + min_size = var.autoscaling_db["min_size"] + desired_capacity = var.autoscaling_db["desired_capacity"] health_check_type = "ELB" default_cooldown = "30" health_check_grace_period = "120" force_delete = true - launch_configuration = "${aws_launch_configuration.db.name}" - load_balancers = ["${aws_elb.db.name}"] + launch_configuration = aws_launch_configuration.db.name + load_balancers = [aws_elb.db.name] termination_policies = ["OldestLaunchConfiguration"] - vpc_zone_identifier = ["${aws_subnet.db.id}"] + vpc_zone_identifier = [aws_subnet.db.id] } # Configure instance launching configuration resource "aws_launch_configuration" "db" { - name_prefix = "db" - image_id = "${var.ami}" - instance_type = "t2.micro" - key_name = "${aws_key_pair.user_key.key_name}" - security_groups = ["${aws_security_group.administration.id}", - "${aws_security_group.web.id}"] - user_data = "${file("scripts/first-boot-db.sh")}" + name_prefix = "db" + image_id = var.ami + instance_type = "t2.micro" + key_name = aws_key_pair.user_key.key_name + security_groups = [ + aws_security_group.administration.id, + aws_security_group.web.id, + ] + user_data = file("scripts/first-boot-db.sh") } + diff --git a/05-autoscaling-group/071-routing-table.tf b/05-autoscaling-group/071-routing-table.tf index 11d85ae..273f017 100644 --- a/05-autoscaling-group/071-routing-table.tf +++ b/05-autoscaling-group/071-routing-table.tf @@ -2,21 +2,22 @@ # Routing table configuration resource "aws_route_table" "public" { - vpc_id = "${aws_vpc.terraform.id}" + vpc_id = aws_vpc.terraform.id route { cidr_block = "0.0.0.0/0" - gateway_id = "${aws_internet_gateway.gw.id}" + gateway_id = aws_internet_gateway.gw.id } } # Associate http route resource "aws_route_table_association" "http" { - subnet_id = "${aws_subnet.http.id}" - route_table_id = "${aws_route_table.public.id}" + subnet_id = aws_subnet.http.id + route_table_id = aws_route_table.public.id } # Associate db route resource "aws_route_table_association" "db" { - subnet_id = "${aws_subnet.db.id}" - route_table_id = "${aws_route_table.public.id}" + subnet_id = aws_subnet.db.id + route_table_id = aws_route_table.public.id } + diff --git a/05-autoscaling-group/100-outputs.tf b/05-autoscaling-group/100-outputs.tf index 6409723..3e6a67c 100644 --- a/05-autoscaling-group/100-outputs.tf +++ b/05-autoscaling-group/100-outputs.tf @@ -2,10 +2,11 @@ # Display http loadbalancer dns name output "lb_hostname_http" { - value = "${aws_elb.http.dns_name}" + value = aws_elb.http.dns_name } # Display db loadbalancer dns name output "lb_hostname_db" { - value = "${aws_elb.db.dns_name}" + value = aws_elb.db.dns_name } + diff --git a/05-autoscaling-group/versions.tf b/05-autoscaling-group/versions.tf new file mode 100644 index 0000000..ac97c6a --- /dev/null +++ b/05-autoscaling-group/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +}