AWSTemplateFormatVersion: '2010-09-09' Description: Vpc Stack with 2 public subnets in separate AZs Metadata: {} Parameters: TheVpcRange: Type: String 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]))$ TheSubnetRange: Type: String 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]))$ TheOtherSubnetRange: Type: String 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]))$ ThePublicIp: Type: String 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]))$ Resources: TheVpc: Type: AWS::EC2::VPC Properties: CidrBlock: !Ref 'TheVpcRange' EnableDnsHostnames: true EnableDnsSupport: true InstanceTenancy: default Tags: - Key: Name Value: !Sub '${AWS::StackName}-VPC' TheSubnet: Type: AWS::EC2::Subnet Properties: AvailabilityZone: !Select - 0 - !GetAZs Ref: AWS::Region CidrBlock: !Ref 'TheSubnetRange' MapPublicIpOnLaunch: true Tags: - Key: Name Value: !Sub '${AWS::StackName}-SUBNET' VpcId: !Ref 'TheVpc' TheOtherSubnet: Type: AWS::EC2::Subnet Properties: AvailabilityZone: !Select - 1 - !GetAZs Ref: AWS::Region CidrBlock: !Ref 'TheOtherSubnetRange' MapPublicIpOnLaunch: true Tags: - Key: Name Value: !Sub '${AWS::StackName}-OTHERSUBNET' VpcId: !Ref 'TheVpc' TheRouteTable: Type: AWS::EC2::RouteTable Properties: VpcId: !Ref 'TheVpc' Tags: - Key: Name Value: !Sub '${AWS::StackName}-RouteTable' TheSubnetRouteTableAssociation: Type: AWS::EC2::SubnetRouteTableAssociation Properties: RouteTableId: !Ref 'TheRouteTable' SubnetId: !Ref 'TheSubnet' TheOtherSubnetRouteTableAssociation: Type: AWS::EC2::SubnetRouteTableAssociation Properties: RouteTableId: !Ref 'TheRouteTable' SubnetId: !Ref 'TheOtherSubnet' TheGateway: Type: AWS::EC2::InternetGateway Properties: Tags: - Key: Name Value: !Sub '${AWS::StackName}-InternetGateway' TheInternetVpcAssociation: Type: AWS::EC2::VPCGatewayAttachment Properties: InternetGatewayId: !Ref 'TheGateway' VpcId: !Ref 'TheVpc' TheRoute: Type: AWS::EC2::Route Properties: DestinationCidrBlock: !Ref 'ThePublicIp' GatewayId: !Ref 'TheGateway' RouteTableId: !Ref 'TheRouteTable' Outputs: ThePublicIpWhite: Description: white listed public ip for access Value: !Ref 'ThePublicIp' Export: Name: allowed-ips SubnetId: Description: subnet to attach ec2 to Value: !Ref 'TheSubnet' OtherSubnetId: Description: subnet to attach ec2 to Value: !Ref 'TheOtherSubnet' VpcId: Description: vpc to attach security group to Value: !Ref 'TheVpc'