Created
November 14, 2019 13:23
-
-
Save martijnvandongen/f69ca54425332e2439c1a4e439a8d4ca to your computer and use it in GitHub Desktop.
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
Resources: | |
# 01 Create VPC | |
VPC: | |
Type: AWS::EC2::VPC | |
Properties: | |
CidrBlock: "10.0.0.0/16" | |
EnableDnsHostnames: true | |
InternetGateway: | |
Type: AWS::EC2::InternetGateway | |
GatewayAttachment: | |
Type: AWS::EC2::VPCGatewayAttachment | |
Properties: | |
InternetGatewayId: !Ref InternetGateway | |
VpcId: !Ref VPC | |
# 2 Add Route Table | |
PublicRouteTable: | |
Type: AWS::EC2::RouteTable | |
Properties: | |
VpcId: !Ref VPC | |
PublicRoute: | |
Type: AWS::EC2::Route | |
Properties: | |
DestinationCidrBlock: 0.0.0.0/0 | |
GatewayId: !Ref InternetGateway | |
RouteTableId: !Ref PublicRouteTable | |
## 3 Add Public Subnets | |
PublicSubnetA: | |
Type: AWS::EC2::Subnet | |
Properties: | |
VpcId: !Ref VPC | |
AvailabilityZone: !Join ["", [!Ref "AWS::Region", "a"]] | |
CidrBlock: "10.0.0.0/24" | |
PublicSubnetARouteTableAssociation: | |
Type: AWS::EC2::SubnetRouteTableAssociation | |
Properties: | |
SubnetId: !Ref PublicSubnetA | |
RouteTableId: !Ref PublicRouteTable | |
PublicSubnetB: | |
Type: AWS::EC2::Subnet | |
Properties: | |
VpcId: !Ref VPC | |
AvailabilityZone: !Join ["", [!Ref "AWS::Region", "b"]] | |
CidrBlock: "10.0.1.0/24" | |
PublicSubnetBRouteTableAssociation: | |
Type: AWS::EC2::SubnetRouteTableAssociation | |
Properties: | |
SubnetId: !Ref PublicSubnetB | |
RouteTableId: !Ref PublicRouteTable | |
# 4 Add NAT | |
EIP: | |
Type: AWS::EC2::EIP | |
Properties: | |
Domain: vpc | |
NAT: | |
DependsOn: GatewayAttachment | |
Type: AWS::EC2::NatGateway | |
Properties: | |
AllocationId: !Sub "${EIP.AllocationId}" | |
SubnetId: !Ref PublicSubnetA | |
# 5 Add private Route Table | |
PrivateSubnetRouteTable: | |
Type: AWS::EC2::RouteTable | |
Properties: | |
VpcId: | |
Ref: VPC | |
PrivateRouteTableRouteNAT: | |
Type: AWS::EC2::Route | |
Properties: | |
RouteTableId: !Ref PrivateSubnetRouteTable | |
DestinationCidrBlock: 0.0.0.0/0 | |
NatGatewayId: !Ref NAT | |
# 6 Add private subnets and associate route tables | |
PrivateSubnetA: | |
Type: AWS::EC2::Subnet | |
Properties: | |
VpcId: !Ref VPC | |
AvailabilityZone: !Join ["", [!Ref "AWS::Region", "a"]] | |
CidrBlock: "10.0.64.0/24" | |
PrivateSubnetARouteTableAssociation: | |
Type: AWS::EC2::SubnetRouteTableAssociation | |
Properties: | |
SubnetId: !Ref PrivateSubnetA | |
RouteTableId: !Ref PrivateSubnetRouteTable | |
PrivateSubnetB: | |
Type: AWS::EC2::Subnet | |
Properties: | |
VpcId: !Ref VPC | |
AvailabilityZone: !Join ["", [!Ref "AWS::Region", "b"]] | |
CidrBlock: "10.0.65.0/24" | |
PrivateSubnetBRouteTableAssociation: | |
Type: AWS::EC2::SubnetRouteTableAssociation | |
Properties: | |
SubnetId: !Ref PrivateSubnetB | |
RouteTableId: !Ref PrivateSubnetRouteTable | |
# 7 add data route without any rules | |
DataSubnetRouteTable: | |
Type: AWS::EC2::RouteTable | |
Properties: | |
VpcId: !Ref VPC | |
DataSubnetA: | |
Type: AWS::EC2::Subnet | |
Properties: | |
VpcId: !Ref VPC | |
AvailabilityZone: !Join ["", [!Ref "AWS::Region", "a"]] | |
CidrBlock: "10.0.128.0/24" | |
DataSubnetARouteTableAssociation: | |
Type: AWS::EC2::SubnetRouteTableAssociation | |
Properties: | |
SubnetId: !Ref DataSubnetA | |
RouteTableId: !Ref DataSubnetRouteTable | |
DataSubnetB: | |
Type: AWS::EC2::Subnet | |
Properties: | |
VpcId: !Ref VPC | |
AvailabilityZone: !Join ["", [!Ref "AWS::Region", "b"]] | |
CidrBlock: "10.0.129.0/24" | |
DataSubnetBRouteTableAssociation: | |
Type: AWS::EC2::SubnetRouteTableAssociation | |
Properties: | |
SubnetId: !Ref DataSubnetB | |
RouteTableId: !Ref DataSubnetRouteTable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment