Skip to content

Instantly share code, notes, and snippets.

@KernelPanicAUS
Forked from gmr/vpc.yaml
Created July 30, 2019 09:55
Show Gist options
  • Save KernelPanicAUS/cc71602f679b61b1b341d7610950b10a to your computer and use it in GitHub Desktop.
Save KernelPanicAUS/cc71602f679b61b1b341d7610950b10a to your computer and use it in GitHub Desktop.
Demonstration CloudFormation YAML template for creating a VPC
AWSTemplateFormatVersion: '2010-09-09'
Description: VPC Network Stack
Metadata: {}
Mappings: {}
Conditions: {}
Outputs: {}
Parameters:
CidrBlock:
AllowedPattern: '((\d{1,3})\.){3}\d{1,3}/\d{1,2}'
Default: 10.0.0.0/16
Description: VPC CIDR Block (eg 10.0.0.0/16)
Type: String
AvailabilityZone1:
Description: The AvailabilityZone to use for the first subnet
Type: AWS::EC2::AvailabilityZone::Name
AvailabilityZone2:
Description: The AvailabilityZone to use for the second subnet
Type: AWS::EC2::AvailabilityZone::Name
SubnetCIDR1:
AllowedPattern: '((\d{1,3})\.){3}\d{1,3}/\d{1,2}'
Default: 10.0.0.0/24
Description: VPC CIDR Block for the Public Subnet (eg 10.0.0.0/24)
Type: String
SubnetCIDR2:
AllowedPattern: '((\d{1,3})\.){3}\d{1,3}/\d{1,2}'
Default: 10.0.1.0/24
Description: VPC CIDR Block for the Public Subnet (eg 10.0.0.0/24)
Type: String
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock:
Ref: CidrBlock
EnableDnsHostnames: true
EnableDnsSupport: true
Tags:
- Key: Name
Value:
Ref: AWS::StackName
InternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value:
Ref: AWS::StackName
GatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId:
Ref: InternetGateway
VpcId:
Ref: VPC
RouteTable:
Type: AWS::EC2::RouteTable
Properties:
Tags:
- Key: Name
Value: {Ref: 'AWS::StackName'}
VpcId:
Ref: VPC
PublicRoute:
Type: AWS::EC2::Route
Properties:
DestinationCidrBlock: 0.0.0.0/0
GatewayId:
Ref: InternetGateway
RouteTableId:
Ref: RouteTable
Subnet1:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: {Ref: AvailabilityZone1}
CidrBlock: {Ref: SubnetCIDR1}
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value:
Fn::Join:
- '-'
- [{Ref: 'AWS::StackName'}, {Ref: AvailabilityZone1}]
VpcId: {Ref: VPC}
Subnet2:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: {Ref: AvailabilityZone2}
CidrBlock: {Ref: SubnetCIDR2}
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value:
Fn::Join:
- '-'
- [{Ref: 'AWS::StackName'}, {Ref: AvailabilityZone2}]
VpcId: {Ref: VPC}
SubnetAssoc1:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId:
Ref: RouteTable
SubnetId:
Ref: Subnet1
SubnetAssoc2:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId:
Ref: RouteTable
SubnetId:
Ref: Subnet2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment