    # Usage:
    #   aws cloudformation --region <region> create-stack --stack-name <stack name> --template-body file://vpc.yaml

    # This template will:
    #   Create a VPC with:
    #       1 Public Subnet
    #       2 Private Subnets
    #   An Internet Gateway (with routes to it for Public Subnets)
    #   A NAT Gateway for outbound access (with routes from Private Subnets set to use it)
    #
    Parameters:
      AZName1:
        Type: String
        AllowedValues:
            - us-east-1a
            - us-east-1b
            - us-east-1c
            - us-east-1d
            - us-east-1e
            - us-east-1f
        Description: Enter AZ that maps to the AZ ids use1-az2
      AZName2:
          Type: String
          AllowedValues:
              - us-east-1a
              - us-east-1b
              - us-east-1c
              - us-east-1d
              - us-east-1e
              - us-east-1f
          Description: Enter AZ that maps to the AZ ids use1-az4

    Resources:
      PubPrivateVPC:
        Type: 'AWS::EC2::VPC'
        Properties:
          CidrBlock: 10.10.0.0/16
          Tags:
            - Key: Name
              Value: WorkspacesVPC

      PublicSubnet1:
        Type: 'AWS::EC2::Subnet'
        Properties:
          VpcId: !Ref PubPrivateVPC
          AvailabilityZone:
            Ref: AZName1
          CidrBlock: 10.10.1.0/24
          MapPublicIpOnLaunch: true
          Tags:
            - Key: Name
              Value: WorkspacesPub1


      PrivateSubnet1:
        Type: 'AWS::EC2::Subnet'
        Properties:
          VpcId: !Ref PubPrivateVPC
          AvailabilityZone:
            Ref: AZName1
          CidrBlock: 10.10.3.0/24
          MapPublicIpOnLaunch: false
          Tags:
            - Key: Name
              Value: WorkspacesPvt1

      PrivateSubnet2:
        Type: 'AWS::EC2::Subnet'
        Properties:
          VpcId: !Ref PubPrivateVPC
          AvailabilityZone:
            Ref: AZName2
          CidrBlock: 10.10.4.0/24
          MapPublicIpOnLaunch: false
          Tags:
            - Key: Name
              Value: WorkspacesPvt2


      InternetGateway:
        Type: 'AWS::EC2::InternetGateway'
        Properties:
          Tags:
            - Key: Name
              Value: !Join [_, [!Ref 'AWS::StackName']]
            - Key: Network
              Value: Public

      GatewayToInternet:
        Type: 'AWS::EC2::VPCGatewayAttachment'
        Properties:
          VpcId: !Ref PubPrivateVPC
          InternetGatewayId: !Ref InternetGateway

      PublicRouteTable:
        Type: 'AWS::EC2::RouteTable'
        Properties:
          VpcId: !Ref PubPrivateVPC
          Tags:
            - Key: Network
              Value: Public

      PublicRoute:
        Type: 'AWS::EC2::Route'
        DependsOn: GatewayToInternet
        Properties:
          RouteTableId: !Ref PublicRouteTable
          DestinationCidrBlock: 0.0.0.0/0
          GatewayId: !Ref InternetGateway

      PublicSubnet1RouteTableAssociation:
        Type: 'AWS::EC2::SubnetRouteTableAssociation'
        Properties:
          SubnetId: !Ref PublicSubnet1
          RouteTableId: !Ref PublicRouteTable


      NatGateway:
        Type: "AWS::EC2::NatGateway"
        DependsOn: NatPublicIP
        Properties:
          AllocationId: !GetAtt NatPublicIP.AllocationId
          SubnetId: !Ref PublicSubnet1

      NatPublicIP:
        Type: "AWS::EC2::EIP"
        DependsOn: PubPrivateVPC
        Properties:
          Domain: vpc

      PrivateRouteTable:
        Type: 'AWS::EC2::RouteTable'
        Properties:
          VpcId: !Ref PubPrivateVPC
          Tags:
            - Key: Network
              Value: Private

      PrivateRoute:
        Type: 'AWS::EC2::Route'
        Properties:
          RouteTableId: !Ref PrivateRouteTable
          DestinationCidrBlock: 0.0.0.0/0
          NatGatewayId: !Ref NatGateway

      PrivateSubnet1RouteTableAssociation:
        Type: 'AWS::EC2::SubnetRouteTableAssociation'
        Properties:
          SubnetId: !Ref PrivateSubnet1
          RouteTableId: !Ref PrivateRouteTable

      PrivateSubnet2RouteTableAssociation:
        Type: 'AWS::EC2::SubnetRouteTableAssociation'
        Properties:
          SubnetId: !Ref PrivateSubnet2
          RouteTableId: !Ref PrivateRouteTable
