--- AWSTemplateFormatVersion: 2010-09-09 Description: Creates Amazon Virtual Private Cloud (Amazon VPC) with one Availability Zone (AZ), one public subnet and one private subnet (one public, private subnet in each AZ), an Internet gateway, and a NAT gateway. Metadata: AWS::CloudFormation::Interface: ParameterGroups: - Label: default: Virtual Private Cloud Parameters: - VpcCidr - AvailabilityZones ParameterLabels: AvailabilityZones: default: Availability Zones (select one) VpcCidr: default: VPC CIDR Parameters: AvailabilityZones: Description: Select one (1) availability zone (AZ). One (1) public subnet and one (1) private subnet will be created in each AZ (2 total subnets). Type: AWS::EC2::AvailabilityZone::Name VpcCidr: AllowedValues: - 10.0.0.0/16 - 172.31.0.0/16 - 192.168.0.0/16 Default: 10.0.0.0/16 Description: Select the private address IPv4 CIDR for the VPC. Type: String Resources: AttachInternetGateway: Type: AWS::EC2::VPCGatewayAttachment Properties: InternetGatewayId: !Ref InternetGateway VpcId: !Ref Vpc InternetGateway: Type: AWS::EC2::InternetGateway Properties: Tags: - Key: Name Value: !Join [ '', [ 'VPC IGW | ', !Ref 'AWS::StackName' ] ] PrivateRouteTable0: Type: AWS::EC2::RouteTable Properties: Tags: - Key: Name Value: !Join [ '', [ 'Private Route Table | ', !Ref 'AWS::StackName' ] ] - Key: Network Value: Private VpcId: !Ref Vpc PrivateRouteTableAssociation0: Type: AWS::EC2::SubnetRouteTableAssociation Properties: SubnetId: !Ref PrivateSubnet0 RouteTableId: !Ref PrivateRouteTable0 PrivateSubnet0: Type: AWS::EC2::Subnet Properties: AvailabilityZone: !Ref AvailabilityZones CidrBlock: !Select [ 1, !Cidr [ !GetAtt Vpc.CidrBlock, 3, 8 ]] Tags: - Key: Name Value: !Join [ '', [ 'Private Subnet 0 | ', !Ref 'AWS::StackName' ] ] - Key: SubnetType Value: Private VpcId: !Ref Vpc PublicRoute: Type: AWS::EC2::Route Properties: RouteTableId: !Ref PublicRouteTable DestinationCidrBlock: 0.0.0.0/0 GatewayId: !Ref InternetGateway PublicRouteTable: Type: AWS::EC2::RouteTable Properties: Tags: - Key: Name Value: !Join [ '', [ 'Public Route Table | ', !Ref 'AWS::StackName' ] ] - Key: Network Value: Public VpcId: !Ref Vpc PublicRouteTableAssociation0: Type: AWS::EC2::SubnetRouteTableAssociation Properties: SubnetId: !Ref PublicSubnet0 RouteTableId: !Ref PublicRouteTable PublicSubnet0: Type: AWS::EC2::Subnet Properties: AvailabilityZone: !Ref AvailabilityZones CidrBlock: !Select [ 0, !Cidr [ !GetAtt Vpc.CidrBlock, 2, 4 ] ] MapPublicIpOnLaunch: true Tags: - Key: Name Value: !Join [ '', [ 'Public Subnet 0 | ', !Ref 'AWS::StackName' ] ] - Key: SubnetType Value: Public VpcId: !Ref Vpc Vpc: Type: AWS::EC2::VPC Properties: CidrBlock: !Ref VpcCidr EnableDnsHostnames: true EnableDnsSupport: true Tags: - Key: Name Value: !Join [ '', [ 'VPC | ', !Ref 'AWS::StackName' ] ] Outputs: VpcId: Value: !Ref Vpc VpcCidr: Value: !Ref VpcCidr DefaultSecurityGroupId: Value: !GetAtt Vpc.DefaultSecurityGroup PrivateSubnetId0: Value: !Ref PrivateSubnet0 PrivateSubnetCidr0: Value: !Select [ 1, !Cidr [ !GetAtt Vpc.CidrBlock, 3, 8 ] ] PublicSubnetId0: Value: !Ref PublicSubnet0 PublicSubnetCidr0: Value: !Select [ 0, !Cidr [ !GetAtt Vpc.CidrBlock, 2, 4 ] ]