It’s very straightforward to deploy a VPC utilizing CloudFormation:
AWSTemplateFormatVersion: 2010-09-09
Description: Deploy a VPC
Sources:
VPC:
Sort: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
EnableDnsHostnames: true
Tags:
- Key: Identify
Worth: Lab VPC
<meta charset="utf-8">Outputs:
VPC:
Description: VPC
Worth: !Ref VPC
This will even output the created VPC useful resource info.
However what should you additionally wish to create Subnets and an hooked up Web Gateway?
AWSTemplateFormatVersion: 2010-09-09
Description: Deploy a VPC
Sources:
VPC:
Sort: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
EnableDnsHostnames: true
Tags:
- Key: Identify
Worth: Lab VPC
InternetGateway:
Sort: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Identify
Worth: Lab Web Gateway
AttachGateway:
Sort: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId: !Ref VPC
InternetGatewayId: !Ref InternetGateway
PublicSubnet1:
Sort: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: 10.0.0.0/24
AvailabilityZone: !Choose
- '0'
- !GetAZs ''
Tags:
- Key: Identify
Worth: Public Subnet 1
PrivateSubnet1:
Sort: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: 10.0.1.0/24
AvailabilityZone: !Choose
- '0'
- !GetAZs ''
Tags:
- Key: Identify
Worth: Non-public Subnet 1
PublicRouteTable:
Sort: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Identify
Worth: Public Route Desk
PublicRoute:
Sort: AWS::EC2::Route
Properties:
RouteTableId: !Ref PublicRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
PublicSubnetRouteTableAssociation1:
Sort: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PublicSubnet1
RouteTableId: !Ref PublicRouteTable
PrivateRouteTable:
Sort: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Identify
Worth: Non-public Route Desk
PrivateSubnetRouteTableAssociation1:
Sort: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PrivateSubnet1
RouteTableId: !Ref PrivateRouteTable
Outputs:
VPC:
Description: VPC
Worth: !Ref VPC
AZ1:
Description: Availability Zone 1
Worth: !GetAtt
- PublicSubnet1
- AvailabilityZone