Skip to content

Instantly share code, notes, and snippets.

@jboursiquot
Created August 29, 2019 02:50
Show Gist options
  • Save jboursiquot/cdb5635b98e451cafa61f1d276e776df to your computer and use it in GitHub Desktop.
Save jboursiquot/cdb5635b98e451cafa61f1d276e776df to your computer and use it in GitHub Desktop.
CCA 630 Project 3 VPC CloudFormation template
AWSTemplateFormatVersion: '2010-09-09'
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: "VPC Configuration"
Parameters:
- vpccidr
- publicacidr
- publicbcidr
- privateacidr
- privatebcidr
ParameterLabels:
vpccidr:
default: "VPC CIDR Block"
publicacidr:
default: "Public Subnet A CIDR Block"
publicbcidr:
default: "Public Subnet B CIDR Block"
privateacidr:
default: "Private Subnet A CIDR Block"
privatebcidr:
default: "Private Subnet B CIDR Block"
Parameters:
vpccidr:
Type: String
Description: "VPC CIDR Block"
MinLength: 9
MaxLength: 18
AllowedPattern: "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})"
ConstraintDescription: Must be a valid CIDR range in the form x.x.x.x/16
Default: 10.103.0.0/16
publicacidr:
Type: String
Description: "Public Subnet A CIDR Block"
MinLength: 9
MaxLength: 18
AllowedPattern: "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})"
ConstraintDescription: Must be a valid CIDR range in the form x.x.x.x/22
Default: 10.103.0.0/22
privateacidr:
Type: String
Description: "Private Subnet A CIDR Block"
MinLength: 9
MaxLength: 18
AllowedPattern: "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})"
ConstraintDescription: Must be a valid CIDR range in the form x.x.x.x/22
Default: 10.103.4.0/22
publicbcidr:
Type: String
Description: "Public Subnet B CIDR Block"
MinLength: 9
MaxLength: 18
AllowedPattern: "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})"
ConstraintDescription: Must be a valid CIDR range in the form x.x.x.x/22
Default: 10.103.8.0/22
privatebcidr:
Type: String
Description: "Private Subnet B CIDR Block"
MinLength: 9
MaxLength: 18
AllowedPattern: "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})"
ConstraintDescription: Must be a valid CIDR range in the form x.x.x.x/22
Default: 10.103.12.0/22
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref vpccidr
EnableDnsSupport: true
EnableDnsHostnames: true
Tags:
- Key: Name
Value: cca
SubnetPublicA:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: !Select [0, !GetAZs ]
CidrBlock: !Ref publicacidr
MapPublicIpOnLaunch: true
VpcId: !Ref VPC
Tags:
- Key: Name
Value: cca-pub-sub-a
SubnetPrivateA:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: !Select [0, !GetAZs ]
CidrBlock: !Ref privateacidr
MapPublicIpOnLaunch: false
VpcId: !Ref VPC
Tags:
- Key: Name
Value: cca-priv-sub-a
SubnetPublicB:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: !Select [1, !GetAZs ]
CidrBlock: !Ref publicbcidr
MapPublicIpOnLaunch: true
VpcId: !Ref VPC
Tags:
- Key: Name
Value: cca-pub-sub-b
SubnetPrivateB:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: !Select [1, !GetAZs ]
CidrBlock: !Ref privatebcidr
MapPublicIpOnLaunch: false
VpcId: !Ref VPC
Tags:
- Key: Name
Value: cca-priv-sub-b
RouteTablePublic:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: cca-pub-rt
SubnetRouteTableAssociatePublicA:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref RouteTablePublic
SubnetId: !Ref SubnetPublicA
SubnetRouteTableAssociatePrivateA:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref RouteTablePrivateA
SubnetId: !Ref SubnetPrivateA
SubnetRouteTableAssociatePublicB:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref RouteTablePublic
SubnetId: !Ref SubnetPublicB
SubnetRouteTableAssociatePrivateB:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref RouteTablePrivateB
SubnetId: !Ref SubnetPrivateB
IGW:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: cca-igw
GatewayAttach:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId: !Ref IGW
VpcId: !Ref VPC
RouteDefaultPublic:
Type: AWS::EC2::Route
DependsOn: GatewayAttach
Properties:
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref IGW
RouteTableId: !Ref RouteTablePublic
RouteTablePrivateA:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: cca-priv-rt-a
RouteTablePrivateB:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: cca-priv-rt-b
EIPNatGWA:
DependsOn: GatewayAttach
Type: AWS::EC2::EIP
Properties:
Domain: vpc
EIPNatGWB:
DependsOn: GatewayAttach
Type: AWS::EC2::EIP
Properties:
Domain: vpc
NatGatewayA:
Type: AWS::EC2::NatGateway
Properties:
AllocationId: !GetAtt EIPNatGWA.AllocationId
SubnetId: !Ref SubnetPublicA
Tags:
- Key: Name
Value: cca-nat-a
NatGatewayB:
Type: "AWS::EC2::NatGateway"
Properties:
AllocationId: !GetAtt EIPNatGWB.AllocationId
SubnetId: !Ref SubnetPublicB
Tags:
- Key: Name
Value: cca-nat-b
RouteDefaultPrivateA:
Type: AWS::EC2::Route
Properties:
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref NatGatewayA
RouteTableId: !Ref RouteTablePrivateA
RouteDefaultPrivateB:
Type: AWS::EC2::Route
Properties:
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref NatGatewayB
RouteTableId: !Ref RouteTablePrivateB
Outputs:
VPC:
Description: VPC ID
Value: !Ref VPC
Export:
Name: cca-vpc-id
SubnetPublicA:
Description: Public Subnet A's ID
Value: !Ref SubnetPublicA
Export:
Name: cca-vpc-pub-sub-a-id
SubnetPublicB:
Description: Public Subnet B's ID
Value: !Ref SubnetPublicB
Export:
Name: cca-vpc-pub-sub-b-id
SubnetPrivateA:
Description: Private Subnet A's ID
Value: !Ref SubnetPrivateA
Export:
Name: cca-vpc-priv-sub-a-id
SubnetPrivateB:
Description: Private Subnet B's ID
Value: !Ref SubnetPrivateB
Export:
Name: cca-vpc-priv-sub-b-id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment