Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. Parameters:
  2. EnvironmentName:
  3. Description: An environment name that will be prefixed to resource names
  4. Type: String
  5.  
  6. VpcCIDR:
  7. Description: Please enter the IP range (CIDR notation) for this VPC
  8. Type: String
  9. Default: 10.0.0.0/16
  10.  
  11. PublicSubnet1CIDR:
  12. Description: Please enter the IP range (CIDR notation) for the public subnet in the first Availability Zone
  13. Type: String
  14. Default: 10.0.0.0/18
  15.  
  16. PrivateSubnet1CIDR:
  17. Description: Please enter the IP range (CIDR notation) for the private subnet in the first Availability Zone
  18. Type: String
  19. Default: 10.0.128.0/18
  20.  
  21. PublicSubnet2CIDR:
  22. Description: Please enter the IP range (CIDR notation) for the public subnet in the second Availability Zone
  23. Type: String
  24. Default: 10.0.64.0/18
  25.  
  26. PrivateSubnet2CIDR:
  27. Description: Please enter the IP range (CIDR notation) for the private subnet in the second Availability Zone
  28. Type: String
  29. Default: 10.0.192.0/18
  30.  
  31. Resources:
  32. VPC:
  33. Type: AWS::EC2::VPC
  34. Properties:
  35. CidrBlock: !Ref VpcCIDR
  36. EnableDnsHostnames: true
  37. EnableDnsSupport: true
  38. InstanceTenancy: default
  39. Tags:
  40. - Key: Name
  41. Value: !Sub ${EnvironmentName} VPC
  42.  
  43. PublicSubnet1:
  44. Type: AWS::EC2::Subnet
  45. Properties:
  46. VpcId: !Ref VPC
  47. AvailabilityZone:
  48. Fn::Select:
  49. - 0
  50. - Fn::GetAZs: ''
  51. CidrBlock: !Ref PublicSubnet1CIDR
  52. MapPublicIpOnLaunch: true
  53. Tags:
  54. - Key: Name
  55. Value: !Sub ${EnvironmentName} Public Subnet (AZ1)
  56.  
  57. PrivateSubnet1:
  58. Type: AWS::EC2::Subnet
  59. Properties:
  60. VpcId: !Ref VPC
  61. AvailabilityZone:
  62. Fn::Select:
  63. - 0
  64. - Fn::GetAZs: ''
  65. CidrBlock: !Ref PrivateSubnet1CIDR
  66. MapPublicIpOnLaunch: false
  67. Tags:
  68. - Key: Name
  69. Value: !Sub ${EnvironmentName} Private Subnet (AZ1)
  70.  
  71. PublicSubnet2:
  72. Type: AWS::EC2::Subnet
  73. Properties:
  74. VpcId: !Ref VPC
  75. AvailabilityZone:
  76. Fn::Select:
  77. - 1
  78. - Fn::GetAZs: ''
  79. CidrBlock: !Ref PublicSubnet2CIDR
  80. MapPublicIpOnLaunch: true
  81. Tags:
  82. - Key: Name
  83. Value: !Sub ${EnvironmentName} Public Subnet (AZ2)
  84.  
  85. PrivateSubnet2:
  86. Type: AWS::EC2::Subnet
  87. Properties:
  88. VpcId: !Ref VPC
  89. AvailabilityZone:
  90. Fn::Select:
  91. - 1
  92. - Fn::GetAZs: ''
  93. CidrBlock: !Ref PrivateSubnet2CIDR
  94. MapPublicIpOnLaunch: false
  95. Tags:
  96. - Key: Name
  97. Value: !Sub ${EnvironmentName} Private Subnet (AZ2)
  98.  
  99. InternetGateway:
  100. Type: AWS::EC2::InternetGateway
  101. Properties:
  102. Tags:
  103. - Key: Name
  104. Value: !Sub ${EnvironmentName} Internet Gateway
  105.  
  106. VPCToInternetGateway:
  107. Type: AWS::EC2::VPCGatewayAttachment
  108. Properties:
  109. VpcId: !Ref VPC
  110. InternetGatewayId: !Ref InternetGateway
  111.  
  112. PublicRouteTable:
  113. Type: AWS::EC2::RouteTable
  114. Properties:
  115. VpcId: !Ref VPC
  116. Tags:
  117. - Key: Network
  118. Value: Public
  119. - Key: Name
  120. Value: !Sub ${EnvironmentName} Public Route Table
  121.  
  122. PublicRoute:
  123. Type: AWS::EC2::Route
  124. DependsOn: VPCToInternetGateway
  125. Properties:
  126. RouteTableId: !Ref PublicRouteTable
  127. DestinationCidrBlock: 0.0.0.0/0
  128. GatewayId: !Ref InternetGateway
  129.  
  130. PublicSubnet1RouteTableAssociation:
  131. Type: AWS::EC2::SubnetRouteTableAssociation
  132. Properties:
  133. SubnetId: !Ref PublicSubnet1
  134. RouteTableId: !Ref PublicRouteTable
  135.  
  136. PublicSubnet2RouteTableAssociation:
  137. Type: AWS::EC2::SubnetRouteTableAssociation
  138. Properties:
  139. SubnetId: !Ref PublicSubnet2
  140. RouteTableId: !Ref PublicRouteTable
  141.  
  142. NatPublicEIP:
  143. Type: AWS::EC2::EIP
  144. DependsOn: VPCToInternetGateway
  145. Properties:
  146. Domain: vpc
  147.  
  148. NatGateway:
  149. Type: AWS::EC2::NatGateway
  150. DependsOn: NatPublicEIP
  151. Properties:
  152. AllocationId: !GetAtt NatPublicEIP.AllocationId
  153. SubnetId: !Ref PublicSubnet1
  154.  
  155. PrivateRouteTable:
  156. Type: AWS::EC2::RouteTable
  157. Properties:
  158. VpcId: !Ref VPC
  159. Tags:
  160. - Key: Network
  161. Value: Private
  162. - Key: Name
  163. Value: !Sub ${EnvironmentName} Private Route Table
  164.  
  165. PrivateRoute:
  166. Type: AWS::EC2::Route
  167. Properties:
  168. RouteTableId: !Ref PrivateRouteTable
  169. DestinationCidrBlock: 0.0.0.0/0
  170. NatGatewayId: !Ref NatGateway
  171.  
  172. PrivateSubnet1RouteTableAssociation:
  173. Type: AWS::EC2::SubnetRouteTableAssociation
  174. Properties:
  175. SubnetId: !Ref PrivateSubnet1
  176. RouteTableId: !Ref PrivateRouteTable
  177.  
  178. PrivateSubnet2RouteTableAssociation:
  179. Type: AWS::EC2::SubnetRouteTableAssociation
  180. Properties:
  181. SubnetId: !Ref PrivateSubnet2
  182. RouteTableId: !Ref PrivateRouteTable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement