Skip to content

Instantly share code, notes, and snippets.

@MaG21
Forked from shaselton/vpc.tf
Created August 8, 2021 04:26
Show Gist options
  • Save MaG21/be97174db36d03200b22236735f1331a to your computer and use it in GitHub Desktop.
Save MaG21/be97174db36d03200b22236735f1331a to your computer and use it in GitHub Desktop.
VPC template
# Rough Implementation of the pattern found here: https://medium.com/aws-activate-startup-blog/practical-vpc-design-8412e1a18dcc
provider "aws" {
region = "us-east-1"
}
# create a vpc
resource "aws_vpc" "shaselton" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true
tags {
Name = "shaselton_vpc"
}
}
# AZ A
resource "aws_subnet" "az_a_private" {
vpc_id = "${aws_vpc.shaselton.id}"
cidr_block = "10.0.0.0/19"
availability_zone = "us-east-1a"
tags {
Name = "Availability Zone A Private"
}
}
resource "aws_subnet" "az_a_public" {
vpc_id = "${aws_vpc.shaselton.id}"
cidr_block = "10.0.32.0/20"
availability_zone = "us-east-1a"
tags {
Name = "Availability Zone A Public"
}
}
resource "aws_subnet" "az_a_public_protected" {
vpc_id = "${aws_vpc.shaselton.id}"
cidr_block = "10.0.48.0/21"
availability_zone = "us-east-1a"
tags {
Name = "Availability Zone A Public Protected"
}
}
resource "aws_subnet" "az_a_public_spare" {
vpc_id = "${aws_vpc.shaselton.id}"
cidr_block = "10.0.56.0/21"
availability_zone = "us-east-1a"
tags {
Name = "Availability Zone A Public Spare"
}
}
# AZ B
resource "aws_subnet" "az_b_private" {
vpc_id = "${aws_vpc.shaselton.id}"
cidr_block = "10.0.64.0/19"
availability_zone = "us-east-1b"
tags {
Name = "Availability Zone B Private"
}
}
resource "aws_subnet" "az_b_public" {
vpc_id = "${aws_vpc.shaselton.id}"
cidr_block = "10.0.96.0/20"
availability_zone = "us-east-1b"
tags {
Name = "Availability Zone B Public"
}
}
resource "aws_subnet" "az_b_public_protected" {
vpc_id = "${aws_vpc.shaselton.id}"
cidr_block = "10.0.112.0/21"
availability_zone = "us-east-1b"
tags {
Name = "Availability Zone B Public Protected"
}
}
resource "aws_subnet" "az_b_public_spare" {
vpc_id = "${aws_vpc.shaselton.id}"
cidr_block = "10.0.120.0/21"
availability_zone = "us-east-1b"
tags {
Name = "Availability Zone B Public Spare"
}
}
# AZ C
resource "aws_subnet" "az_c_private" {
vpc_id = "${aws_vpc.shaselton.id}"
cidr_block = "10.0.128.0/19"
availability_zone = "us-east-1c"
tags {
Name = "Availability Zone C Private"
}
}
resource "aws_subnet" "az_c_public" {
vpc_id = "${aws_vpc.shaselton.id}"
cidr_block = "10.0.160.0/20"
availability_zone = "us-east-1c"
tags {
Name = "Availability Zone C Public"
}
}
resource "aws_subnet" "az_c_public_protected" {
vpc_id = "${aws_vpc.shaselton.id}"
cidr_block = "10.0.176.0/21"
availability_zone = "us-east-1c"
tags {
Name = "Availability Zone C Public Protected"
}
}
resource "aws_subnet" "az_c_public_spare" {
vpc_id = "${aws_vpc.shaselton.id}"
cidr_block = "10.0.184.0/21"
availability_zone = "us-east-1c"
tags {
Name = "Availability Zone C Public Spare"
}
}
resource "aws_subnet" "spare_subnet" {
vpc_id = "${aws_vpc.shaselton.id}"
cidr_block = "10.0.192.0/18"
tags {
Name = "Spare Subnet Space"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment