Skip to content

Commit

Permalink
add terraform 0.12 support for 05 example
Browse files Browse the repository at this point in the history
  • Loading branch information
diodonfrost committed Sep 20, 2019
1 parent 09bcd35 commit e277007
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 66 deletions.
9 changes: 5 additions & 4 deletions 05-autoscaling-group/00-params.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand All @@ -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"
}
}

Expand All @@ -46,3 +46,4 @@ variable "autoscaling_db" {
min_size = "1"
}
}

1 change: 1 addition & 0 deletions 05-autoscaling-group/010-ssh-key.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 protected]"
}

31 changes: 16 additions & 15 deletions 05-autoscaling-group/020-network.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

19 changes: 10 additions & 9 deletions 05-autoscaling-group/030-security-group.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -93,3 +93,4 @@ resource "aws_security_group" "db" {
cidr_blocks = ["0.0.0.0/0"]
}
}

33 changes: 18 additions & 15 deletions 05-autoscaling-group/060-instance-http.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,34 +19,37 @@ resource "aws_elb" "http" {
target = "HTTP:80/"
interval = 30
}
tags {
tags = {
Name = "http-lb"
}
}

# 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")
}

33 changes: 18 additions & 15 deletions 05-autoscaling-group/061-instance-db.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -20,34 +20,37 @@ resource "aws_elb" "db" {
target = "TCP:3306"
interval = 30
}
tags {
tags = {
Name = "db-lb"
}
}

# 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")
}

13 changes: 7 additions & 6 deletions 05-autoscaling-group/071-routing-table.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

5 changes: 3 additions & 2 deletions 05-autoscaling-group/100-outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

4 changes: 4 additions & 0 deletions 05-autoscaling-group/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

terraform {
required_version = ">= 0.12"
}

0 comments on commit e277007

Please sign in to comment.