CloudFormation for VPC with NAT and EIP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: 2010-09-09 | |
VpcCidr: | |
Type: String | |
Default: 10.192.0.0/16 | |
PublicSubnetCidr: | |
Type: String | |
Default: 10.192.10.0/24 | |
PrivateSubnetCidr: | |
Type: String | |
Default: 10.192.20.0/24 | |
Resources: | |
VPC: | |
Type: AWS::EC2::VPC | |
Properties: | |
CidrBlock: !Ref VpcCidr | |
EnableDnsSupport: true | |
EnableDnsHostnames: true | |
InternetGateway: | |
Type: AWS::EC2::InternetGateway | |
InternetGatewayAttachment: | |
Type: AWS::EC2::VPCGatewayAttachment | |
Properties: | |
InternetGatewayId: !Ref InternetGateway | |
VpcId: !Ref VPC | |
PublicSubnet: | |
Type: AWS::EC2::Subnet | |
Properties: | |
VpcId: !Ref VPC | |
AvailabilityZone: !Select [ 0, !GetAZs '' ] | |
CidrBlock: !Ref PublicSubnetCidr | |
MapPublicIpOnLaunch: true | |
PrivateSubnet: | |
Type: AWS::EC2::Subnet | |
Properties: | |
VpcId: !Ref VPC | |
AvailabilityZone: !Select [ 0, !GetAZs '' ] | |
CidrBlock: !Ref PrivateSubnetCidr | |
MapPublicIpOnLaunch: false | |
NatGatewayEIP: | |
Type: AWS::EC2::EIP | |
DependsOn: InternetGatewayAttachment | |
Properties: | |
Domain: vpc | |
NatGateway: | |
Type: AWS::EC2::NatGateway | |
Properties: | |
AllocationId: !GetAtt NatGatewayEIP.AllocationId | |
SubnetId: !Ref PublicSubnet | |
PublicRouteTable: | |
Type: AWS::EC2::RouteTable | |
Properties: | |
VpcId: !Ref VPC | |
DefaultPublicRoute: | |
Type: AWS::EC2::Route | |
DependsOn: InternetGatewayAttachment | |
Properties: | |
RouteTableId: !Ref PublicRouteTable | |
DestinationCidrBlock: 0.0.0.0/0 | |
GatewayId: !Ref InternetGateway | |
PublicSubnetRouteTableAssociation: | |
Type: AWS::EC2::SubnetRouteTableAssociation | |
Properties: | |
RouteTableId: !Ref PublicRouteTable | |
SubnetId: !Ref PublicSubnet | |
PrivateRouteTable: | |
Type: AWS::EC2::RouteTable | |
Properties: | |
VpcId: !Ref VPC | |
DefaultPrivateRoute: | |
Type: AWS::EC2::Route | |
Properties: | |
RouteTableId: !Ref PrivateRouteTable | |
DestinationCidrBlock: 0.0.0.0/0 | |
NatGatewayId: !Ref NatGateway | |
PrivateSubnetRouteTableAssociation: | |
Type: AWS::EC2::SubnetRouteTableAssociation | |
Properties: | |
RouteTableId: !Ref PrivateRouteTable | |
SubnetId: !Ref PrivateSubnet | |
NoIngressSecurityGroup: | |
Type: AWS::EC2::SecurityGroup | |
Properties: | |
GroupName: "no-ingress-sg" | |
GroupDescription: "Security group with no ingress rule" | |
VpcId: !Ref VPC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment