Commit 5add0b77 authored by Felix Edelsten's avatar Felix Edelsten

terraform version 0.12.29

parent b5570009
Pipeline #8332 failed with stage
in 15 seconds
variable "name" { variable "name" {
description = "Name of the VPC" description = "Name of the VPC"
} }
variable "cidr" { variable "cidr" {
description = "The CIDR block for the VPC" description = "The CIDR block for the VPC"
} }
variable "availability_zones" { variable "availability_zones" {
description = "List of availability zones" description = "List of availability zones"
type = "list" type = list(string)
} }
variable "public_subnets" { variable "public_subnets" {
description = "List of public subnets to availability zones" description = "List of public subnets to availability zones"
type = "list" type = list(string)
} }
variable "private_subnets" { variable "private_subnets" {
description = "List of private subnets to availability zones" description = "List of private subnets to availability zones"
type = "list" type = list(string)
} }
variable "enable_dns_hostnames" { variable "enable_dns_hostnames" {
description = "When set to true, instances in the VPC get DNS hostname" description = "When set to true, instances in the VPC get DNS hostname"
default = true default = true
} }
variable "enable_dns_support" { variable "enable_dns_support" {
description = "When set to true, the Amazon DNS server is enabled within the VPC" description = "When set to true, the Amazon DNS server is enabled within the VPC"
default = true default = true
} }
resource "aws_vpc" "mod" { resource "aws_vpc" "mod" {
cidr_block = "${var.cidr}" cidr_block = var.cidr
enable_dns_hostnames = "${var.enable_dns_hostnames}" enable_dns_hostnames = var.enable_dns_hostnames
enable_dns_support = "${var.enable_dns_support}" enable_dns_support = var.enable_dns_support
tags { tags = {
Name = "${var.name}" Name = var.name
} }
} }
resource "aws_subnet" "public" { resource "aws_subnet" "public" {
lifecycle { create_before_destroy = true } lifecycle {
create_before_destroy = true
}
vpc_id = "${aws_vpc.mod.id}" vpc_id = aws_vpc.mod.id
cidr_block = "${element(var.public_subnets, count.index)}" cidr_block = element(var.public_subnets, count.index)
availability_zone = "${element(var.availability_zones, count.index)}" availability_zone = element(var.availability_zones, count.index)
count = "${length(var.public_subnets)}" count = length(var.public_subnets)
map_public_ip_on_launch = true map_public_ip_on_launch = true
tags { tags = {
Name = "${var.name}.public.${element(var.availability_zones, count.index)}" Name = "${var.name}.public.${element(var.availability_zones, count.index)}"
} }
} }
resource "aws_subnet" "private" { resource "aws_subnet" "private" {
lifecycle { create_before_destroy = true } lifecycle {
create_before_destroy = true
vpc_id = "${aws_vpc.mod.id}" }
cidr_block = "${element(var.private_subnets, count.index)}"
availability_zone = "${element(var.availability_zones, count.index)}" vpc_id = aws_vpc.mod.id
count = "${length(var.private_subnets)}" cidr_block = element(var.private_subnets, count.index)
availability_zone = element(var.availability_zones, count.index)
tags { count = length(var.private_subnets)
tags = {
Name = "${var.name}.private.${element(var.availability_zones, count.index)}" Name = "${var.name}.private.${element(var.availability_zones, count.index)}"
} }
} }
resource "aws_internet_gateway" "mod" { resource "aws_internet_gateway" "mod" {
vpc_id = "${aws_vpc.mod.id}" vpc_id = aws_vpc.mod.id
tags { tags = {
Name = "${var.name}" Name = var.name
} }
} }
resource "aws_eip" "nat" { resource "aws_eip" "nat" {
vpc = true vpc = true
count = "${length(var.public_subnets)}" count = length(var.public_subnets)
} }
resource "aws_nat_gateway" "nat" { resource "aws_nat_gateway" "nat" {
subnet_id = "${element(aws_subnet.public.*.id, count.index)}" subnet_id = element(aws_subnet.public.*.id, count.index)
allocation_id = "${element(aws_eip.nat.*.id, count.index)}" allocation_id = element(aws_eip.nat.*.id, count.index)
count = "${length(var.public_subnets)}" count = length(var.public_subnets)
depends_on = ["aws_internet_gateway.mod"] depends_on = [aws_internet_gateway.mod]
} }
resource "aws_route_table" "public" { resource "aws_route_table" "public" {
vpc_id = "${aws_vpc.mod.id}" vpc_id = aws_vpc.mod.id
tags { tags = {
Name = "${var.name}.public" Name = "${var.name}.public"
} }
} }
resource "aws_route_table" "private" { resource "aws_route_table" "private" {
vpc_id = "${aws_vpc.mod.id}" vpc_id = aws_vpc.mod.id
count = "${length(var.private_subnets)}" count = length(var.private_subnets)
tags { tags = {
Name = "${var.name}.private.${element(var.availability_zones, count.index)}" Name = "${var.name}.private.${element(var.availability_zones, count.index)}"
} }
} }
resource "aws_route" "public_internet_gateway" { resource "aws_route" "public_internet_gateway" {
route_table_id = "${aws_route_table.public.id}" route_table_id = aws_route_table.public.id
destination_cidr_block = "0.0.0.0/0" destination_cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.mod.id}" gateway_id = aws_internet_gateway.mod.id
} }
resource "aws_route" "nat_gateway" { resource "aws_route" "nat_gateway" {
route_table_id = "${element(aws_route_table.private.*.id, count.index)}" route_table_id = element(aws_route_table.private.*.id, count.index)
destination_cidr_block = "0.0.0.0/0" destination_cidr_block = "0.0.0.0/0"
nat_gateway_id = "${element(aws_nat_gateway.nat.*.id, count.index)}" nat_gateway_id = element(aws_nat_gateway.nat.*.id, count.index)
count = "${length(var.public_subnets)}" count = length(var.public_subnets)
depends_on = ["aws_route_table.private"] depends_on = [aws_route_table.private]
} }
resource "aws_route_table_association" "public" { resource "aws_route_table_association" "public" {
subnet_id = "${element(aws_subnet.public.*.id, count.index)}" subnet_id = element(aws_subnet.public.*.id, count.index)
route_table_id = "${aws_route_table.public.id}" route_table_id = aws_route_table.public.id
count = "${length(var.public_subnets)}" count = length(var.public_subnets)
} }
resource "aws_route_table_association" "private" { resource "aws_route_table_association" "private" {
subnet_id = "${element(aws_subnet.private.*.id, count.index)}" subnet_id = element(aws_subnet.private.*.id, count.index)
route_table_id = "${element(aws_route_table.private.*.id, count.index)}" route_table_id = element(aws_route_table.private.*.id, count.index)
count = "${length(var.private_subnets)}" count = length(var.private_subnets)
} }
output "private_subnets" { output "private_subnets" {
value = ["${aws_subnet.private.*.id}"] value = aws_subnet.private.*.id
} }
output "public_subnets" { output "public_subnets" {
value = ["${aws_subnet.public.*.id}"] value = aws_subnet.public.*.id
} }
output "vpc_id" { output "vpc_id" {
value = "${aws_vpc.mod.id}" value = aws_vpc.mod.id
} }
output "public_route_table_id" { output "public_route_table_id" {
value = "${aws_route_table.public.id}" value = aws_route_table.public.id
} }
output "private_route_table_ids" { output "private_route_table_ids" {
value = ["${aws_route_table.private.*.id}"] value = aws_route_table.private.*.id
} }
output "nat_gateway_public_ips" { output "nat_gateway_public_ips" {
value = ["${aws_eip.nat.*.public_ip}"] value = aws_eip.nat.*.public_ip
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment