# CloudFormation Workshop - Template 1 # # Resources built: # # (1) An Amazon VPC # (2) A public subnet # (3) An Internet gateway # (4) A route table # (5) A default route # # Output values: # # VpcId - The ID of the VPC (e.g. vpc-123456789012345) # SubnetId - The ID of the subnet (e.g. subnet-123456789012345) # AzId - The Availability Zone of the subnet (e.g. us-east-1a) --- AWSTemplateFormatVersion: '2010-09-09' Description: Create a VPC Mappings: RegionMap: us-east-1: VpcCidr: 10.201.0.0/16 SubnetCidr: 10.201.1.0/24 us-east-2: VpcCidr: 10.202.0.0/16 SubnetCidr: 10.202.1.0/24 us-west-1: VpcCidr: 10.203.0.0/16 SubnetCidr: 10.203.1.0/24 us-west-2: VpcCidr: 10.204.0.0/16 SubnetCidr: 10.204.1.0/24 ca-central-1: VpcCidr: 10.205.0.0/16 SubnetCidr: 10.205.1.0/24 eu-central-1: VpcCidr: 10.206.0.0/16 SubnetCidr: 10.206.1.0/24 eu-west-1: VpcCidr: 10.207.0.0/16 SubnetCidr: 10.207.1.0/24 eu-west-2: VpcCidr: 10.208.0.0/16 SubnetCidr: 10.208.1.0/24 eu-west-3: VpcCidr: 10.209.0.0/16 SubnetCidr: 10.209.1.0/24 ap-northeast-1: VpcCidr: 10.210.0.0/16 SubnetCidr: 10.210.1.0/24 ap-northeast-2: VpcCidr: 10.211.0.0/16 SubnetCidr: 10.211.1.0/24 ap-northeast-3: VpcCidr: 10.212.0.0/16 SubnetCidr: 10.212.1.0/24 ap-southeast-1: VpcCidr: 10.213.0.0/16 SubnetCidr: 10.213.1.0/24 ap-southeast-2: VpcCidr: 10.214.0.0/16 SubnetCidr: 10.214.1.0/24 ap-south-1: VpcCidr: 10.215.0.0/16 SubnetCidr: 10.215.1.0/24 us-gov-west: VpcCidr: 10.216.0.0/16 SubnetCidr: 10.216.1.0/24 cn-north-1: VpcCidr: 10.217.0.0/16 SubnetCidr: 10.217.1.0/24 cn-northwest-1: VpcCidr: 10.218.0.0/16 SubnetCidr: 10.218.1.0/24 Resources: Vpc: Type: AWS::EC2::VPC Properties: CidrBlock: !FindInMap [ RegionMap, !Ref "AWS::Region", VpcCidr ] EnableDnsHostnames: 'true' PublicSubnet: Type: AWS::EC2::Subnet Properties: AvailabilityZone: !Select - 0 - !GetAZs "" CidrBlock: !FindInMap [ RegionMap, !Ref "AWS::Region", SubnetCidr ] MapPublicIpOnLaunch: 'true' VpcId: !Ref Vpc VpcIgw: Type: AWS::EC2::InternetGateway VpcIgwAttachment: Type: AWS::EC2::VPCGatewayAttachment Properties: InternetGatewayId: !Ref VpcIgw VpcId: !Ref Vpc # Note the use of the DependsOn attribute. You need to use this to delay # the creation of the route table if it contains a route that reports to # an Internet Gateway. # # See: # # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-dependson.html RouteTable: Type: AWS::EC2::RouteTable DependsOn: VpcIgwAttachment Properties: VpcId: !Ref Vpc DefaultRoute: Type: AWS::EC2::Route Properties: DestinationCidrBlock: 0.0.0.0/0 GatewayId: !Ref VpcIgw RouteTableId: !Ref RouteTable AssociatePublicSubnetToRouteTable: Type: AWS::EC2::SubnetRouteTableAssociation Properties: RouteTableId: !Ref RouteTable SubnetId: !Ref PublicSubnet # Note that the output values are derived from the PublicSubnet resource. # You can see what values !Ref and !GetAtt return by looking at the # CloudFormation documentation for AWS::EC2::Subnet at: # # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-subnet.html Outputs: SubnetId: Description: Subnet ID Value: !Ref PublicSubnet Export: Name: SubnetId VpcId: Description: Vpc ID Value: !Ref Vpc Export: Name: VpcId VpcCidr: Description: Vpc CIDR block Value: !GetAtt Vpc.CidrBlock Export: Name: VpcCidr AzName: Description: Subnet Availability Zone Value: !GetAtt PublicSubnet.AvailabilityZone Export: Name: AzName