Skip to content

Instantly share code, notes, and snippets.

@c4milo
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c4milo/4c68e16a33fdfe7e8380 to your computer and use it in GitHub Desktop.
Save c4milo/4c68e16a33fdfe7e8380 to your computer and use it in GitHub Desktop.
/*
* Sets up global resources such as VPC, route table and subnets.
*/
provider "aws" {
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
region = "${var.region}"
}
// DHCP Options Set
resource "aws_vpc_dhcp_options" "staging_dos" {
domain_name = "service.consul"
domain_name_servers = "127.0.0.1, AmazonProvidedDNS"
ntp_servers = "127.0.0.1"
netbios_name_servers = "127.0.0.1"
netbios_node_type = 2
tags {
Name = "consul-dns-resolver-stg"
}
}
resource "aws_vpc_dhcp_options_association" "dos_association" {
vpc_id = "${aws_vpc.main.id}"
dhcp_options_id = "${aws_vpc_dhcp_options.staging_dos.id}"
}
// VPC
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
tags {
Name = "main"
}
enable_dns_support = true
enable_dns_hostnames = true
}
resource "aws_internet_gateway" "network" {
vpc_id = "${aws_vpc.main.id}"
}
resource "aws_route_table" "network" {
vpc_id = "${aws_vpc.main.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.network.id}"
}
}
resource "aws_main_route_table_association" "vpc-main-route-table" {
vpc_id = "${aws_vpc.main.id}"
route_table_id = "${aws_route_table.network.id}"
}
// Subnet A
resource "aws_subnet" "subnet_a" {
vpc_id = "${aws_vpc.main.id}"
availability_zone = "${var.zone_a}"
cidr_block = "10.0.0.0/24"
map_public_ip_on_launch = true
tags {
Name = "${var.env}-a"
}
}
resource "aws_route_table_association" "network_a" {
subnet_id = "${aws_subnet.subnet_a.id}"
route_table_id = "${aws_route_table.network.id}"
}
// Subnet B
resource "aws_subnet" "subnet_b" {
vpc_id = "${aws_vpc.main.id}"
availability_zone = "${var.zone_b}"
cidr_block = "10.0.1.0/24"
map_public_ip_on_launch = true
tags {
Name = "${var.env}-b"
}
}
resource "aws_route_table_association" "network_b" {
subnet_id = "${aws_subnet.subnet_b.id}"
route_table_id = "${aws_route_table.network.id}"
}
output "vpc-id" {
value = "${aws_vpc.main.id}"
}
output "subnet-a-id" {
value = "${aws_subnet.subnet_a.id}"
}
output "subnet-b-id" {
value = "${aws_subnet.subnet_b.id}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment