Created
April 28, 2016 16:17
-
-
Save anoldguy/14dde9fd4dab134143ced50b2b3d9c6d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "aws_region" { | |
description = "EC2 Region for the VPC" | |
default = "us-east-1" | |
} | |
variable "amis" { | |
description = "AMIs by region" | |
default = { | |
eu-west-1 = "ami-f1810f86" # ubuntu 14.04 LTS | |
} | |
} | |
variable "vpc_cidr" { | |
description = "CIDR for the whole VPC" | |
default = "10.1.0.0/16" | |
} | |
variable "public_subnet_cidr" { | |
description = "CIDR for the Public Subnet" | |
default = "10.1.0.0/24" | |
} | |
variable "private_subnet_cidr" { | |
description = "CIDR for the Private Subnet" | |
default = "10.1.1.0/24" | |
} | |
resource "aws_vpc" "default" { | |
cidr_block = "${var.vpc_cidr}" | |
enable_dns_hostnames = true | |
tags { | |
Name = "terraform-aws-vpc-abc123" | |
} | |
} | |
resource "aws_internet_gateway" "default" { | |
vpc_id = "${aws_vpc.default.id}" | |
} | |
resource "aws_eip" "nat" { | |
vpc = true | |
} | |
resource "aws_nat_gateway" "gw" { | |
allocation_id = "${aws_eip.nat.id}" | |
subnet_id = "${aws_subnet.us-east-1a-public.id}" | |
} | |
/* | |
Public Subnet | |
*/ | |
resource "aws_subnet" "us-east-1a-public" { | |
vpc_id = "${aws_vpc.default.id}" | |
cidr_block = "${var.public_subnet_cidr}" | |
availability_zone = "us-east-1a" | |
tags { | |
Name = "Test Public Subnet" | |
} | |
} | |
resource "aws_route_table" "us-east-1a-public" { | |
vpc_id = "${aws_vpc.default.id}" | |
route { | |
cidr_block = "0.0.0.0/0" | |
gateway_id = "${aws_internet_gateway.default.id}" | |
} | |
tags { | |
Name = "Test Public Subnet" | |
} | |
} | |
resource "aws_route_table_association" "us-east-1a-public" { | |
subnet_id = "${aws_subnet.us-east-1a-public.id}" | |
route_table_id = "${aws_route_table.us-east-1a-public.id}" | |
} | |
/* | |
Private Subnet | |
*/ | |
resource "aws_subnet" "us-east-1a-private" { | |
vpc_id = "${aws_vpc.default.id}" | |
cidr_block = "${var.private_subnet_cidr}" | |
availability_zone = "us-east-1a" | |
tags { | |
Name = "Test Private Subnet" | |
} | |
} | |
resource "aws_route_table" "us-east-1a-private" { | |
vpc_id = "${aws_vpc.default.id}" | |
route { | |
cidr_block = "0.0.0.0/0" | |
nat_gateway_id = "${aws_nat_gateway.gw.id}" | |
} | |
tags { | |
Name = "Test Private Subnet" | |
} | |
} | |
resource "aws_route_table_association" "us-east-1a-private" { | |
subnet_id = "${aws_subnet.us-east-1a-private.id}" | |
route_table_id = "${aws_route_table.us-east-1a-private.id}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment