AWSTemplateFormatVersion: "2010-09-09" Description: Create VPC resources. Parameters: VPCName: Type: String Description: The name of the VPC. VpcCidr: Type: String Description: The CIDR block for the VPC. AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$ ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28 PublicSubnet1Cidr: Type: String Description: The CIDR block for the public subnet located in Availability Zone 1. AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$ ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28 PublicSubnet2Cidr: Type: String Description: The CIDR block for the public subnet located in Availability Zone 2. AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$ ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28 PrivateSubnet1Cidr: Type: String Description: The CIDR block for the private subnet located in Availability Zone 1. AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$ ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28 PrivateSubnet2Cidr: Type: String Description: The CIDR block for the private subnet located in Availability Zone 2. AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$ ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28 Resources: VPC: Type: AWS::EC2::VPC Properties: CidrBlock: !Ref VpcCidr EnableDnsHostnames: true EnableDnsSupport: true InstanceTenancy: default Tags: - Key: Name Value: !Ref VPCName VPCPublicSubnet1: Type: AWS::EC2::Subnet Properties: CidrBlock: !Ref PublicSubnet1Cidr VpcId: !Ref VPC AvailabilityZone: !Select [ 0, !GetAZs '' ] MapPublicIpOnLaunch: true Tags: - Key: Name Value: PublicSubnet1 - Key: subnet-type Value: Public VPCPublicSubnet1RouteTable: Type: AWS::EC2::RouteTable Properties: VpcId: !Ref VPC Tags: - Key: Name Value: PublicSubnet1 VPCPublicSubnet1RouteTableAssociation: Type: AWS::EC2::SubnetRouteTableAssociation Properties: RouteTableId: Ref: VPCPublicSubnet1RouteTable SubnetId: Ref: VPCPublicSubnet1 VPCPublicSubnet1DefaultRoute: Type: AWS::EC2::Route Properties: RouteTableId: Ref: VPCPublicSubnet1RouteTable DestinationCidrBlock: 0.0.0.0/0 GatewayId: Ref: VPCIGW DependsOn: - VPCGW VPCPublicSubnet2: Type: AWS::EC2::Subnet Properties: CidrBlock: !Ref PublicSubnet2Cidr VpcId: !Ref VPC AvailabilityZone: !Select [ 1, !GetAZs '' ] MapPublicIpOnLaunch: true Tags: - Key: Name Value: PublicSubnet2 - Key: subnet-type Value: Public VPCPublicSubnet2RouteTable: Type: AWS::EC2::RouteTable Properties: VpcId: !Ref VPC Tags: - Key: Name Value: PublicSubnet2 VPCPublicSubnet2RouteTableAssociation: Type: AWS::EC2::SubnetRouteTableAssociation Properties: RouteTableId: Ref: VPCPublicSubnet2RouteTable SubnetId: Ref: VPCPublicSubnet2 VPCPublicSubnet2DefaultRoute: Type: AWS::EC2::Route Properties: RouteTableId: !Ref VPCPublicSubnet2RouteTable DestinationCidrBlock: 0.0.0.0/0 GatewayId: !Ref VPCIGW DependsOn: - VPCGW VPCPrivateSubnet1: Type: AWS::EC2::Subnet Properties: CidrBlock: !Ref PrivateSubnet1Cidr VpcId: !Ref VPC AvailabilityZone: !Select [ 0, !GetAZs '' ] MapPublicIpOnLaunch: false Tags: - Key: Name Value: PrivateSubnet1 - Key: subnet-type Value: Private VPCPrivateSubnet1RouteTable: Type: AWS::EC2::RouteTable Properties: VpcId: !Ref VPC Tags: - Key: Name Value: PrivateSubnet1 VPCPrivateSubnet1RouteTableAssociation: Type: AWS::EC2::SubnetRouteTableAssociation Properties: RouteTableId: Ref: VPCPrivateSubnet1RouteTable SubnetId: Ref: VPCPrivateSubnet1 VPCPrivateSubnet2: Type: AWS::EC2::Subnet Properties: CidrBlock: !Ref PrivateSubnet2Cidr VpcId: !Ref VPC AvailabilityZone: !Select [ 1, !GetAZs '' ] MapPublicIpOnLaunch: false Tags: - Key: Name Value: PrivateSubnet2 - Key: subnet-type Value: Private VPCPrivateSubnet2RouteTable: Type: AWS::EC2::RouteTable Properties: VpcId: !Ref VPC Tags: - Key: Name Value: PrivateSubnet2 VPCPrivateSubnet2RouteTableAssociation: Type: AWS::EC2::SubnetRouteTableAssociation Properties: RouteTableId: Ref: VPCPrivateSubnet2RouteTable SubnetId: Ref: VPCPrivateSubnet2 VPCIGW: Type: AWS::EC2::InternetGateway Properties: Tags: - Key: Name Value: VPCIGW VPCGW: Type: AWS::EC2::VPCGatewayAttachment Properties: VpcId: Ref: VPC InternetGatewayId: Ref: VPCIGW Outputs: StackName: Description: VPC nested stack name Value: !Sub "${AWS::StackName}" VpcId: Description: The VPC that this cluster utilises Value: !Ref VPC Export: Name: !Sub "${AWS::StackName}-VpcId" VpcCidr: Description: The VPC Cidr Range Value: !Ref VpcCidr Export: Name: !Sub "${AWS::StackName}-VpcCidr" PrivateSubnetAz1: Description: The first private subnet for this cluster Value: !Ref VPCPrivateSubnet1 Export: Name: !Sub "${AWS::StackName}-PrivateSubnetAz1" PrivateSubnetAz2: Description: The first private subnet for this cluster Value: !Ref VPCPrivateSubnet2 Export: Name: !Sub "${AWS::StackName}-PrivateSubnetAz2" PublicSubnetAZ1: Description: The first public subnet for this cluster Value: !Ref VPCPublicSubnet1 Export: Name: !Sub "${AWS::StackName}-PublicSubnetAz1" PublicSubnetAZ2: Description: The first public subnet for this cluster Value: !Ref VPCPublicSubnet2 Export: Name: !Sub "${AWS::StackName}-PublicSubnetAz2"