quickstart-cisco-asav-ravpn-tgw.yaml 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. AWSTemplateFormatVersion: 2010-09-09
  2. Description: The template creates the TGW resource to connect on-premises firewall with cloud (qs-1qp7e9toe)
  3. Parameters:
  4. PrivateSubnet1ARouteTable:
  5. Type: String
  6. Description: Public Subnet 1 Route Table ID
  7. PrivateSubnet2ARouteTable:
  8. Type: String
  9. Description: Public Subnet 2 Route Table ID
  10. PrivateSubnet3ARouteTable:
  11. Type: String
  12. Default: 'null'
  13. Description: Public Subnet 3 Route Table ID
  14. PrivateSubnet4ARouteTable:
  15. Type: String
  16. Default: 'null'
  17. Description: Public Subnet 4 Route Table ID
  18. OnPremFirewallPublicIP:
  19. Description: Specify the Public IP of the on-premises ASAv/router
  20. Type: String
  21. OnPremFirewallASN:
  22. Description: Specify the BGP ASN of the on-premisis ASAv/router
  23. Type: String
  24. PreSharedKeyForVPNAttachment:
  25. Description: Specify the PreSharedKey of vEdgeCloud1. Must be 15 characters in length and cannot start with zero (0).
  26. Type: String
  27. AmazonSideAsn:
  28. Description: A private Autonomous System Number (ASN) for the Amazon side of a BGP session. The range is 64512 to 65534 for 16-bit ASNs and 4200000000 to 4294967294 for 32-bit ASNs.
  29. Type: String
  30. VPNTunnelCIDRs:
  31. Description: Specify the Tunnel InsideCIDRs for the on-premises firewall. You can use the default pre-filled CIDRs as well.
  32. Type: CommaDelimitedList
  33. VPCID:
  34. Type: AWS::EC2::VPC::Id
  35. Description: Select VPC which for VPC Attachment
  36. TGWSubnet1CIDR:
  37. 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])(\/(1[6-9]|2[0-8]))$
  38. ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
  39. Description: CIDR block for TGW subnet 1 located in Availability Zone 1
  40. Type: String
  41. TGWSubnet2CIDR:
  42. 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])(\/(1[6-9]|2[0-8]))$
  43. ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
  44. Description: CIDR block for TGW subnet 2 located in Availability Zone 1
  45. Type: String
  46. TGWSubnet3CIDR:
  47. 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])(\/(1[6-9]|2[0-8]))$
  48. ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
  49. Description: CIDR block for TGW subnet 3 located in Availability Zone 1
  50. Type: String
  51. TGWSubnet4CIDR:
  52. 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])(\/(1[6-9]|2[0-8]))$
  53. ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
  54. Description: CIDR block for TGW subnet 4 located in Availability Zone 1
  55. Type: String
  56. VPNPoolCIDR1:
  57. Description: CIDR block for the VPN pool 1
  58. Type: String
  59. VPNPoolCIDR2:
  60. Description: CIDR block for the VPN pool 2
  61. Type: String
  62. VPNPoolCIDR3:
  63. Description: CIDR block for the VPN pool 3
  64. Type: String
  65. VPNPoolCIDR4:
  66. Description: CIDR block for the VPN pool 4
  67. Type: String
  68. OnPremCIDR:
  69. 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])(\/(1[6-9]|2[0-8]))$
  70. ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
  71. Description: CIDR block for the On-prem network
  72. Type: String
  73. AvailabilityZones:
  74. Description: >-
  75. List of Availability Zones to use for the subnets in the VPC. Note: The
  76. logical order is preserved and only 2 AZs are used for this deployment.
  77. Type: 'List<AWS::EC2::AvailabilityZone::Name>'
  78. NumberOfAZs:
  79. Description: >-
  80. Number of Availability Zones to use in the VPC. This must match your
  81. selections in the list of Availability Zones parameter.
  82. Type: String
  83. NumberOfASAv:
  84. Description: >-
  85. Number of ASAv Instances to be initiated.
  86. Type: String
  87. NetworkInterfaceId1ASAv1:
  88. Type: String
  89. Default: 'null'
  90. Description: NetworkInterfaceId of ASAv1 for 1 ASAv deployment
  91. NetworkInterfaceId1ASAv2:
  92. Type: String
  93. Default: 'null'
  94. Description: NetworkInterfaceId of ASAv1 for 2 ASAv deployment
  95. NetworkInterfaceId2ASAv2:
  96. Type: String
  97. Default: 'null'
  98. Description: NetworkInterfaceId of ASAv2 for 2 ASAv deployment
  99. NetworkInterfaceId1ASAv3:
  100. Type: String
  101. Default: 'null'
  102. Description: NetworkInterfaceId of ASAv1 for 3 ASAv deployment
  103. NetworkInterfaceId2ASAv3:
  104. Type: String
  105. Default: 'null'
  106. Description: NetworkInterfaceId of ASAv2 for 3 ASAv deployment
  107. NetworkInterfaceId3ASAv3:
  108. Type: String
  109. Default: 'null'
  110. Description: NetworkInterfaceId of ASAv3 for 3 ASAv deployment
  111. NetworkInterfaceId1ASAv4:
  112. Type: String
  113. Default: 'null'
  114. Description: NetworkInterfaceId of ASAv1 for 4 ASAv deployment
  115. NetworkInterfaceId2ASAv4:
  116. Type: String
  117. Default: 'null'
  118. Description: NetworkInterfaceId of ASAv2 for 4 ASAv deployment
  119. NetworkInterfaceId3ASAv4:
  120. Type: String
  121. Default: 'null'
  122. Description: NetworkInterfaceId of ASAv3 for 4 ASAv deployment
  123. NetworkInterfaceId4ASAv4:
  124. Type: String
  125. Default: 'null'
  126. Description: NetworkInterfaceId of ASAv4 for 4 ASAv deployment
  127. QSS3BucketName:
  128. AllowedPattern: "^[0-9a-zA-Z]+([0-9a-zA-Z-]*[0-9a-zA-Z])*$"
  129. ConstraintDescription: >-
  130. Quick Start bucket name can include numbers, lowercase letters, uppercase
  131. letters, and hyphens (-). It cannot start or end with a hyphen (-).
  132. Description: >-
  133. S3 bucket name for the Quick Start assets. Quick Start bucket name can
  134. include numbers, lowercase letters, uppercase letters, and hyphens (-). It
  135. cannot start or end with a hyphen (-).
  136. Type: String
  137. QSS3KeyPrefix:
  138. AllowedPattern: "^[0-9a-zA-Z-/]*$"
  139. ConstraintDescription: >-
  140. Quick Start key prefix can include numbers, lowercase letters, uppercase
  141. letters, hyphens (-), and forward slash (/).
  142. Description: >-
  143. S3 key prefix for the Quick Start assets. Quick Start key prefix can
  144. include numbers, lowercase letters, uppercase letters, hyphens (-), and
  145. forward slash (/).
  146. Type: String
  147. QSS3BucketRegion:
  148. Description: >-
  149. The AWS Region where the Quick Start S3 bucket (QSS3BucketName) is hosted.
  150. When using your own bucket, you must specify this value.
  151. Type: String
  152. Conditions:
  153. UsingDefaultBucket: !Equals
  154. - !Ref QSS3BucketName
  155. - aws-quickstart
  156. 1AZCondition: !Equals
  157. - !Ref 'NumberOfAZs'
  158. - '1'
  159. 2AZCondition: !Equals
  160. - !Ref 'NumberOfAZs'
  161. - '2'
  162. 3AZCondition: !Equals
  163. - !Ref 'NumberOfAZs'
  164. - '3'
  165. 4AZCondition: !Equals
  166. - !Ref 'NumberOfAZs'
  167. - '4'
  168. #Subnet conditions to specifically handle TGW Subnet Resource constraints
  169. 1SubnetCondition: !Or
  170. - !Equals
  171. - !Ref 'NumberOfAZs'
  172. - '1'
  173. - !Condition 2SubnetCondition
  174. - !Condition 3SubnetCondition
  175. - !Condition 4SubnetCondition
  176. 2SubnetCondition: !Or
  177. - !Equals
  178. - !Ref 'NumberOfAZs'
  179. - '2'
  180. - !Condition 3SubnetCondition
  181. - !Condition 4SubnetCondition
  182. 3SubnetCondition: !Or
  183. - !Equals
  184. - !Ref 'NumberOfAZs'
  185. - '3'
  186. - !Condition 4SubnetCondition
  187. 4SubnetCondition: !Equals
  188. - !Ref 'NumberOfAZs'
  189. - '4'
  190. 1ASAvCondition: !Equals
  191. - !Ref 'NumberOfASAv'
  192. - '1'
  193. 2ASAvCondition: !Equals
  194. - !Ref 'NumberOfASAv'
  195. - '2'
  196. 3ASAvCondition: !Equals
  197. - !Ref 'NumberOfASAv'
  198. - '3'
  199. 4ASAvCondition: !Equals
  200. - !Ref 'NumberOfASAv'
  201. - '4'
  202. Resources:
  203. #------------------ TGW Subnets and Routes -------------------------------------------
  204. TGWSubnet1:
  205. Type: AWS::EC2::Subnet
  206. Properties:
  207. VpcId: !Ref 'VPCID'
  208. CidrBlock: !Ref 'TGWSubnet1CIDR'
  209. AvailabilityZone: !Select
  210. - '0'
  211. - !Ref 'AvailabilityZones'
  212. Tags:
  213. - Key: Name
  214. Value: TGW subnet 1
  215. TGWSubnet2:
  216. Condition: 2SubnetCondition
  217. Type: AWS::EC2::Subnet
  218. Properties:
  219. VpcId: !Ref 'VPCID'
  220. CidrBlock: !Ref 'TGWSubnet2CIDR'
  221. AvailabilityZone: !Select
  222. - '1'
  223. - !Ref 'AvailabilityZones'
  224. Tags:
  225. - Key: Name
  226. Value: TGW subnet 2
  227. TGWSubnet3:
  228. Condition: 3SubnetCondition
  229. Type: AWS::EC2::Subnet
  230. Properties:
  231. VpcId: !Ref 'VPCID'
  232. CidrBlock: !Ref 'TGWSubnet3CIDR'
  233. AvailabilityZone: !Select
  234. - '2'
  235. - !Ref 'AvailabilityZones'
  236. Tags:
  237. - Key: Name
  238. Value: TGW subnet 3
  239. TGWSubnet4:
  240. Condition: 4AZCondition
  241. Type: AWS::EC2::Subnet
  242. Properties:
  243. VpcId: !Ref 'VPCID'
  244. CidrBlock: !Ref 'TGWSubnet4CIDR'
  245. AvailabilityZone: !Select
  246. - '3'
  247. - !Ref 'AvailabilityZones'
  248. Tags:
  249. - Key: Name
  250. Value: TGW subnet 4
  251. TGWSubnetRouteTable:
  252. Type: AWS::EC2::RouteTable
  253. Properties:
  254. VpcId: !Ref 'VPCID'
  255. Tags:
  256. - Key: Name
  257. Value: TGW subnets route table
  258. TGWSubnet1Route:
  259. Condition: 1ASAvCondition
  260. Type: AWS::EC2::Route
  261. Properties:
  262. RouteTableId: !Ref 'TGWSubnetRouteTable'
  263. DestinationCidrBlock: !Ref VPNPoolCIDR1
  264. NetworkInterfaceId: !Ref NetworkInterfaceId1ASAv1
  265. TGWSubnet1Route2ASAv:
  266. Condition: 2ASAvCondition
  267. Type: AWS::EC2::Route
  268. Properties:
  269. RouteTableId: !Ref 'TGWSubnetRouteTable'
  270. DestinationCidrBlock: !Ref VPNPoolCIDR1
  271. NetworkInterfaceId: !Ref NetworkInterfaceId1ASAv2
  272. TGWSubnet1Route3ASAv:
  273. Condition: 3ASAvCondition
  274. Type: AWS::EC2::Route
  275. Properties:
  276. RouteTableId: !Ref 'TGWSubnetRouteTable'
  277. DestinationCidrBlock: !Ref VPNPoolCIDR1
  278. NetworkInterfaceId: !Ref NetworkInterfaceId1ASAv3
  279. TGWSubnet1Route4ASAv:
  280. Condition: 4ASAvCondition
  281. Type: AWS::EC2::Route
  282. Properties:
  283. RouteTableId: !Ref 'TGWSubnetRouteTable'
  284. DestinationCidrBlock: !Ref VPNPoolCIDR1
  285. NetworkInterfaceId: !Ref NetworkInterfaceId1ASAv4
  286. TGWSubnet1AZRouteTableAssociation:
  287. Type: AWS::EC2::SubnetRouteTableAssociation
  288. Properties:
  289. SubnetId: !Ref 'TGWSubnet1'
  290. RouteTableId: !Ref 'TGWSubnetRouteTable'
  291. TGWSubnet2Route:
  292. Condition: 2ASAvCondition
  293. Type: AWS::EC2::Route
  294. Properties:
  295. RouteTableId: !Ref 'TGWSubnetRouteTable'
  296. DestinationCidrBlock: !Ref VPNPoolCIDR2
  297. NetworkInterfaceId: !Ref NetworkInterfaceId2ASAv2
  298. TGWSubnet2Route3ASAv:
  299. Condition: 3ASAvCondition
  300. Type: AWS::EC2::Route
  301. Properties:
  302. RouteTableId: !Ref 'TGWSubnetRouteTable'
  303. DestinationCidrBlock: !Ref VPNPoolCIDR2
  304. NetworkInterfaceId: !Ref NetworkInterfaceId2ASAv3
  305. TGWSubnet2Route4ASAv:
  306. Condition: 4ASAvCondition
  307. Type: AWS::EC2::Route
  308. Properties:
  309. RouteTableId: !Ref 'TGWSubnetRouteTable'
  310. DestinationCidrBlock: !Ref VPNPoolCIDR2
  311. NetworkInterfaceId: !Ref NetworkInterfaceId2ASAv4
  312. TGWSubnet2AZRouteTableAssociation:
  313. Condition: 2SubnetCondition
  314. Type: AWS::EC2::SubnetRouteTableAssociation
  315. Properties:
  316. SubnetId: !Ref 'TGWSubnet2'
  317. RouteTableId: !Ref 'TGWSubnetRouteTable'
  318. TGWSubnet3Route:
  319. Condition: 3ASAvCondition
  320. Type: AWS::EC2::Route
  321. Properties:
  322. RouteTableId: !Ref 'TGWSubnetRouteTable'
  323. DestinationCidrBlock: !Ref VPNPoolCIDR3
  324. NetworkInterfaceId: !Ref NetworkInterfaceId3ASAv3
  325. TGWSubnet3Route4ASAv:
  326. Condition: 4ASAvCondition
  327. Type: AWS::EC2::Route
  328. Properties:
  329. RouteTableId: !Ref 'TGWSubnetRouteTable'
  330. DestinationCidrBlock: !Ref VPNPoolCIDR3
  331. NetworkInterfaceId: !Ref NetworkInterfaceId3ASAv4
  332. TGWSubnet3AZRouteTableAssociation:
  333. Condition: 3SubnetCondition
  334. Type: AWS::EC2::SubnetRouteTableAssociation
  335. Properties:
  336. SubnetId: !Ref 'TGWSubnet3'
  337. RouteTableId: !Ref 'TGWSubnetRouteTable'
  338. TGWSubnet4Route:
  339. Condition: 4ASAvCondition
  340. Type: AWS::EC2::Route
  341. Properties:
  342. RouteTableId: !Ref 'TGWSubnetRouteTable'
  343. DestinationCidrBlock: !Ref VPNPoolCIDR4
  344. NetworkInterfaceId: !Ref NetworkInterfaceId4ASAv4
  345. TGWSubnet4AZRouteTableAssociation:
  346. Condition: 4SubnetCondition
  347. Type: AWS::EC2::SubnetRouteTableAssociation
  348. Properties:
  349. SubnetId: !Ref 'TGWSubnet4'
  350. RouteTableId: !Ref 'TGWSubnetRouteTable'
  351. #------------------ Transit Gateway -------------------------------------------
  352. TransitGateway:
  353. Type: "AWS::EC2::TransitGateway"
  354. Properties:
  355. AmazonSideAsn: !Ref AmazonSideAsn
  356. AutoAcceptSharedAttachments: enable
  357. DefaultRouteTableAssociation: disable
  358. DefaultRouteTablePropagation: disable
  359. Description: A transit gateway connect onpremsised with AWS
  360. Tags:
  361. - Key: Name
  362. Value: !Sub ${AWS::StackName}-TGW
  363. #------------------ Copy lambda stack into local S3 bucket ------------------------------------------------
  364. CopyLambdaStack:
  365. Type: AWS::CloudFormation::Stack
  366. Properties:
  367. #TemplateURL: !Sub "https://${QSS3BucketName}.s3.amazonaws.com/${QSS3KeyPrefix}templates/copy-lambdas.yaml"
  368. TemplateURL: !Sub
  369. - >-
  370. https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/copy-lambdas.yaml
  371. - S3Region: !If
  372. - UsingDefaultBucket
  373. - !Ref 'AWS::Region'
  374. - !Ref QSS3BucketRegion
  375. S3Bucket: !If
  376. - UsingDefaultBucket
  377. - !Sub '${QSS3BucketName}-${AWS::Region}'
  378. - !Ref QSS3BucketName
  379. Parameters:
  380. QSS3BucketName: !Ref QSS3BucketName
  381. QSS3KeyPrefix: !Ref QSS3KeyPrefix
  382. ##------------------ Custom Resource lambda to get the various TGW properties needed -------------------------------------------
  383. LambdaBasicExecutionRole:
  384. Type: AWS::IAM::Role
  385. Properties:
  386. AssumeRolePolicyDocument:
  387. Statement:
  388. - Effect: Allow
  389. Principal:
  390. Service: lambda.amazonaws.com
  391. Action: sts:AssumeRole
  392. Condition: {}
  393. Path: /
  394. Policies:
  395. - PolicyName: !Sub ${AWS::StackName}-tgwDescribe
  396. PolicyDocument:
  397. Version: 2012-10-17
  398. Statement:
  399. - Effect: Allow
  400. Action:
  401. - logs:CreateLogGroup
  402. - logs:CreateLogStream
  403. - logs:PutLogEvents
  404. Resource: !Sub arn:${AWS::Partition}:logs:*:*:*
  405. - Effect: Allow
  406. Action:
  407. - ec2:DescribeVpnConnections
  408. - ec2:DescribeTransitGatewayRouteTables
  409. - ec2:DescribeTransitGatewayAttachments
  410. Resource: "*"
  411. TransitGatewayProperties:
  412. Type: Custom::TransitGatewayProperty
  413. Properties:
  414. ServiceToken: !GetAtt 'TransitGatewayLambda.Arn'
  415. vpn_id: !Ref VPNAttachment
  416. stackName: !Ref "AWS::StackName"
  417. TransitGatewayLambda:
  418. Type: AWS::Lambda::Function
  419. Properties:
  420. Handler: getTgwProperties/lambda_function.lambda_handler
  421. Timeout: 60
  422. Role: !GetAtt 'LambdaBasicExecutionRole.Arn'
  423. Runtime: python3.6
  424. Code:
  425. S3Bucket: !GetAtt 'CopyLambdaStack.Outputs.LambdaZipsBucket'
  426. S3Key: !Sub "${QSS3KeyPrefix}functions/packages/lambda.zip"
  427. MemorySize: 3008
  428. #------------------ TGW Route Tables and Routes -------------------------------------------
  429. TransitGatewaySecurityRouteTable:
  430. Type: "AWS::EC2::TransitGatewayRouteTable"
  431. Properties:
  432. Tags:
  433. - Key: Name
  434. Value: !Sub ${AWS::StackName}-Securityrtb
  435. TransitGatewayId: !Ref TransitGateway
  436. TransitGatewayVPNRoute:
  437. Type: AWS::EC2::TransitGatewayRoute
  438. Properties:
  439. DestinationCidrBlock: !Ref OnPremCIDR
  440. TransitGatewayAttachmentId: !GetAtt TransitGatewayProperties.vpn1_tgw_attachment_id
  441. TransitGatewayRouteTableId: !Ref TransitGatewaySecurityRouteTable
  442. TransitGatewayVPNPoolRoute1:
  443. Condition: 1ASAvCondition
  444. Type: AWS::EC2::TransitGatewayRoute
  445. Properties:
  446. DestinationCidrBlock: !Ref VPNPoolCIDR1
  447. TransitGatewayAttachmentId: !Ref VPCAttachment1AZ
  448. TransitGatewayRouteTableId: !Ref TransitGatewaySecurityRouteTable
  449. TransitGatewayVPNPoolRoute2a:
  450. Condition: 2ASAvCondition
  451. Type: AWS::EC2::TransitGatewayRoute
  452. Properties:
  453. DestinationCidrBlock: !Ref VPNPoolCIDR1
  454. TransitGatewayAttachmentId: !Ref VPCAttachment2AZ
  455. TransitGatewayRouteTableId: !Ref TransitGatewaySecurityRouteTable
  456. TransitGatewayVPNPoolRoute2b:
  457. Condition: 2ASAvCondition
  458. Type: AWS::EC2::TransitGatewayRoute
  459. Properties:
  460. DestinationCidrBlock: !Ref VPNPoolCIDR2
  461. TransitGatewayAttachmentId: !Ref VPCAttachment2AZ
  462. TransitGatewayRouteTableId: !Ref TransitGatewaySecurityRouteTable
  463. TransitGatewayVPNPoolRoute3a:
  464. Condition: 3ASAvCondition
  465. Type: AWS::EC2::TransitGatewayRoute
  466. Properties:
  467. DestinationCidrBlock: !Ref VPNPoolCIDR1
  468. TransitGatewayAttachmentId: !Ref VPCAttachment3AZ
  469. TransitGatewayRouteTableId: !Ref TransitGatewaySecurityRouteTable
  470. TransitGatewayVPNPoolRoute3b:
  471. Condition: 3ASAvCondition
  472. Type: AWS::EC2::TransitGatewayRoute
  473. Properties:
  474. DestinationCidrBlock: !Ref VPNPoolCIDR2
  475. TransitGatewayAttachmentId: !Ref VPCAttachment3AZ
  476. TransitGatewayRouteTableId: !Ref TransitGatewaySecurityRouteTable
  477. TransitGatewayVPNPoolRoute3c:
  478. Condition: 3ASAvCondition
  479. Type: AWS::EC2::TransitGatewayRoute
  480. Properties:
  481. DestinationCidrBlock: !Ref VPNPoolCIDR3
  482. TransitGatewayAttachmentId: !Ref VPCAttachment3AZ
  483. TransitGatewayRouteTableId: !Ref TransitGatewaySecurityRouteTable
  484. TransitGatewayVPNPoolRoute4a:
  485. Condition: 4ASAvCondition
  486. Type: AWS::EC2::TransitGatewayRoute
  487. Properties:
  488. DestinationCidrBlock: !Ref VPNPoolCIDR1
  489. TransitGatewayAttachmentId: !Ref VPCAttachment4AZ
  490. TransitGatewayRouteTableId: !Ref TransitGatewaySecurityRouteTable
  491. TransitGatewayVPNPoolRoute4b:
  492. Condition: 4ASAvCondition
  493. Type: AWS::EC2::TransitGatewayRoute
  494. Properties:
  495. DestinationCidrBlock: !Ref VPNPoolCIDR2
  496. TransitGatewayAttachmentId: !Ref VPCAttachment4AZ
  497. TransitGatewayRouteTableId: !Ref TransitGatewaySecurityRouteTable
  498. TransitGatewayVPNPoolRoute4c:
  499. Condition: 4ASAvCondition
  500. Type: AWS::EC2::TransitGatewayRoute
  501. Properties:
  502. DestinationCidrBlock: !Ref VPNPoolCIDR3
  503. TransitGatewayAttachmentId: !Ref VPCAttachment4AZ
  504. TransitGatewayRouteTableId: !Ref TransitGatewaySecurityRouteTable
  505. TransitGatewayVPNPoolRoute4d:
  506. Condition: 4ASAvCondition
  507. Type: AWS::EC2::TransitGatewayRoute
  508. Properties:
  509. DestinationCidrBlock: !Ref VPNPoolCIDR4
  510. TransitGatewayAttachmentId: !Ref VPCAttachment4AZ
  511. TransitGatewayRouteTableId: !Ref TransitGatewaySecurityRouteTable
  512. TransitGatewaySpokeRouteTable:
  513. Type: "AWS::EC2::TransitGatewayRouteTable"
  514. Properties:
  515. Tags:
  516. - Key: Name
  517. Value: !Sub ${AWS::StackName}-Spokertb
  518. TransitGatewayId: !Ref TransitGateway
  519. #------------------ TGW VPN attachment -------------------------------------------
  520. CustomerGateway:
  521. Type: AWS::EC2::CustomerGateway
  522. Properties:
  523. Type: ipsec.1
  524. BgpAsn: !Ref OnPremFirewallASN
  525. IpAddress: !Ref OnPremFirewallPublicIP
  526. Tags:
  527. - Key: Name
  528. Value: !Sub "${AWS::StackName}-On-Premgateway"
  529. VPNAttachment:
  530. Type: AWS::EC2::VPNConnection
  531. Properties:
  532. CustomerGatewayId: !Ref CustomerGateway
  533. TransitGatewayId: !Ref TransitGateway
  534. Type: ipsec.1
  535. VpnTunnelOptionsSpecifications:
  536. - PreSharedKey: !Ref PreSharedKeyForVPNAttachment
  537. TunnelInsideCidr: !Select [0, !Ref VPNTunnelCIDRs]
  538. - PreSharedKey: !Ref PreSharedKeyForVPNAttachment
  539. TunnelInsideCidr: !Select [1, !Ref VPNTunnelCIDRs]
  540. Tags:
  541. - Key: Name
  542. Value: !Sub "${AWS::StackName}-VPNAttachment"
  543. #------------------ TGW VPC attachments -------------------------------------------
  544. VPCAttachment1AZ:
  545. Condition: 1AZCondition
  546. Type: AWS::EC2::TransitGatewayAttachment
  547. Properties:
  548. SubnetIds:
  549. - !Ref TGWSubnet1
  550. Tags:
  551. - Key: Name
  552. Value: !Sub "${AWS::StackName}-VPCAttachment"
  553. TransitGatewayId: !Ref TransitGateway
  554. VpcId: !Ref VPCID
  555. VPCAttachment2AZ:
  556. Condition: 2AZCondition
  557. Type: AWS::EC2::TransitGatewayAttachment
  558. Properties:
  559. SubnetIds:
  560. - !Ref TGWSubnet1
  561. - !Ref TGWSubnet2
  562. Tags:
  563. - Key: Name
  564. Value: !Sub "${AWS::StackName}-VPCAttachment"
  565. TransitGatewayId: !Ref TransitGateway
  566. VpcId: !Ref VPCID
  567. VPCAttachment3AZ:
  568. Condition: 3AZCondition
  569. Type: AWS::EC2::TransitGatewayAttachment
  570. Properties:
  571. SubnetIds:
  572. - !Ref TGWSubnet1
  573. - !Ref TGWSubnet2
  574. - !Ref TGWSubnet3
  575. Tags:
  576. - Key: Name
  577. Value: !Sub "${AWS::StackName}-VPCAttachment"
  578. TransitGatewayId: !Ref TransitGateway
  579. VpcId: !Ref VPCID
  580. VPCAttachment4AZ:
  581. Condition: 4AZCondition
  582. Type: AWS::EC2::TransitGatewayAttachment
  583. Properties:
  584. SubnetIds:
  585. - !Ref TGWSubnet1
  586. - !Ref TGWSubnet2
  587. - !Ref TGWSubnet3
  588. - !Ref TGWSubnet4
  589. Tags:
  590. - Key: Name
  591. Value: !Sub "${AWS::StackName}-VPCAttachment"
  592. TransitGatewayId: !Ref TransitGateway
  593. VpcId: !Ref VPCID
  594. #------------------ TGW route table associations -------------------------------------------
  595. CustomerGatewayTransitGatewayAssociation:
  596. Type: "AWS::EC2::TransitGatewayRouteTableAssociation"
  597. Properties:
  598. TransitGatewayAttachmentId: !GetAtt TransitGatewayProperties.vpn1_tgw_attachment_id
  599. TransitGatewayRouteTableId: !Ref TransitGatewaySecurityRouteTable
  600. #The VPC association works
  601. VPCTransitGatewayAssociation1AZ:
  602. Condition: 1AZCondition
  603. Type: "AWS::EC2::TransitGatewayRouteTableAssociation"
  604. Properties:
  605. TransitGatewayAttachmentId: !Ref VPCAttachment1AZ
  606. TransitGatewayRouteTableId: !Ref TransitGatewaySecurityRouteTable
  607. VPCTransitGatewayAssociation2AZ:
  608. Condition: 2AZCondition
  609. Type: "AWS::EC2::TransitGatewayRouteTableAssociation"
  610. Properties:
  611. TransitGatewayAttachmentId: !Ref VPCAttachment2AZ
  612. TransitGatewayRouteTableId: !Ref TransitGatewaySecurityRouteTable
  613. VPCTransitGatewayAssociation3AZ:
  614. Condition: 3AZCondition
  615. Type: "AWS::EC2::TransitGatewayRouteTableAssociation"
  616. Properties:
  617. TransitGatewayAttachmentId: !Ref VPCAttachment3AZ
  618. TransitGatewayRouteTableId: !Ref TransitGatewaySecurityRouteTable
  619. VPCTransitGatewayAssociation4AZ:
  620. Condition: 4AZCondition
  621. Type: "AWS::EC2::TransitGatewayRouteTableAssociation"
  622. Properties:
  623. TransitGatewayAttachmentId: !Ref VPCAttachment4AZ
  624. TransitGatewayRouteTableId: !Ref TransitGatewaySecurityRouteTable
  625. #------------------ TGW route table propagations -------------------------------------------
  626. EdgeRouteTablePropagation1AZ:
  627. Condition: 1AZCondition
  628. Type: "AWS::EC2::TransitGatewayRouteTablePropagation"
  629. Properties:
  630. TransitGatewayAttachmentId: !Ref VPCAttachment1AZ
  631. TransitGatewayRouteTableId: !Ref TransitGatewaySecurityRouteTable
  632. EdgeRouteTablePropagation2AZ:
  633. Condition: 2AZCondition
  634. Type: "AWS::EC2::TransitGatewayRouteTablePropagation"
  635. Properties:
  636. TransitGatewayAttachmentId: !Ref VPCAttachment2AZ
  637. TransitGatewayRouteTableId: !Ref TransitGatewaySecurityRouteTable
  638. EdgeRouteTablePropagation3AZ:
  639. Condition: 3AZCondition
  640. Type: "AWS::EC2::TransitGatewayRouteTablePropagation"
  641. Properties:
  642. TransitGatewayAttachmentId: !Ref VPCAttachment3AZ
  643. TransitGatewayRouteTableId: !Ref TransitGatewaySecurityRouteTable
  644. EdgeRouteTablePropagation4AZ:
  645. Condition: 4AZCondition
  646. Type: "AWS::EC2::TransitGatewayRouteTablePropagation"
  647. Properties:
  648. TransitGatewayAttachmentId: !Ref VPCAttachment4AZ
  649. TransitGatewayRouteTableId: !Ref TransitGatewaySecurityRouteTable
  650. RouteTableEntryPrivate1:
  651. Type: AWS::EC2::Route
  652. DependsOn: TransitGatewayVPNRoute
  653. Properties:
  654. DestinationCidrBlock: !Ref OnPremCIDR
  655. RouteTableId: !Ref PrivateSubnet1ARouteTable
  656. TransitGatewayId: !Ref TransitGateway
  657. RouteTableEntryPrivate2:
  658. Condition: 2SubnetCondition
  659. Type: AWS::EC2::Route
  660. DependsOn: TransitGatewayVPNRoute
  661. #DependsOn: VPCAttachment2AZ
  662. Properties:
  663. DestinationCidrBlock: !Ref OnPremCIDR
  664. RouteTableId: !Ref PrivateSubnet2ARouteTable
  665. TransitGatewayId: !Ref TransitGateway
  666. RouteTableEntryPrivate3:
  667. Condition: 3SubnetCondition
  668. DependsOn: TransitGatewayVPNRoute
  669. #DependsOn: VPCAttachment3AZ
  670. Type: AWS::EC2::Route
  671. Properties:
  672. DestinationCidrBlock: !Ref OnPremCIDR
  673. RouteTableId: !Ref PrivateSubnet3ARouteTable
  674. TransitGatewayId: !Ref TransitGateway
  675. RouteTableEntryPrivate4:
  676. Condition: 4SubnetCondition
  677. Type: AWS::EC2::Route
  678. DependsOn: TransitGatewayVPNRoute
  679. #DependsOn: VPCAttachment4AZ
  680. Properties:
  681. DestinationCidrBlock: !Ref OnPremCIDR
  682. RouteTableId: !Ref PrivateSubnet4ARouteTable
  683. TransitGatewayId: !Ref TransitGateway
  684. Outputs:
  685. TransitGateway:
  686. Value: !Ref TransitGateway
  687. Export:
  688. Name: !Sub ${AWS::StackName}-TransitGateway
  689. AmazonSideAsn:
  690. Description: "Amazon side ASN for the BGP session"
  691. Value: !Ref AmazonSideAsn
  692. VPNTunnelInsideCIDRs:
  693. Description: "VPN Tunnel CIDRs"
  694. Value: !Join
  695. - ','
  696. - !Ref VPNTunnelCIDRs
  697. Export:
  698. Name: !Sub ${AWS::StackName}-VPNTunnelInsideCIDRs
  699. VPNTunnelOutsideIPs:
  700. Description: "VPN Tunnel Outside IP"
  701. Value: !Join
  702. - ','
  703. - !GetAtt TransitGatewayProperties.vpn0OutsideIps
  704. Export:
  705. Name: !Sub ${AWS::StackName}-VPNTunnelOutsideIPs
  706. VPNPreSharedKey:
  707. Description: "VPN IPsec PreSharedKey"
  708. Value: !Ref PreSharedKeyForVPNAttachment
  709. Export:
  710. Name: !Sub ${AWS::StackName}-PreSharedKey