Skip to content

Instantly share code, notes, and snippets.

@samkeen
Last active March 20, 2016 04:23
Show Gist options
  • Save samkeen/392fbc667b2822bbb106 to your computer and use it in GitHub Desktop.
Save samkeen/392fbc667b2822bbb106 to your computer and use it in GitHub Desktop.
Lean version of 3 subnet VPC Template
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "VPC Across 3 AZs",
"Parameters": {
"EnvName": {
"Type": "String",
"Default": "Dev",
"AllowedValues": [
"Dev", "Test", "Prod"
],
"Description": "Select the environment name"
},
"TargetAZs": {
"Description": "AZs to create Subnets for. Hardcoded to 3 currently, if you do not supply 3, stack will fail.",
"Type": "List<AWS::EC2::AvailabilityZone::Name>"
}
},
"Mappings": {
"SubnetConfig": {
"VPC": {
"CIDR": "10.0.0.0/16"
}, "AZ1-Public": {
"CIDR": "10.0.32.0/20"
}, "AZ1-Private": {
"CIDR": "10.0.0.0/19"
}, "AZ2-Public": {
"CIDR": "10.0.96.0/20"
}, "AZ2-Private": {
"CIDR": "10.0.64.0/19"
}, "AZ3-Public": {
"CIDR": "10.0.160.0/20"
}, "AZ3-Private": {
"CIDR": "10.0.128.0/19"
}
}
},
"Resources": {
"VPC": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": {"Fn::FindInMap": ["SubnetConfig", "VPC", "CIDR"]},
"InstanceTenancy": "default",
"EnableDnsSupport": "true",
"EnableDnsHostnames": "false",
"Tags": [
{
"Key": "Name", "Value": {"Fn::Join": ["", [{"Ref": "EnvName"}, "_VPC"]]}
}
]
}
},
"SubnetAz1Public": {
"Type": "AWS::EC2::Subnet", "Properties": {
"CidrBlock": {
"Fn::FindInMap": ["SubnetConfig", "AZ1-Public", "CIDR"]
},
"AvailabilityZone": {
"Fn::Select": ["0", {"Ref": "TargetAZs"}]
},
"VpcId": {"Ref": "VPC"},
"Tags": [
{
"Key": "Name",
"Value": {
"Fn::Join": [
"", [{"Ref": "EnvName"}, "-", {"Fn::Select": ["0", {"Ref": "TargetAZs"}]}, "-public"]
]
}
}
]
}
},
"SubnetAz1Private": {
"Type": "AWS::EC2::Subnet", "Properties": {
"CidrBlock": {"Fn::FindInMap": ["SubnetConfig", "AZ1-Private", "CIDR"]},
"AvailabilityZone": {"Fn::Select": ["0", {"Ref": "TargetAZs"}]}, "VpcId": {"Ref": "VPC"},
"Tags": [
{
"Key": "Name",
"Value": {
"Fn::Join": [
"", [{"Ref": "EnvName"}, "-", {"Fn::Select": ["0", {"Ref": "TargetAZs"}]}, "-private"]
]
}
}
]
}
},
"SubnetAz2Public": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"CidrBlock": {"Fn::FindInMap": ["SubnetConfig", "AZ2-Public", "CIDR"]},
"AvailabilityZone": {"Fn::Select": ["1", {"Ref": "TargetAZs"}]}, "VpcId": {"Ref": "VPC"},
"Tags": [
{
"Key": "Name",
"Value": {
"Fn::Join": [
"", [{"Ref": "EnvName"}, "-", {"Fn::Select": ["1", {"Ref": "TargetAZs"}]}, "-public"]
]
}
}
]
}
},
"SubnetAz2Private": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"CidrBlock": {"Fn::FindInMap": ["SubnetConfig", "AZ2-Private", "CIDR"]},
"AvailabilityZone": {"Fn::Select": ["1", {"Ref": "TargetAZs"}]}, "VpcId": {"Ref": "VPC"},
"Tags": [
{
"Key": "Name",
"Value": {
"Fn::Join": [
"", [{"Ref": "EnvName"}, "-", {"Fn::Select": ["1", {"Ref": "TargetAZs"}]}, "-private"]
]
}
}
]
}
},
"SubnetAz3Public": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"CidrBlock": {"Fn::FindInMap": ["SubnetConfig", "AZ3-Public", "CIDR"]},
"AvailabilityZone": {"Fn::Select": ["2", {"Ref": "TargetAZs"}]}, "VpcId": {"Ref": "VPC"},
"Tags": [
{
"Key": "Name",
"Value": {
"Fn::Join": [
"", [{"Ref": "EnvName"}, "-", {"Fn::Select": ["2", {"Ref": "TargetAZs"}]}, "-public"]
]
}
}
]
}
},
"SubnetAz3Private": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"CidrBlock": {"Fn::FindInMap": ["SubnetConfig", "AZ3-Private", "CIDR"]},
"AvailabilityZone": {"Fn::Select": ["2", {"Ref": "TargetAZs"}]}, "VpcId": {"Ref": "VPC"},
"Tags": [
{
"Key": "Name",
"Value": {
"Fn::Join": [
"", [{"Ref": "EnvName"}, "-", {"Fn::Select": ["2", {"Ref": "TargetAZs"}]}, "-private"]
]
}
}
]
}
},
"InternetGateway": {
"Type": "AWS::EC2::InternetGateway",
"Properties": {
"Tags": [
{
"Key": "Name", "Value": "Dev-Internet_Gateway"
}
]
}
},
"RouteTableInternal": {
"Type": "AWS::EC2::RouteTable",
"Properties": {
"VpcId": {"Ref": "VPC"},
"Tags": [
{
"Key": "Name", "Value": "Dev-Internal-RouteTable"
}
]
}
},
"RouteTablePublic": {
"Type": "AWS::EC2::RouteTable",
"Properties": {
"VpcId": {"Ref": "VPC"},
"Tags": [
{
"Key": "Name", "Value": "Dev-Public-RouteTable"
}
]
}
},
"GwAttachmentInternetGateway": {
"Type": "AWS::EC2::VPCGatewayAttachment",
"Properties": {
"VpcId": {"Ref": "VPC"},
"InternetGatewayId": {"Ref": "InternetGateway"}
}
}, "RouteTableAssocAz1Private": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"RouteTableId": {"Ref": "RouteTableInternal"},
"SubnetId": {"Ref": "SubnetAz1Private"}
}
},
"RouteTableAssocAz3Private": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"RouteTableId": {"Ref": "RouteTableInternal"},
"SubnetId": {"Ref": "SubnetAz3Private"}
}
},
"RouteTableAssocAz2Private": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"RouteTableId": {"Ref": "RouteTableInternal"},
"SubnetId": {"Ref": "SubnetAz2Private"}
}
},
"RouteTableAssocAz1Public": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"RouteTableId": {"Ref": "RouteTablePublic"},
"SubnetId": {"Ref": "SubnetAz1Public"}
}
},
"RouteTableAssocAz3Public": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"RouteTableId": {"Ref": "RouteTablePublic"},
"SubnetId": {"Ref": "SubnetAz3Public"}
}
},
"RouteTableAssocAz2Public": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"RouteTableId": {"Ref": "RouteTablePublic"},
"SubnetId": {"Ref": "SubnetAz2Public"}
}
},
"RouteTablePublicRoute1": {
"Type": "AWS::EC2::Route",
"Properties": {
"DestinationCidrBlock": "0.0.0.0/0",
"RouteTableId": {"Ref": "RouteTablePublic"},
"GatewayId": {"Ref": "InternetGateway"}
},
"DependsOn": "GwAttachmentInternetGateway"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment