in src/deployments/cdk/src/deployments/alb/step-1.ts [53:157]
export async function step1(props: ElbStep1Props) {
const {
accountStacks,
config,
outputs,
aesLogArchiveBucket,
acceleratorExecutionRoleName,
accounts,
deployAlb,
deployGlb,
} = props;
const vpcConfigs = config.getVpcConfigs();
for (const { ouKey, accountKey, albs: albConfigs } of config.getElbConfigs()) {
if (albConfigs.length === 0) {
continue;
}
if (ouKey) {
const accountConfigs = config.getAccountConfigsForOu(ouKey);
const accountConfig = accountConfigs.find(([aKey, _]) => aKey === accountKey);
if (accountConfig && accountConfig[1]['exclude-ou-albs']) {
continue;
}
}
for (const albConfig of albConfigs) {
const vpcConfig = vpcConfigs.find(v => v.vpcConfig.name === albConfig.vpc)?.vpcConfig;
if (!vpcConfig) {
console.warn(`Cannot find vpc config with name ${albConfig.vpc}`);
continue;
}
const accountStack = accountStacks.tryGetOrCreateAccountStack(accountKey, vpcConfig.region);
if (!accountStack) {
console.warn(`Cannot find account stack ${accountKey}`);
continue;
}
const accountConfig = config.getAccountConfigs().find(([accKey, _]) => accKey === accountKey)?.[1];
const tags = albConfig['apply-tags'] || {};
/* eslint-disable no-template-curly-in-string */
for (const [key, value] of Object.entries(tags)) {
let tagValue = value;
let replacementValue = tagValue.match('\\${SEA::([a-zA-Z0-9-]*)}');
while (replacementValue) {
const replaceKey = replacementValue[1];
let replaceValue = replaceKey;
if (replaceKey === 'FirewallLaunchConfig') {
if (
accountConfig &&
accountConfig.deployments &&
accountConfig.deployments.firewalls &&
accountConfig.deployments.firewalls.length > 0
) {
const fwConfig = accountConfig.deployments.firewalls.find(
fw => fw.type === 'autoscale' && fw.deploy && fw['load-balancer'] === albConfig.name,
);
if (fwConfig) {
replaceValue = createName({
name: fwConfig.name,
suffixLength: 0,
});
}
}
} else if (
replaceKey === 'FirewallManager' &&
accountConfig &&
accountConfig.deployments &&
accountConfig.deployments['firewall-manager']
) {
replaceValue = createName({
name: accountConfig.deployments['firewall-manager'].name,
suffixLength: 0,
});
}
tagValue = tagValue.replace(new RegExp('\\${SEA::' + replaceKey + '}', 'g'), replaceValue);
replacementValue = tagValue.match('\\${SEA::([a-zA-Z0-9-]*)}');
}
/* eslint-enable */
tags[key] = tagValue;
}
if (albConfig.type === 'ALB' && deployAlb) {
createAlb({
accountKey,
albConfig,
accountStack,
outputs,
aesLogArchiveBucket,
deploy: vpcConfig.deploy,
tags,
});
} else if (albConfig.type === 'GWLB' && deployGlb) {
createGlb({
accountKey,
lbConfig: albConfig,
accountStack,
outputs,
acceleratorExecutionRoleName: acceleratorExecutionRoleName!,
accounts: accounts!,
tags,
});
}
}
}
}