Skip to content
This repository was archived by the owner on Dec 31, 2025. It is now read-only.

Commit 332006e

Browse files
fix(asea): add option to append unique suffixes to vpc names
1 parent 28fcbf2 commit 332006e

3 files changed

Lines changed: 22 additions & 19 deletions

File tree

reference-artifacts/Custom-Scripts/lza-upgrade/src/asea-config/index.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,18 +1318,18 @@ export class AcceleratorConfig {
13181318
* Find all VPC configurations in mandatory accounts, workload accounts and organizational units. VPC configuration in
13191319
* organizational units will have the correct `accountKey` based on the `deploy` value of the VPC configuration.
13201320
*/
1321-
getVpcConfigs(): ResolvedVpcConfig[] {
1321+
getVpcConfigs(appendSuffix: boolean): ResolvedVpcConfig[] {
13221322
const vpcConfigs: ResolvedVpcConfig[] = [];
13231323

13241324
// Add mandatory account VPC configuration first
13251325
for (const [accountKey, accountConfig] of this.getMandatoryAccountConfigs()) {
13261326
for (const vpcConfig of accountConfig.vpc || []) {
1327-
const lzaVpcName = createLzaVpcName(vpcConfig.name, accountKey, vpcConfig.region);
1327+
const lzaVpcName = createLzaVpcName(vpcConfig.name, accountKey, vpcConfig.region, appendSuffix);
13281328
vpcConfigs.push({
13291329
accountKey,
13301330
vpcConfig,
13311331
ouKey: accountConfig.ou,
1332-
lzaVpcName
1332+
lzaVpcName
13331333
});
13341334
}
13351335
}
@@ -1349,9 +1349,9 @@ export class AcceleratorConfig {
13491349
continue;
13501350
}
13511351
}
1352-
vpcConfig.lzaVpcName = createLzaVpcName(vpcConfig.name, accountKey, vpcConfig.region);
1352+
vpcConfig.lzaVpcName = createLzaVpcName(vpcConfig.name, accountKey, vpcConfig.region, appendSuffix);
13531353
if (vpcConfig['cidr-src'] === 'dynamic') {
1354-
const lzaVpcName = createLzaVpcName(vpcConfig.name, accountKey, vpcConfig.region);
1354+
const lzaVpcName = createLzaVpcName(vpcConfig.name, accountKey, vpcConfig.region, appendSuffix);
13551355
vpcConfigs.push({
13561356
ouKey,
13571357
accountKey,
@@ -1365,7 +1365,7 @@ export class AcceleratorConfig {
13651365
ouKey,
13661366
vpcConfig,
13671367
excludeAccounts,
1368-
lzaVpcName: createLzaVpcName(vpcConfig.name, ouKey, vpcConfig.region),
1368+
lzaVpcName: createLzaVpcName(vpcConfig.name, ouKey, vpcConfig.region, appendSuffix),
13691369
});
13701370
}
13711371
} else {
@@ -1374,7 +1374,7 @@ export class AcceleratorConfig {
13741374
ouKey,
13751375
accountKey: destinationAccountKey,
13761376
vpcConfig,
1377-
lzaVpcName: createLzaVpcName(vpcConfig.name, destinationAccountKey, vpcConfig.region)
1377+
lzaVpcName: createLzaVpcName(vpcConfig.name, destinationAccountKey, vpcConfig.region, appendSuffix)
13781378
});
13791379
}
13801380
}
@@ -1387,16 +1387,16 @@ export class AcceleratorConfig {
13871387
accountKey,
13881388
vpcConfig,
13891389
ouKey: accountConfig.ou,
1390-
lzaVpcName: createLzaVpcName(vpcConfig.name, accountKey, vpcConfig.region),
1390+
lzaVpcName: createLzaVpcName(vpcConfig.name, accountKey, vpcConfig.region, appendSuffix),
13911391
});
13921392
}
13931393
}
13941394

13951395
return vpcConfigs;
13961396
}
13971397

1398-
getAzSubnets(accountKey: string, vpcName: string, subnetName: string) {
1399-
const vpcConfigs = this.getVpcConfigs();
1398+
getAzSubnets(accountKey: string, vpcName: string, subnetName: string, appendSuffix: boolean) {
1399+
const vpcConfigs = this.getVpcConfigs(appendSuffix);
14001400
const vpcConfig = vpcConfigs.find((v) => v.accountKey === accountKey && v.vpcConfig.name === vpcName)?.vpcConfig;
14011401
if (!vpcConfig) {
14021402
throw new Error(`VPC named "${vpcName}" not found in account "${accountKey}"`);
@@ -1414,9 +1414,9 @@ export class AcceleratorConfig {
14141414
}
14151415
}
14161416

1417-
export function createLzaVpcName(vpcName: string, accountKey: string, region: string): string {
1417+
export function createLzaVpcName(vpcName: string, accountKey: string, region: string, appendSuffix: boolean): string {
14181418
const md5Hash = crypto.createHash('md5').update(`${vpcName}_${accountKey}_${region}`).digest('hex');
14191419
const vpcNameWithType = vpcName.endsWith('_vpc') ? vpcName : `${vpcName}_vpc`;
1420-
const lzaVpcName = `${vpcNameWithType}..${md5Hash.substring(0,5)}`;
1420+
const lzaVpcName = appendSuffix ? `${vpcNameWithType}..${md5Hash.substring(0,5)}` : vpcNameWithType;
14211421
return lzaVpcName;
14221422
}

reference-artifacts/Custom-Scripts/lza-upgrade/src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface Config {
3636
skipDriftDetection?: boolean;
3737
localConfigFilePath?: string;
3838
enableTerminationProtection?: boolean;
39+
appendUniqueSuffixToVPCNames?: boolean
3940
lzaInstallerTemplateBucket?: string
4041
lzaInstallerTemplateKey?: string
4142
}

reference-artifacts/Custom-Scripts/lza-upgrade/src/convert-config.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ export class ConvertAseaConfig {
190190
private readonly assumeRoleName: string;
191191
private readonly writeFilesConfig: WriteToSourcesTypes.WriteToSourcesConfig;
192192
private readonly ouToNestedOuMap: Map<string, Set<string>> = new Map();
193+
private readonly appendVpcSuffixes: boolean;
193194
private accounts: Account[] = [];
194195
private outputs: StackOutput[] = [];
195196
private vpcAssignedCidrs: VpcAssignedCidr[] = [];
@@ -213,6 +214,7 @@ export class ConvertAseaConfig {
213214
this.region = config.homeRegion;
214215
this.centralBucketName = config.centralBucket!;
215216
this.aseaPrefix = config.aseaPrefix!.endsWith('-') ? config.aseaPrefix! : `${config.aseaPrefix}-`;
217+
this.appendVpcSuffixes = config.appendUniqueSuffixToVPCNames ?? false;
216218
this.parametersTable = `${this.aseaPrefix}Parameters`;
217219
this.acceleratorName = config.acceleratorName!;
218220
this.sts = new STS();
@@ -252,7 +254,7 @@ export class ConvertAseaConfig {
252254
this.subnetAssignedCidrs = await loadSubnetAssignedCidrs(subnetsCidrsTableName(this.aseaPrefix), this.dynamoDb);
253255
this.outputs = await loadOutputs(`${this.aseaPrefix}Outputs`, this.dynamoDb);
254256
this.globalOptions = aseaConfig['global-options'];
255-
this.vpcConfigs = aseaConfig.getVpcConfigs();
257+
this.vpcConfigs = aseaConfig.getVpcConfigs(this.appendVpcSuffixes);
256258
const regionsWithVpc = this.vpcConfigs.map((resolvedConfig) => resolvedConfig.vpcConfig.region);
257259
this.regionsWithoutVpc = this.globalOptions['supported-regions'].filter(
258260
(region) => !regionsWithVpc.includes(region),
@@ -2988,7 +2990,7 @@ export class ConvertAseaConfig {
29882990
sourceVpcConfig = this.vpcConfigs.find(({ vpcConfig }) => vpcConfig.name === source.vpc);
29892991
}
29902992
if (SecurityGroupSourceConfig.is(source)) {
2991-
lzaRule.sources.push({
2993+
lzaRule.sources.push({
29922994
securityGroups: source['security-group'].map(securityGroupName),
29932995
});
29942996
} else if (SubnetSourceConfig.is(source)) {
@@ -3000,7 +3002,7 @@ export class ConvertAseaConfig {
30003002
),
30013003
subnets: source.subnet.flatMap((sourceSubnet) =>
30023004
aseaConfig
3003-
.getAzSubnets(sourceVpcConfig?.accountKey || source.account || accountKey || '', source.vpc, sourceSubnet)
3005+
.getAzSubnets(sourceVpcConfig?.accountKey || source.account || accountKey || '', source.vpc, sourceSubnet, this.appendVpcSuffixes)
30043006
.map((s) => createSubnetName(source.vpc, s.subnetName, s.az)),
30053007
),
30063008
vpc: sourceVpcConfig?.lzaVpcName ?? source.vpc,
@@ -3080,7 +3082,7 @@ export class ConvertAseaConfig {
30803082
target = {
30813083
account: destinationAccountKey,
30823084
subnet: createSubnetName(dest.vpc, ruleSubnet.subnetName, ruleSubnet.az),
3083-
vpc: createLzaVpcName(destination, destinationAccountKey!, vpcConfig.region),
3085+
vpc: createLzaVpcName(destination, destinationAccountKey!, vpcConfig.region, this.appendVpcSuffixes),
30843086
region: targetRegion,
30853087
};
30863088
}
@@ -3227,7 +3229,7 @@ export class ConvertAseaConfig {
32273229
if (inboundResolver) {
32283230
lzaEndpointsConfig.push({
32293231
name: `${vpcConfig.name}InboundEndpoint`,
3230-
vpc: createLzaVpcName(vpcConfig.name, accountKey!, vpcConfig.region),
3232+
vpc: createLzaVpcName(vpcConfig.name, accountKey!, vpcConfig.region, this.appendVpcSuffixes),
32313233
subnets:
32323234
vpcConfig.subnets
32333235
?.find((subnetItem) => subnetItem.name === vpcConfig.resolvers?.subnet)
@@ -3241,7 +3243,7 @@ export class ConvertAseaConfig {
32413243
if (outboundResolver) {
32423244
lzaEndpointsConfig.push({
32433245
name: `${vpcConfig.name}OutboundEndpoint`,
3244-
vpc: createLzaVpcName(vpcConfig.name, accountKey!, vpcConfig.region),
3246+
vpc: createLzaVpcName(vpcConfig.name, accountKey!, vpcConfig.region, this.appendVpcSuffixes),
32453247
subnets:
32463248
vpcConfig.subnets
32473249
?.find((subnetItem) => subnetItem.name === vpcConfig.resolvers?.subnet)
@@ -3740,7 +3742,7 @@ export class ConvertAseaConfig {
37403742
return ipv4CidrBlock;
37413743
}
37423744
private async createCloudFormationStacksForALBIpForwarding(aseaConfig: AcceleratorConfig) {
3743-
const vpcs = aseaConfig.getVpcConfigs();
3745+
const vpcs = aseaConfig.getVpcConfigs(this.appendVpcSuffixes);
37443746
const vpcMaps = [];
37453747
for (const vpc of vpcs) {
37463748
if (vpc.vpcConfig['alb-forwarding']) {

0 commit comments

Comments
 (0)