Last active
July 18, 2022 15:19
-
-
Save vikfork/e75f205464f7d25cfecbfc34e7105676 to your computer and use it in GitHub Desktop.
CloudFormation template to create a Client VPC with 1 private and 1 public subnet for Amazon MSK PrivateLink blog
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' | |
Description: > | |
**WARNING** This template creates VPC, Subnets, NATGateway | |
and related resources. You will be billed for the AWS resources | |
used if you create a stack from this template. | |
Parameters: | |
VPCCidr: | |
Type: String | |
Default: '10.0.0.0/16' | |
PublicSubnetFirstCidr: | |
Type: String | |
Default: '10.0.1.0/24' | |
PrivateSubnetFirstCidr: | |
Type: String | |
Default: '10.0.2.0/24' | |
PrivateSubnetSecondCidr: | |
Type: String | |
Default: '10.0.3.0/24' | |
PrivateSubnetThirdCidr: | |
Type: String | |
Default: '10.0.4.0/24' | |
PrivateSubnetFourthCidr: | |
Type: String | |
Default: '10.0.5.0/24' | |
Resources: | |
VPC: | |
Type: AWS::EC2::VPC | |
Properties: | |
EnableDnsSupport: true | |
EnableDnsHostnames: true | |
CidrBlock: !Ref 'VPCCidr' | |
Tags: | |
- Key: 'Name' | |
Value: 'ClientVPC' | |
PublicSubnetOne: | |
Type: AWS::EC2::Subnet | |
Properties: | |
AvailabilityZone: | |
Fn::Select: | |
- 0 | |
- Fn::GetAZs: {Ref: 'AWS::Region'} | |
VpcId: !Ref 'VPC' | |
CidrBlock: !Ref 'PublicSubnetFirstCidr' | |
MapPublicIpOnLaunch: true | |
Tags: | |
- Key: 'Name' | |
Value: 'PublicSubnetOne' | |
PrivateSubnetOne: | |
Type: AWS::EC2::Subnet | |
Properties: | |
AvailabilityZone: | |
Fn::Select: | |
- 0 | |
- Fn::GetAZs: {Ref: 'AWS::Region'} | |
VpcId: !Ref 'VPC' | |
CidrBlock: !Ref 'PrivateSubnetFirstCidr' | |
MapPublicIpOnLaunch: false | |
Tags: | |
- Key: 'Name' | |
Value: 'PrivateSubnetOne' | |
PrivateSubnetTwo: | |
Type: AWS::EC2::Subnet | |
Properties: | |
AvailabilityZone: | |
Fn::Select: | |
- 1 | |
- Fn::GetAZs: {Ref: 'AWS::Region'} | |
VpcId: !Ref 'VPC' | |
CidrBlock: !Ref 'PrivateSubnetSecondCidr' | |
MapPublicIpOnLaunch: false | |
Tags: | |
- Key: 'Name' | |
Value: 'PrivateSubnetTwo' | |
PrivateSubnetThree: | |
Type: AWS::EC2::Subnet | |
Properties: | |
AvailabilityZone: | |
Fn::Select: | |
- 2 | |
- Fn::GetAZs: {Ref: 'AWS::Region'} | |
VpcId: !Ref 'VPC' | |
CidrBlock: !Ref 'PrivateSubnetThirdCidr' | |
MapPublicIpOnLaunch: false | |
Tags: | |
- Key: 'Name' | |
Value: 'PrivateSubnetThree' | |
PrivateSubnetFour: | |
Type: AWS::EC2::Subnet | |
Properties: | |
AvailabilityZone: | |
Fn::Select: | |
- 3 | |
- Fn::GetAZs: {Ref: 'AWS::Region'} | |
VpcId: !Ref 'VPC' | |
CidrBlock: !Ref 'PrivateSubnetFourthCidr' | |
MapPublicIpOnLaunch: false | |
Tags: | |
- Key: 'Name' | |
Value: 'PrivateSubnetFourth' | |
InternetGateway: | |
Type: AWS::EC2::InternetGateway | |
GatewayAttachement: | |
Type: AWS::EC2::VPCGatewayAttachment | |
Properties: | |
VpcId: !Ref 'VPC' | |
InternetGatewayId: !Ref 'InternetGateway' | |
NATEIP: | |
Type: AWS::EC2::EIP | |
DependsOn: GatewayAttachement | |
Properties: | |
Domain: vpc | |
NATGateway: | |
Type: AWS::EC2::NatGateway | |
Properties: | |
AllocationId: !GetAtt NATEIP.AllocationId | |
SubnetId: !Ref 'PublicSubnetOne' | |
Tags: | |
- Key: 'Name' | |
Value: 'ClientVPC-NATGateway' | |
PublicRouteTable: | |
Type: AWS::EC2::RouteTable | |
Properties: | |
VpcId: !Ref 'VPC' | |
Tags: | |
- Key: 'Name' | |
Value: 'ClientVPC-Public-Table' | |
PublicRoute: | |
Type: AWS::EC2::Route | |
DependsOn: GatewayAttachement | |
Properties: | |
RouteTableId: !Ref 'PublicRouteTable' | |
DestinationCidrBlock: '0.0.0.0/0' | |
GatewayId: !Ref 'InternetGateway' | |
PublicSubnetOneRouteTableAssociation: | |
Type: AWS::EC2::SubnetRouteTableAssociation | |
Properties: | |
SubnetId: !Ref 'PublicSubnetOne' | |
RouteTableId: !Ref PublicRouteTable | |
PrivateRouteTable: | |
Type: AWS::EC2::RouteTable | |
Properties: | |
VpcId: !Ref 'VPC' | |
Tags: | |
- Key: 'Name' | |
Value: 'MSKVPC-Private-Table' | |
PrivateRoute: | |
Type: AWS::EC2::Route | |
Properties: | |
RouteTableId: !Ref 'PrivateRouteTable' | |
DestinationCidrBlock: '0.0.0.0/0' | |
NatGatewayId: !Ref 'NATGateway' | |
PrivateSubnetOneRouteTableAssociation: | |
Type: AWS::EC2::SubnetRouteTableAssociation | |
Properties: | |
RouteTableId: !Ref 'PrivateRouteTable' | |
SubnetId: !Ref 'PrivateSubnetOne' | |
PrivateSubnetTwoRouteTableAssociation: | |
Type: AWS::EC2::SubnetRouteTableAssociation | |
Properties: | |
RouteTableId: !Ref 'PrivateRouteTable' | |
SubnetId: !Ref 'PrivateSubnetTwo' | |
PrivateSubnetThreeRouteTableAssociation: | |
Type: AWS::EC2::SubnetRouteTableAssociation | |
Properties: | |
RouteTableId: !Ref 'PrivateRouteTable' | |
SubnetId: !Ref 'PrivateSubnetThree' | |
PrivateSubnetFourRouteTableAssociation: | |
Type: AWS::EC2::SubnetRouteTableAssociation | |
Properties: | |
RouteTableId: !Ref 'PrivateRouteTable' | |
SubnetId: !Ref 'PrivateSubnetFour' | |
Outputs: | |
VPCId: | |
Description: The ID of the VPC created | |
Value: !Ref 'VPC' | |
Export: | |
Name: !Sub "${AWS::StackName}-VPCID" | |
VPCCidr: | |
Description: The ID of the VPC created | |
Value: !Ref 'VPCCidr' | |
Export: | |
Name: !Sub "${AWS::StackName}-VPCCidr" | |
PublicSubnetOneCidr: | |
Description: Public subnet CIDR address | |
Value: !Ref 'PublicSubnetFirstCidr' | |
Export: | |
Name: !Sub "${AWS::StackName}-PublicSubnetFirstCidr" | |
PublicSubnetOne: | |
Description: The ID of the public subnet created | |
Value: !Ref 'PublicSubnetOne' | |
Export: | |
Name: !Sub "${AWS::StackName}-PublicSubnetOne" | |
PrivateSubnetOne: | |
Description: The ID of private subnet one created | |
Value: !Ref 'PrivateSubnetOne' | |
Export: | |
Name: !Sub "${AWS::StackName}-PrivateSubnetOne" | |
PrivateSubnetTwo: | |
Description: The ID of private subnet two created | |
Value: !Ref 'PrivateSubnetTwo' | |
Export: | |
Name: !Sub "${AWS::StackName}-PrivateSubnetTwo" | |
PrivateSubnetThree: | |
Description: The ID of private subnet three created | |
Value: !Ref 'PrivateSubnetThree' | |
Export: | |
Name: !Sub "${AWS::StackName}-PrivateSubnetThree" | |
PrivateSubnetFour: | |
Description: The ID of private subnet four created | |
Value: !Ref 'PrivateSubnetFour' | |
Export: | |
Name: !Sub "${AWS::StackName}-PrivateSubnetFour" | |
VPCStackName: | |
Description: The name of the VPC Stack | |
Value: !Ref 'AWS::StackName' | |
Export: | |
Name: !Sub "${AWS::StackName}-VPCStackName" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment