resource "aws_vpc" "main" { cidr_block = "${var.cidr}" enable_dns_hostnames = "${var.enable_dns_hostnames}" enable_dns_support = "${var.enable_dns_support}" tags { Name = "${var.name}" managed_by = "terraform" } } resource "aws_internet_gateway" "main" { vpc_id = "${aws_vpc.main.id}" tags { Name = "${var.name}-igw" managed_by = "terraform" } } resource "aws_route_table" "public" { vpc_id = "${aws_vpc.main.id}" propagating_vgws = ["${var.public_propagating_vgws}"] tags { Name = "${var.name}-rt-public" managed_by = "terraform" } } resource "aws_route" "public_internet_gateway" { route_table_id = "${aws_route_table.public.id}" destination_cidr_block = "0.0.0.0/0" gateway_id = "${aws_internet_gateway.main.id}" } resource "aws_route" "private_nat_gateway" { route_table_id = "${aws_route_table.private.id}" destination_cidr_block = "0.0.0.0/0" nat_gateway_id = "${aws_nat_gateway.natgw.id}" } resource "aws_route_table" "private" { vpc_id = "${aws_vpc.main.id}" propagating_vgws = ["${var.private_propagating_vgws}"] tags { Name = "${var.name}-rt-private-${data.aws_availability_zones.available.names[1]}" managed_by = "terraform" } } resource "aws_subnet" "public" { vpc_id = "${aws_vpc.main.id}" cidr_block = "${var.public_subnet}" availability_zone = "${data.aws_availability_zones.available.names[0]}" tags { Name = "${var.name}-subnet-public-${data.aws_availability_zones.available.names[0]}" managed_by = "terraform" } map_public_ip_on_launch = "${var.map_public_ip_on_launch}" } resource "aws_subnet" "private" { vpc_id = "${aws_vpc.main.id}" cidr_block = "${var.private_subnet}" availability_zone = "${data.aws_availability_zones.available.names[1]}" tags { Name = "${var.name}-rt-private-${data.aws_availability_zones.available.names[1]}" managed_by = "terraform" } } resource "aws_eip" "nateip" { vpc = true } resource "aws_nat_gateway" "natgw" { allocation_id = "${aws_eip.nateip.id}" subnet_id = "${aws_subnet.public.id}" depends_on = ["aws_internet_gateway.main"] } resource "aws_route_table_association" "public" { subnet_id = "${aws_subnet.public.id}" route_table_id = "${aws_route_table.public.id}" } resource "aws_route_table_association" "private" { subnet_id = "${aws_subnet.private.id}" route_table_id = "${aws_route_table.private.id}" } resource "aws_security_group" "inbound" { name = "allow-ssh-wnb" vpc_id = "${aws_vpc.main.id}" description = "Allows external incoming ssh and web traffic" ingress { from_port = 22 to_port = 22 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } ingress { from_port = 80 to_port = 80 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } ingress { from_port = 8080 to_port = 8080 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } ingress { from_port = 443 to_port = 443 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } egress { from_port = 0 to_port = 0 protocol = -1 cidr_blocks = ["0.0.0.0/0"] } lifecycle { create_before_destroy = true } }