Skip to content

Commit 4b7dd2c

Browse files
authored
Revert "fix(asea): handle duplicate vpc names (#1286)"
This reverts commit 3934c7b.
1 parent 3934c7b commit 4b7dd2c

File tree

5 files changed

+36
-55
lines changed

5 files changed

+36
-55
lines changed

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@
1818
"globals": "15.0.0",
1919
"prettier": "3.0.3",
2020
"typescript-eslint": "^7.6.0"
21-
},
22-
"packageManager": "pnpm@10.11.0+sha512.6540583f41cc5f628eb3d9773ecee802f4f9ef9923cc45b69890fb47991d4b092964694ec3a4f738a420c918a333062c8b925d312f42e4f0c263eb603551f977"
23-
}
21+
}
22+
}

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
* and limitations under the License.
1212
*/
1313
import * as t from './types';
14-
import * as crypto from 'crypto';
1514

1615
export const MandatoryAccountType = t.enums('MandatoryAccountType', [
1716
'master',
@@ -1324,12 +1323,10 @@ export class AcceleratorConfig {
13241323
// Add mandatory account VPC configuration first
13251324
for (const [accountKey, accountConfig] of this.getMandatoryAccountConfigs()) {
13261325
for (const vpcConfig of accountConfig.vpc || []) {
1327-
const lzaVpcName = createLzaVpcName(vpcConfig.name, accountKey, vpcConfig.region);
13281326
vpcConfigs.push({
13291327
accountKey,
13301328
vpcConfig,
13311329
ouKey: accountConfig.ou,
1332-
lzaVpcName
13331330
});
13341331
}
13351332
}
@@ -1349,14 +1346,13 @@ export class AcceleratorConfig {
13491346
continue;
13501347
}
13511348
}
1352-
vpcConfig.lzaVpcName = createLzaVpcName(vpcConfig.name, accountKey, vpcConfig.region);
1349+
vpcConfig.lzaVpcName = `${vpcConfig.name}_${accountKey}`;
13531350
if (vpcConfig['cidr-src'] === 'dynamic') {
1354-
const lzaVpcName = createLzaVpcName(vpcConfig.name, accountKey, vpcConfig.region);
13551351
vpcConfigs.push({
13561352
ouKey,
13571353
accountKey,
13581354
vpcConfig,
1359-
lzaVpcName,
1355+
lzaVpcName: `${vpcConfig.name}_${accountKey}`,
13601356
});
13611357
}
13621358
}
@@ -1365,7 +1361,6 @@ export class AcceleratorConfig {
13651361
ouKey,
13661362
vpcConfig,
13671363
excludeAccounts,
1368-
lzaVpcName: createLzaVpcName(vpcConfig.name, ouKey, vpcConfig.region),
13691364
});
13701365
}
13711366
} else {
@@ -1374,7 +1369,6 @@ export class AcceleratorConfig {
13741369
ouKey,
13751370
accountKey: destinationAccountKey,
13761371
vpcConfig,
1377-
lzaVpcName: createLzaVpcName(vpcConfig.name, destinationAccountKey, vpcConfig.region)
13781372
});
13791373
}
13801374
}
@@ -1387,7 +1381,6 @@ export class AcceleratorConfig {
13871381
accountKey,
13881382
vpcConfig,
13891383
ouKey: accountConfig.ou,
1390-
lzaVpcName: createLzaVpcName(vpcConfig.name, accountKey, vpcConfig.region),
13911384
});
13921385
}
13931386
}
@@ -1413,10 +1406,3 @@ export class AcceleratorConfig {
14131406
}));
14141407
}
14151408
}
1416-
1417-
export function createLzaVpcName(vpcName: string, accountKey: string, region: string): string {
1418-
const md5Hash = crypto.createHash('md5').update(`${vpcName}_${accountKey}_${region}`).digest('hex');
1419-
const vpcNameWithType = vpcName.endsWith('_vpc') ? vpcName : `${vpcName}_vpc`;
1420-
const lzaVpcName = `${vpcNameWithType}..${md5Hash.substring(0,5)}`;
1421-
return lzaVpcName;
1422-
}

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

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import {
3535
TransitGatewayRouteConfig,
3636
VpcConfig,
3737
VpcFlowLogsDestinationConfig,
38-
createLzaVpcName,
3938
} from './asea-config';
4039
import { loadAseaConfig } from './asea-config/load';
4140
import * as WriteToSourcesTypes from './common//utils/types/writeToSourcesTypes';
@@ -540,9 +539,9 @@ export class ConvertAseaConfig {
540539
name: createNetworkFirewallName(firewallConfigName, this.aseaPrefix),
541540
subnetChangeProtection: false,
542541
tags: [],
543-
vpc: lzaVpcName!,
542+
vpc: createVpcName(lzaVpcName ?? vpcConfig.name),
544543
subnets: this.getAzSubnets(vpcConfig, networkFirewallConfig.subnet.name).map((subnet) =>
545-
createSubnetName(vpcConfig.name, subnet.subnetName, subnet.az),
544+
createSubnetName(lzaVpcName ?? vpcConfig.name, subnet.subnetName, subnet.az),
546545
),
547546
});
548547
}
@@ -1777,7 +1776,7 @@ export class ConvertAseaConfig {
17771776
name: instanceNameWithAz,
17781777
account,
17791778
launchTemplate,
1780-
vpc: firewallScopedVpcConfig?.lzaVpcName!,
1779+
vpc: `${vpcName}_vpc`,
17811780
terminationProtection,
17821781
detailedMonitoring,
17831782
tags,
@@ -2433,7 +2432,7 @@ export class ConvertAseaConfig {
24332432
const setConfigRulesConfig = async () => {
24342433
if (!globalOptions['aws-config']) return;
24352434
// TODO: Consider account regions for deploymentTargets
2436-
const currentNodeRuntime = 'nodejs20.x';
2435+
const currentNodeRuntime = 'nodejs18.x';
24372436
const rulesWithTarget: (AwsConfigRule & {
24382437
deployTo?: string[];
24392438
excludedAccounts?: string[];
@@ -2801,7 +2800,7 @@ export class ConvertAseaConfig {
28012800
if (route['target-vpc']) {
28022801
return {
28032802
account: this.getAccountKeyforLza(globalOptions, route['target-account'] || accountKey),
2804-
vpcName: this.getLzaVpcName(route['target-vpc']),
2803+
vpcName: createVpcName(route['target-vpc']),
28052804
};
28062805
} else if (route['target-vpn']) {
28072806
return {
@@ -2968,27 +2967,27 @@ export class ConvertAseaConfig {
29682967
sources: [],
29692968
};
29702969
for (const source of rule.source) {
2971-
let sourceVpcConfig: ResolvedVpcConfig | undefined;
2970+
let sourceVpcAccountKey: string | undefined = undefined;
29722971
if (SubnetSourceConfig.is(source)) {
2973-
sourceVpcConfig = this.vpcConfigs.find(({ vpcConfig }) => vpcConfig.name === source.vpc);
2972+
sourceVpcAccountKey = this.vpcConfigs.find(({ vpcConfig }) => vpcConfig.name === source.vpc)?.accountKey;
29742973
}
29752974
if (SecurityGroupSourceConfig.is(source)) {
2976-
lzaRule.sources.push({
2975+
lzaRule.sources.push({
29772976
securityGroups: source['security-group'].map(securityGroupName),
29782977
});
29792978
} else if (SubnetSourceConfig.is(source)) {
29802979
lzaRule.sources.push({
29812980
//account: this.getAccountKeyforLza(globalOptions, source.account || accountKey || ''),
29822981
account: this.getAccountKeyforLza(
29832982
globalOptions,
2984-
sourceVpcConfig?.accountKey || source.account || accountKey || '',
2983+
sourceVpcAccountKey || source.account || accountKey || '',
29852984
),
29862985
subnets: source.subnet.flatMap((sourceSubnet) =>
29872986
aseaConfig
2988-
.getAzSubnets(sourceVpcConfig?.accountKey || source.account || accountKey || '', source.vpc, sourceSubnet)
2987+
.getAzSubnets(sourceVpcAccountKey || source.account || accountKey || '', source.vpc, sourceSubnet)
29892988
.map((s) => createSubnetName(source.vpc, s.subnetName, s.az)),
29902989
),
2991-
vpc: sourceVpcConfig?.lzaVpcName ?? source.vpc,
2990+
vpc: createVpcName(source.vpc),
29922991
});
29932992
} else {
29942993
lzaRule.sources.push(source);
@@ -3012,6 +3011,7 @@ export class ConvertAseaConfig {
30123011
rules: NaclConfig[],
30133012
vpcConfig: VpcConfig,
30143013
accountKey?: string,
3014+
lzaVpcName?: string,
30153015
) => {
30163016
const lzaRules: (ConvertConfigTypes.LzaNaclInboundRuleType | ConvertConfigTypes.LzaNaclOutboundRuleType)[] = [];
30173017
for (const rule of rules) {
@@ -3055,17 +3055,18 @@ export class ConvertAseaConfig {
30553055
});
30563056
} else {
30573057
// determine which vpc the nacl rule references
3058+
// use the lzaVpcName when the config is from ou
30583059
let destination: string;
30593060
if (dest.vpc === vpcConfig.name) {
3060-
destination = vpcConfig.name;
3061+
destination = createVpcName(lzaVpcName ?? vpcConfig.name);
30613062
} else {
3062-
destination = dest.vpc;
3063+
destination = createVpcName(dest.vpc);
30633064
}
3064-
const destinationAccountKey = destinationVpcKey ? this.getAccountKeyforLza(globalOptions, destinationVpcKey): undefined;
30653065
target = {
3066-
account: destinationAccountKey,
3066+
account: destinationVpcKey ? this.getAccountKeyforLza(globalOptions, destinationVpcKey) : undefined,
30673067
subnet: createSubnetName(dest.vpc, ruleSubnet.subnetName, ruleSubnet.az),
3068-
vpc: createLzaVpcName(destination, destinationAccountKey!, vpcConfig.region),
3068+
//vpc: createVpcName(dest.vpc),
3069+
vpc: destination,
30693070
region: targetRegion,
30703071
};
30713072
}
@@ -3085,7 +3086,7 @@ export class ConvertAseaConfig {
30853086
}
30863087
return lzaRules;
30873088
};
3088-
const prepareNaclConfig = (vpcConfig: VpcConfig, accountKey?: string) => {
3089+
const prepareNaclConfig = (vpcConfig: VpcConfig, accountKey?: string, lzaVpcName?: string) => {
30893090
const naclSubnetConfigs = vpcConfig.subnets?.filter((s) => !!s.nacls);
30903091
if (!naclSubnetConfigs) return;
30913092
const nacls = [];
@@ -3099,8 +3100,8 @@ export class ConvertAseaConfig {
30993100
subnetAssociations: this.getAzSubnets(vpcConfig, subnetConfig.name).map((s) =>
31003101
createSubnetName(vpcConfig.name, s.subnetName, s.az),
31013102
),
3102-
inboundRules: prepareNaclRules(inboundRules, vpcConfig, accountKey),
3103-
outboundRules: prepareNaclRules(outboundRules, vpcConfig, accountKey),
3103+
inboundRules: prepareNaclRules(inboundRules, vpcConfig, accountKey, lzaVpcName),
3104+
outboundRules: prepareNaclRules(outboundRules, vpcConfig, accountKey, lzaVpcName),
31043105
});
31053106
}
31063107
return nacls;
@@ -3204,15 +3205,14 @@ export class ConvertAseaConfig {
32043205
vpcConfig: VpcConfig,
32053206
lzaEndpointsConfig: ConvertConfigTypes.ResolverEndpointsType[],
32063207
lzaEndpointsRulesConfig: ConvertConfigTypes.ResolverEndpointRulesType[],
3207-
accountKey: string | undefined,
32083208
): ConvertConfigTypes.ResolverEndpointsType[] => {
32093209
let inboundResolver = vpcConfig.resolvers!.inbound;
32103210
let outboundResolver = vpcConfig.resolvers!.outbound;
32113211
if (vpcConfig.resolvers) {
32123212
if (inboundResolver) {
32133213
lzaEndpointsConfig.push({
32143214
name: `${vpcConfig.name}InboundEndpoint`,
3215-
vpc: createLzaVpcName(vpcConfig.name, accountKey!, vpcConfig.region),
3215+
vpc: createVpcName(vpcConfig.lzaVpcName ?? vpcConfig.name),
32163216
subnets:
32173217
vpcConfig.subnets
32183218
?.find((subnetItem) => subnetItem.name === vpcConfig.resolvers?.subnet)
@@ -3226,7 +3226,7 @@ export class ConvertAseaConfig {
32263226
if (outboundResolver) {
32273227
lzaEndpointsConfig.push({
32283228
name: `${vpcConfig.name}OutboundEndpoint`,
3229-
vpc: createLzaVpcName(vpcConfig.name, accountKey!, vpcConfig.region),
3229+
vpc: createVpcName(vpcConfig.lzaVpcName ?? vpcConfig.name),
32303230
subnets:
32313231
vpcConfig.subnets
32323232
?.find((subnetItem) => subnetItem.name === vpcConfig.resolvers?.subnet)
@@ -3262,7 +3262,7 @@ export class ConvertAseaConfig {
32623262
return lzaEndpointsRulesConfig;
32633263
};
32643264

3265-
const prepareResolverConfig = (vpcConfig: VpcConfig, accountKey: string | undefined) => {
3265+
const prepareResolverConfig = (vpcConfig: VpcConfig) => {
32663266
let lzaResolverConfig: {
32673267
endpoints: ConvertConfigTypes.ResolverEndpointsType[] | undefined;
32683268
queryLogs: { name: string; destinations: string[] } | undefined;
@@ -3274,7 +3274,7 @@ export class ConvertAseaConfig {
32743274
let endpoints: any[] = [];
32753275
if (vpcConfig.resolvers) {
32763276
rules = prepareRulesConfig(vpcConfig, lzaEndpointsRulesConfig);
3277-
endpoints = prepareEndpointsConfig(vpcConfig, lzaEndpointsConfig, rules!, accountKey);
3277+
endpoints = prepareEndpointsConfig(vpcConfig, lzaEndpointsConfig, rules!);
32783278
}
32793279

32803280
lzaResolverConfig = {
@@ -3419,7 +3419,7 @@ export class ConvertAseaConfig {
34193419

34203420
const prepareVpcConfig = ({ accountKey, ouKey, vpcConfig, excludeAccounts, lzaVpcName }: ResolvedVpcConfig) => {
34213421
return {
3422-
name: lzaVpcName ?? createVpcName(vpcConfig.name),
3422+
name: createVpcName(lzaVpcName ?? vpcConfig.name),
34233423
account: accountKey ? this.getAccountKeyforLza(globalOptions, accountKey) : undefined,
34243424
deploymentTargets: !accountKey
34253425
? {
@@ -3458,13 +3458,13 @@ export class ConvertAseaConfig {
34583458
useCentralEndpoints: vpcConfig['use-central-endpoints'],
34593459
natGateways: prepareNatGatewayConfig(vpcConfig),
34603460
securityGroups: prepareSecurityGroupsConfig(vpcConfig, accountKey),
3461-
networkAcls: prepareNaclConfig(vpcConfig, accountKey),
3461+
networkAcls: prepareNaclConfig(vpcConfig, accountKey, lzaVpcName),
34623462
vpcFlowLogs: prepareVpcFlowLogs(vpcConfig['flow-logs']),
34633463
subnets: prepareSubnetConfig(vpcConfig, ouKey, accountKey),
34643464
transitGatewayAttachments: prepareTgwAttachConfig(vpcConfig),
34653465
virtualPrivateGateway: vpcConfig.vgw,
34663466
routeTables: prepareRouteTableConfig(vpcConfig, accountKey),
3467-
vpcRoute53Resolver: prepareResolverConfig(vpcConfig, accountKey),
3467+
vpcRoute53Resolver: prepareResolverConfig(vpcConfig),
34683468
};
34693469
};
34703470

@@ -3493,7 +3493,7 @@ export class ConvertAseaConfig {
34933493
.filter(({ vpcConfig }) => !!vpcConfig.pcx)
34943494
.map(({ vpcConfig }) => ({
34953495
name: peeringConnectionName(vpcConfig.name, vpcConfig.pcx!['source-vpc']),
3496-
vpcs: [this.getLzaVpcName(vpcConfig.name), this.getLzaVpcName(vpcConfig.pcx!['source-vpc'])],
3496+
vpcs: [createVpcName(vpcConfig.lzaVpcName ?? vpcConfig.name), createVpcName(vpcConfig.pcx!['source-vpc'])],
34973497
}));
34983498
};
34993499
await setCertificatesConfig();
@@ -3660,10 +3660,6 @@ export class ConvertAseaConfig {
36603660
);
36613661
}
36623662

3663-
private getLzaVpcName(vpcName: string): string {
3664-
return this.vpcConfigs.find((vc) => vc.vpcConfig.name === vpcName )?.lzaVpcName!
3665-
}
3666-
36673663
private getVpcCidr({ accountKey, vpcConfig, ouKey }: { accountKey?: string; vpcConfig: VpcConfig; ouKey?: string }) {
36683664
const cidrs: string[] = [];
36693665
if (vpcConfig['cidr-src'] === 'provided') {

src/installer/cdk/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ class Installer extends cdk.Stack {
279279
nodejs: 22,
280280
},
281281
commands: [
282-
'npm install --global pnpm@10.11.0',
282+
'npm install --global pnpm@10.4.1',
283283
'pnpm install --frozen-lockfile',
284284
'pnpm recursive run build',
285285
],

src/lib/cdk-accelerator/src/codebuild/cdk-deploy-project.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export class PrebuiltCdkDeployProject extends CdkDeployProjectBase {
146146
fs.writeFileSync(
147147
path.join(this.projectTmpDir, 'Dockerfile'),
148148
[
149-
'FROM public.ecr.aws/bitnami/node:22',
149+
'FROM public.ecr.aws/bitnami/node:18',
150150
// Install the package manager
151151
...installPackageManagerCommands(props.packageManager).map(cmd => `RUN ${cmd}`),
152152
`WORKDIR ${appDir}`,
@@ -194,7 +194,7 @@ export class PrebuiltCdkDeployProject extends CdkDeployProjectBase {
194194
*/
195195
function installPackageManagerCommands(packageManager: PackageManager) {
196196
if (packageManager === 'pnpm') {
197-
return ['npm install --global pnpm@10.11.0'];
197+
return ['npm install --global pnpm@10.4.1'];
198198
}
199199
throw new Error(`Unsupported package manager ${packageManager}`);
200200
}

0 commit comments

Comments
 (0)