Skip to content

Commit 202ba8b

Browse files
naveenkoppulaRohit VermaBrian969
authored
feat(core): Fix NATGW/improve VPC multi-cidr support (#705)
* Added support for multiple cidr blocks * updated lock files * improving build * snapshot * harmonizing deps * fixed packages * Creating NATGW routes based on configuration * Using static construct name for cidr2 zero * Fixing NATGW assignment for route * Fixing test using user provided definition * (doc)update sample snippets Co-authored-by: Rohit Verma <rohit.verma@nslhub.com> Co-authored-by: Brian969 <56414362+Brian969@users.noreply.github.com>
1 parent 8b663ab commit 202ba8b

File tree

25 files changed

+187
-216
lines changed

25 files changed

+187
-216
lines changed

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.log
2+
**/dist/
3+
**/cdk.out/**
4+
**/cdk.json
5+
**/node_modules/**
6+
**/.prettierrc

.gitattributes

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Don't allow people to merge changes to these generated files, because the result
2+
# may be invalid. You need to run "rush update" again.
3+
pnpm-lock.yaml merge=binary
4+
5+
# Rush's JSON config files use JavaScript-style code comments. The rule below prevents pedantic
6+
# syntax highlighters such as GitHub's from highlighting these comments as errors. Your text editor
7+
# may also require a special configuration to allow comments in JSON.
8+
#
9+
# For more information, see this issue: https://github.com/microsoft/rushstack/issues/1088
10+
#
11+
*.json linguist-language=JSON-with-Comments

.gitignore

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
cdk.out
2-
node_modules
3-
.DS_Store
4-
*.log
5-
config.json
6-
aws-landing-zone-configuration.zip
7-
1+
cdk.out
2+
node_modules
3+
.DS_Store
4+
*.log
5+
config.json
6+
aws-landing-zone-configuration.zip
7+
**/dist
8+
.idea

pnpm-lock.yaml

Lines changed: 25 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

reference-artifacts/SAMPLE_CONFIGS/sample_snippets.md

Lines changed: 7 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -454,99 +454,29 @@
454454
]
455455
},
456456
{
457-
"name": "SandboxVPC_a"
458-
},
459-
{
460-
"name": "SandboxVPC_b"
461-
}
462-
]
463-
```
464-
465-
---
466-
467-
- Sample NATGW - NOT PREFERED, but works: (uses first AZ)
468-
469-
```
470-
"natgw": {
471-
"subnet": {
472-
"name": "Web"
473-
}
474-
},
475-
"subnets": [
476-
{
477-
"name": "Web",
478-
"share-to-ou-accounts": false,
479-
"share-to-specific-accounts": [],
480-
"definitions": [
481-
{
482-
"az": "a",
483-
"route-table": "SandboxVPC_IGW",
484-
"cidr": "10.6.32.0/20"
485-
},
486-
{
487-
"az": "b",
488-
"route-table": "SandboxVPC_IGW",
489-
"cidr": "10.6.128.0/20"
490-
}
491-
]
492-
},
493-
{
494-
"name": "App",
495-
"share-to-ou-accounts": false,
496-
"share-to-specific-accounts": [],
497-
"definitions": [
498-
{
499-
"az": "a",
500-
"route-table": "SandboxVPC_Common",
501-
"cidr": "10.6.0.0/19"
502-
},
503-
{
504-
"az": "b",
505-
"route-table": "SandboxVPC_Common",
506-
"cidr": "10.6.96.0/19"
507-
}
508-
]
509-
},
510-
{
511-
"name": "Data",
512-
"share-to-ou-accounts": false,
513-
"share-to-specific-accounts": [],
514-
"definitions": [
515-
{
516-
"az": "a",
517-
"route-table": "SandboxVPC_Common",
518-
"cidr": "10.6.48.0/20"
519-
},
520-
{
521-
"az": "b",
522-
"route-table": "SandboxVPC_Common",
523-
"cidr": "10.6.144.0/20"
524-
}
525-
]
526-
}
527-
],
528-
"route-tables": [
529-
{
530-
"name": "SandboxVPC_IGW",
457+
"name": "SandboxVPC_a",
531458
"routes": [
532459
{
533460
"destination": "0.0.0.0/0",
534-
"target": "IGW"
461+
"target": "NATGW_Web_azA"
535462
}
536463
]
537464
},
538465
{
539-
"name": "SandboxVPC_Common",
466+
"name": "SandboxVPC_b",
540467
"routes": [
541468
{
542469
"destination": "0.0.0.0/0",
543-
"target": "NATGW_Web_azA"
470+
"target": "NATGW_Web_azB"
544471
}
545472
]
546473
}
547474
]
548475
```
549476

477+
---
478+
479+
550480
---
551481

552482
- TGW Route tables plus Multiple TGWs

src/core/runtime/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"jest": "25.2.4",
2929
"prettier": "2.2.0",
3030
"ts-jest": "25.3.0",
31-
"ts-node": "6.2.0",
31+
"ts-node": "8.8.1",
3232
"eslint": "7.10.0",
3333
"@typescript-eslint/eslint-plugin": "4.4.0",
3434
"@typescript-eslint/parser": "4.4.0",

src/core/runtime/src/save-outputs-to-ssm/network-outputs.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,14 @@ async function saveVpcOutputs(props: {
312312
vpcUtil.parameters.push('cidr');
313313
}
314314
if (!vpcUtil.parameters.includes('cidr2') && vpcConfig.cidr2) {
315-
await ssm.putParameter(`/${acceleratorPrefix}/network/${vpcPrefix}/${index}/cidr2`, vpcConfig.cidr2.toCidrString());
315+
for (const cidrIndex in vpcConfig.cidr2) {
316+
if (vpcConfig.cidr2[cidrIndex]) {
317+
await ssm.putParameter(
318+
`/${acceleratorPrefix}/network/${vpcPrefix}/${index}/cidr2/${cidrIndex}`,
319+
vpcConfig.cidr2[cidrIndex].toCidrString(),
320+
);
321+
}
322+
}
316323
vpcUtil.parameters.push('cidr2');
317324
}
318325
let subnetsConfig = vpcConfig.subnets;

src/deployments/cdk/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ config.json
33
context.json
44
outputs.json
55
limits.json
6+
organizations.json

src/deployments/cdk/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,10 @@
138138
"colors": "1.4.0",
139139
"constructs": "2.0.1",
140140
"generate-password": "1.5.1",
141+
"hash-sum": "2.0.0",
141142
"io-ts": "2.1.2",
142143
"io-ts-types": "0.5.6",
144+
"ip-num": "1.3.1",
143145
"pascal-case": "3.1.1",
144146
"semver": "7.3.2",
145147
"tempy": "0.5.0",

src/deployments/cdk/src/common/nacl.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,10 @@ export class Nacl extends cdk.Construct {
7575
if (subnetDefinition.disabled) {
7676
continue;
7777
}
78-
const cidrBlock = subnetDefinition.cidr
79-
? subnetDefinition.cidr.toCidrString()
80-
: subnetDefinition.cidr2?.toCidrString();
78+
if (!subnetDefinition.cidr) {
79+
throw new Error(`Please Declare cidr using cidr block only`);
80+
}
81+
const cidrBlock = subnetDefinition.cidr.toCidrString();
8182
const aclEntryProps: ec2.CfnNetworkAclEntryProps = {
8283
networkAclId: nacl.ref,
8384
protocol: rules.protocol,

0 commit comments

Comments
 (0)