Skip to content

Commit 1219237

Browse files
feature(core): 6.25 tgw inter region peering (#364)
* TGW inter-region peering Co-authored-by: Naveen Kumar <nkoppula@amazon.com>
1 parent dc2164f commit 1219237

File tree

42 files changed

+1401
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1401
-4
lines changed

reference-artifacts/config.example.json

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,85 @@
402402
"Default-route-table-propagation": false,
403403
"Auto-accept-sharing-attachments": true
404404
},
405-
"route-tables": ["core", "segregated", "shared", "standalone"]
405+
"route-tables": ["core", "segregated", "shared", "standalone"],
406+
"tgw-routes": [
407+
{
408+
"name": "{TGW_ALL}",
409+
"routes": [
410+
{
411+
"destination": "1.1.0.0/32",
412+
"target-tgw": "East"
413+
}
414+
]
415+
},
416+
{
417+
"name": "segregated",
418+
"routes": [
419+
{
420+
"destination": "1.0.4.0/32",
421+
"blackhole-route": true
422+
}
423+
]
424+
},
425+
{
426+
"name": "shared",
427+
"routes": [{
428+
"destination": "1.0.2.0/32",
429+
"target-vpc": "Dev"
430+
}]
431+
},
432+
{
433+
"name": "standalone",
434+
"routes": [{
435+
"destination": "1.0.3.0/32",
436+
"target-vpn": {
437+
"name": "Perimeter_fw",
438+
"az": "b",
439+
"subnet": "Public"
440+
}
441+
}]
442+
}
443+
]
444+
},
445+
{
446+
"name": "East",
447+
"asn": 64526,
448+
"region": "us-east-1",
449+
"features": {
450+
"DNS-support": true,
451+
"VPN-ECMP-support": true,
452+
"Default-route-table-association": false,
453+
"Default-route-table-propagation": false,
454+
"Auto-accept-sharing-attachments": true
455+
},
456+
"route-tables": ["core", "segregated", "shared", "standalone"],
457+
"tgw-attach": {
458+
"associate-to-tgw": "Main",
459+
"account": "shared-network",
460+
"region": "ca-central-1",
461+
"tgw-rt-associate-local": ["core"],
462+
"tgw-rt-associate-remote": ["core"]
463+
},
464+
"tgw-routes": [
465+
{
466+
"name": "core",
467+
"routes": [
468+
{
469+
"destination": "1.1.0.0/32",
470+
"target-tgw": "Main"
471+
}
472+
]
473+
},
474+
{
475+
"name": "segregated",
476+
"routes": [
477+
{
478+
"destination": "1.1.1.0/32",
479+
"target-tgw": "Main"
480+
}
481+
]
482+
}
483+
]
406484
}
407485
]
408486
}

src/deployments/cdk/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@
6868
"@aws-accelerator/common-outputs": "workspace:^0.0.1",
6969
"@aws-accelerator/common-types": "workspace:^0.0.1",
7070
"@aws-accelerator/cdk-constructs": "workspace:^0.0.1",
71+
"@aws-accelerator/custom-resource-accept-tgw-peering-attachment": "workspace:^0.0.1",
7172
"@aws-accelerator/custom-resource-acm-import-certificate": "workspace:^0.0.1",
7273
"@aws-accelerator/custom-resource-cfn-sleep": "workspace:^0.0.1",
7374
"@aws-accelerator/custom-resource-cur-report-definition": "workspace:^0.0.1",
7475
"@aws-accelerator/custom-resource-cloud-trail": "workspace:^0.0.1",
76+
"@aws-accelerator/custom-resource-create-tgw-peering-attachment": "workspace:^0.0.1",
7577
"@aws-accelerator/custom-resource-ds-log-subscription": "workspace:^0.0.1",
7678
"@aws-accelerator/custom-resource-ec2-ebs-default-encryption": "workspace:^0.0.1",
7779
"@aws-accelerator/custom-resource-ec2-image-finder": "workspace:^0.0.1",

src/deployments/cdk/src/apps/phase--1.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import * as globalRoles from '../deployments/iam';
1212
* - Creating required roles for createSSMDocument custom resource
1313
* - Creating required roles for createLogGroup custom resource
1414
* - Creating required roles for CWLCentralLoggingSubscriptionFilterRole custom resource
15+
* - Creating required roles for TransitGatewayCreatePeeringAttachment custom resource
16+
* - Creating required roles for TransitGatewayAcceptPeeringAttachment custom resource
1517
* - Creating required roles for createLogsMetricFilter custom resource
1618
* - Creating required roles for SnsSubscriberLambda custom resource
1719
*/
@@ -67,6 +69,17 @@ export async function deploy({ acceleratorConfig, accountStacks, accounts }: Pha
6769
config: acceleratorConfig,
6870
});
6971

72+
// Creates roles for transit gateway create peering attachment custom resource
73+
await globalRoles.createTgwPeeringRoles({
74+
accountStacks,
75+
config: acceleratorConfig,
76+
});
77+
78+
// Creates roles for transit gateway accept peering attachment custom resource
79+
await globalRoles.createTgwAcceptPeeringRoles({
80+
accountStacks,
81+
config: acceleratorConfig,
82+
});
7083
// Creates role for createLogsMetricFilter custom resource
7184
await globalRoles.createLogsMetricFilterRole({
7285
accountStacks,

src/deployments/cdk/src/apps/phase-1.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { PhaseInput } from './shared';
3333
import { getIamUserPasswordSecretValue } from '../deployments/iam';
3434
import * as cwlCentralLoggingToS3 from '../deployments/central-services/central-logging-s3';
3535
import * as vpcDeployment from '../deployments/vpc';
36+
import * as transitGateway from '../deployments/transit-gateway';
3637
import { DNS_LOGGING_LOG_GROUP_REGION } from '@aws-accelerator/common/src/util/constants';
3738
import { createR53LogGroupName } from '../common/r53-zones';
3839
import { LogGroup } from '@aws-accelerator/custom-resource-logs-log-group';
@@ -198,6 +199,7 @@ export async function deploy({ acceleratorConfig, accountStacks, accounts, conte
198199
securityGroupName: name,
199200
}),
200201
),
202+
tgwAttachments: vpc.tgwAVpcAttachments,
201203
});
202204

203205
return vpcStack.vpc;
@@ -453,6 +455,13 @@ export async function deploy({ acceleratorConfig, accountStacks, accounts, conte
453455
accounts,
454456
});
455457

458+
await transitGateway.createPeeringAttachment({
459+
accountStacks,
460+
accounts,
461+
config: acceleratorConfig,
462+
outputs,
463+
});
464+
456465
/**
457466
* Code to create LogGroups required for DNS Logging
458467
*/

src/deployments/cdk/src/apps/phase-2.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,11 @@ export async function deploy({ acceleratorConfig, accountStacks, accounts, conte
308308
logBucket,
309309
outputs,
310310
});
311+
312+
await tgwDeployment.acceptPeeringAttachment({
313+
accountStacks,
314+
accounts,
315+
config: acceleratorConfig,
316+
outputs,
317+
});
311318
}

src/deployments/cdk/src/apps/phase-3.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { getStackJsonOutput } from '@aws-accelerator/common-outputs/src/stack-ou
99
import { CentralBucketOutput, AccountBucketOutput } from '../deployments/defaults';
1010
import * as securityHub from '../deployments/security-hub';
1111
import * as macie from '../deployments/macie';
12+
import * as transitGateway from '../deployments/transit-gateway';
1213

1314
export async function deploy({ acceleratorConfig, accountStacks, accounts, context, outputs }: PhaseInput) {
1415
/**
@@ -104,4 +105,11 @@ export async function deploy({ acceleratorConfig, accountStacks, accounts, conte
104105
config: acceleratorConfig,
105106
outputs,
106107
});
108+
109+
await transitGateway.step3({
110+
accountStacks,
111+
accounts,
112+
config: acceleratorConfig,
113+
outputs,
114+
});
107115
}

src/deployments/cdk/src/common/vpc.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ export interface NameToIdMap {
6060
[key: string]: string;
6161
}
6262

63+
export interface TgwAttachment {
64+
name: string;
65+
id: string;
66+
}
67+
6368
/**
6469
* Auxiliary class that makes management and lookup of subnets easier.
6570
*/
@@ -125,6 +130,8 @@ export class Vpc extends cdk.Construct implements constructs.Vpc {
125130
readonly securityGroup?: SecurityGroup;
126131
readonly routeTableNameToIdMap: NameToIdMap = {};
127132

133+
readonly tgwAttachments: TgwAttachment[] = [];
134+
128135
constructor(scope: cdk.Construct, name: string, vpcProps: VpcProps) {
129136
super(scope, name);
130137

@@ -320,6 +327,12 @@ export class Vpc extends cdk.Construct implements constructs.Vpc {
320327
transitGatewayId: tgw.tgwId,
321328
});
322329

330+
// TODO add VPC To TGW attachment output
331+
this.tgwAttachments.push({
332+
name: tgw.name,
333+
id: tgwAttachment.transitGatewayAttachmentId,
334+
});
335+
323336
const ownerAccountId = getAccountId(accounts, tgwAttach.account);
324337
if (ownerAccountId) {
325338
// Add tags in the TGW owner account
@@ -531,6 +544,10 @@ export class Vpc extends cdk.Construct implements constructs.Vpc {
531544
return this.securityGroup?.securityGroups || [];
532545
}
533546

547+
get tgwAVpcAttachments(): constructs.TgwAttachment[] {
548+
return this.tgwAttachments;
549+
}
550+
534551
findSubnetByNameAndAvailabilityZone(name: string, az: string): constructs.Subnet {
535552
const subnet = this.tryFindSubnetByNameAndAvailabilityZone(name, az);
536553
if (!subnet) {

src/deployments/cdk/src/deployments/firewall/cluster/outputs.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as t from 'io-ts';
22
import { optional } from '@aws-accelerator/common-types';
33
import { createCfnStructuredOutput } from '../../../common/structured-output';
44
import { createStructuredOutputFinder } from '@aws-accelerator/common-outputs/src/structured-output';
5+
import { StackOutput } from '@aws-accelerator/common-outputs/src/stack-output';
56

67
export const FirewallInstanceOutput = t.interface(
78
{
@@ -70,3 +71,33 @@ export type FirewallVpnConnectionOutput = t.TypeOf<typeof FirewallVpnConnectionO
7071
export const CfnFirewallVpnConnectionOutput = createCfnStructuredOutput(FirewallVpnConnectionOutput);
7172

7273
export const FirewallVpnConnectionOutputFinder = createStructuredOutputFinder(FirewallVpnConnectionOutput, () => ({}));
74+
75+
export const TgwVpnAttachment = t.interface({
76+
subnet: t.string,
77+
az: t.string,
78+
id: t.string,
79+
});
80+
81+
export type TgwVpnAttachment = t.TypeOf<typeof TgwVpnAttachment>;
82+
83+
export const TgwVpnAttachmentsOutput = t.interface(
84+
{
85+
name: t.string,
86+
attachments: t.array(TgwVpnAttachment),
87+
},
88+
'TgwVpnAttachmentsOutput',
89+
);
90+
91+
export type TgwVpnAttachmentsOutput = t.TypeOf<typeof TgwVpnAttachmentsOutput>;
92+
93+
export const CfnTgwVpnAttachmentsOutput = createCfnStructuredOutput(TgwVpnAttachmentsOutput);
94+
95+
export const TgwVpnAttachmentsOutputFinder = createStructuredOutputFinder(TgwVpnAttachmentsOutput, finder => ({
96+
tryFindOneByName: (props: { outputs: StackOutput[]; accountKey?: string; name: string; region?: string }) =>
97+
finder.tryFindOne({
98+
outputs: props.outputs,
99+
accountKey: props.accountKey,
100+
region: props.region,
101+
predicate: o => o.name === props.name,
102+
}),
103+
}));

src/deployments/cdk/src/deployments/firewall/cluster/step-2.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
FirewallVpnConnection,
1414
CfnFirewallVpnConnectionOutput,
1515
FirewallPortOutputFinder,
16+
TgwVpnAttachment,
17+
CfnTgwVpnAttachmentsOutput,
1618
} from './outputs';
1719

1820
export interface FirewallStep2Props {
@@ -109,6 +111,7 @@ async function createCustomerGateways(props: {
109111

110112
const addTagsDependencies = [];
111113
const addTagsToResources: AddTagsToResource[] = [];
114+
const tgwAttachments: TgwVpnAttachment[] = [];
112115

113116
for (const [index, port] of Object.entries(firewallPorts)) {
114117
if (port.firewallName !== firewallConfig.name) {
@@ -153,6 +156,12 @@ async function createCustomerGateways(props: {
153156
tgwId: transitGateway.tgwId,
154157
});
155158

159+
tgwAttachments.push({
160+
subnet: port.subnetName,
161+
az: port.az,
162+
id: attachments.getTransitGatewayAttachmentId(0),
163+
});
164+
156165
// Make sure to add the tags to the VPN attachments
157166
addTagsDependencies.push(attachments);
158167
addTagsToResources.push({
@@ -208,4 +217,9 @@ async function createCustomerGateways(props: {
208217

209218
// Store the firewall VPN connections as outputs
210219
new CfnFirewallVpnConnectionOutput(scope, `FirewallVpnConnections${firewallConfig.name}`, vpnConnections);
220+
221+
new CfnTgwVpnAttachmentsOutput(scope, `TgwVpnAttachments${firewallConfig.name}`, {
222+
name: firewallCgwName,
223+
attachments: tgwAttachments,
224+
});
211225
}

src/deployments/cdk/src/deployments/iam/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ export * from './ssm-document-roles';
99
export * from './log-group-role';
1010
export * from './cwl-central-logging-roles';
1111
export * from './cwl-add-subscription-filter-role';
12+
export * from './tgw-create-peering-roles';
13+
export * from './tgw-accept-peering-roles';
1214
export * from './logs-metric-filter-role';
1315
export * from './sns-subscriber-lambda-role';

0 commit comments

Comments
 (0)