Skip to content

Commit 4c4868e

Browse files
fix(core): Adding more outputs to SSM (#413)
Co-authored-by: nachundu <nachundu@amazon.com>
1 parent 400f2a0 commit 4c4868e

File tree

14 files changed

+84
-15
lines changed

14 files changed

+84
-15
lines changed

src/core/cdk/src/initial-setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ export namespace InitialSetup {
538538
'configFilePath.$': '$.configFilePath',
539539
'configCommitId.$': '$.configCommitId',
540540
outputUtilsTableName: outputUtilsTable.tableName,
541+
accountsTableName: parametersTable.tableName,
541542
},
542543
}),
543544
resultPath: 'DISCARD',

src/core/cdk/src/tasks/store-outputs-to-ssm-task.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export class StoreOutputsToSSMTask extends sfn.StateMachineFragment {
4444
'configFilePath.$': '$.configFilePath',
4545
'configCommitId.$': '$.configCommitId',
4646
'outputUtilsTableName.$': '$.outputUtilsTableName',
47+
'accountsTableName.$': '$.accountsTableName',
4748
},
4849
});
4950

@@ -72,6 +73,7 @@ export class StoreOutputsToSSMTask extends sfn.StateMachineFragment {
7273
'configFilePath.$': '$.configFilePath',
7374
'configCommitId.$': '$.configCommitId',
7475
'outputUtilsTableName.$': '$.outputUtilsTableName',
76+
'accountsTableName.$': '$.accountsTableName',
7577
},
7678
});
7779

src/core/runtime/src/create-stack-set/create-stack-set.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export const handler = async (input: CreateStackSetInput) => {
4545
OperationPreferences: {
4646
FailureTolerancePercentage: 100,
4747
MaxConcurrentPercentage: 100,
48-
MaxConcurrentCount: 10,
4948
},
5049
});
5150
return {

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

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { getOutput, OutputUtilGenericType, SaveOutputsInput, getIndexOutput, sav
33
import { SSM } from '@aws-accelerator/common/src/aws/ssm';
44
import { STS } from '@aws-accelerator/common/src/aws/sts';
55
import { LoadBalancerOutputFinder, LoadBalancerOutput } from '@aws-accelerator/common-outputs/src/elb';
6+
import { Account, getAccountId } from '@aws-accelerator/common-outputs/src/accounts';
67

78
interface OutputUtilLbType extends OutputUtilGenericType {
89
account: string;
@@ -36,6 +37,7 @@ export async function saveElbOutputs(props: SaveOutputsInput) {
3637
assumeRoleName,
3738
region,
3839
outputUtilsTableName,
40+
accounts,
3941
} = props;
4042
const oldElbOutputUtils = await getIndexOutput(outputUtilsTableName, `${account.key}-${region}-lelb`, dynamodb);
4143
// Existing index check happens on this variable
@@ -76,6 +78,7 @@ export async function saveElbOutputs(props: SaveOutputsInput) {
7678
type: 'nlb',
7779
accountKey: account.key,
7880
source: 'local',
81+
accounts: accounts!,
7982
})
8083
).lbs;
8184

@@ -88,6 +91,7 @@ export async function saveElbOutputs(props: SaveOutputsInput) {
8891
type: 'alb',
8992
accountKey: account.key,
9093
source: 'local',
94+
accounts: accounts!,
9195
})
9296
).lbs;
9397

@@ -172,6 +176,7 @@ export async function saveElbOutputs(props: SaveOutputsInput) {
172176
accountKey,
173177
source: 'remote',
174178
maxIndex: maxNlbIndex,
179+
accounts: accounts!,
175180
});
176181
newRemoteElbOutputs.nlbs.push(...saveNlbOp.lbs);
177182
maxNlbIndex = saveNlbOp.currentMaxIndex!;
@@ -185,6 +190,7 @@ export async function saveElbOutputs(props: SaveOutputsInput) {
185190
accountKey,
186191
source: 'remote',
187192
maxIndex: maxAlbIndex,
193+
accounts: accounts!,
188194
});
189195
newRemoteElbOutputs.albs.push(...saveAlbOp.lbs);
190196
maxAlbIndex = saveAlbOp.currentMaxIndex!;
@@ -207,6 +213,7 @@ export async function saveElbOutputs(props: SaveOutputsInput) {
207213
`/${acceleratorPrefix}/elb/nlb/${nlb.index}/name`,
208214
`/${acceleratorPrefix}/elb/nlb/${nlb.index}/dns`,
209215
`/${acceleratorPrefix}/elb/nlb/${nlb.index}/account`,
216+
`/${acceleratorPrefix}/elb/nlb/${nlb.index}/arn`,
210217
]),
211218
)
212219
.flatMap(s => s)
@@ -219,6 +226,7 @@ export async function saveElbOutputs(props: SaveOutputsInput) {
219226
`/${acceleratorPrefix}/elb/alb/${alb.index}/name`,
220227
`/${acceleratorPrefix}/elb/alb/${alb.index}/dns`,
221228
`/${acceleratorPrefix}/elb/alb/${alb.index}/account`,
229+
`/${acceleratorPrefix}/elb/alb/${alb.index}/arn`,
222230
]),
223231
)
224232
.flatMap(s => s)
@@ -238,11 +246,12 @@ async function saveElbOutputsImpl(props: {
238246
accountKey: string;
239247
source: 'local' | 'remote';
240248
maxIndex?: number;
249+
accounts: Account[];
241250
}): Promise<{
242251
lbs: OutputUtilLbType[];
243252
currentMaxIndex?: number;
244253
}> {
245-
const { acceleratorPrefix, lbOutputs, lbUtil, ssm, type, accountKey, source } = props;
254+
const { acceleratorPrefix, lbOutputs, lbUtil, ssm, type, accountKey, source, accounts } = props;
246255
const lbPrefix = source === 'local' ? 'lelb' : 'elb';
247256
if (lbUtil.length === 0 && lbOutputs.length === 0) {
248257
return {
@@ -265,27 +274,51 @@ async function saveElbOutputsImpl(props: {
265274
} else {
266275
currentIndex = ++maxIndex;
267276
}
268-
newLbUtils.push({
277+
278+
const lbOutput: OutputUtilLbType = {
269279
name: nlbOutput.name,
270280
index: currentIndex,
271281
account: accountKey,
272-
});
282+
parameters: ['name', 'dns', 'arn', 'account'],
283+
};
273284
if (previousIndex < 0) {
274285
await ssm.putParameter(`/${acceleratorPrefix}/${lbPrefix}/${type}/${currentIndex}/name`, nlbOutput.displayName);
275286
await ssm.putParameter(`/${acceleratorPrefix}/${lbPrefix}/${type}/${currentIndex}/dns`, nlbOutput.dnsName);
287+
await ssm.putParameter(`/${acceleratorPrefix}/${lbPrefix}/${type}/${currentIndex}/arn`, nlbOutput.arn);
276288
if (source === 'remote') {
277-
await ssm.putParameter(`/${acceleratorPrefix}/${lbPrefix}/${type}/${currentIndex}/account`, accountKey);
289+
await ssm.putParameter(
290+
`/${acceleratorPrefix}/${lbPrefix}/${type}/${currentIndex}/account`,
291+
getAccountId(accounts, accountKey)!,
292+
);
278293
}
279294
} else {
295+
const previousParams = lbUtil[previousIndex].parameters || [];
296+
if (!previousParams.includes('name')) {
297+
await ssm.putParameter(`/${acceleratorPrefix}/${lbPrefix}/${type}/${currentIndex}/name`, nlbOutput.displayName);
298+
}
299+
if (!previousParams.includes('dns')) {
300+
await ssm.putParameter(`/${acceleratorPrefix}/${lbPrefix}/${type}/${currentIndex}/dns`, nlbOutput.dnsName);
301+
}
302+
if (!previousParams.includes('arn')) {
303+
await ssm.putParameter(`/${acceleratorPrefix}/${lbPrefix}/${type}/${currentIndex}/arn`, nlbOutput.arn);
304+
}
305+
if (!previousParams.includes('account') && source === 'remote') {
306+
await ssm.putParameter(
307+
`/${acceleratorPrefix}/${lbPrefix}/${type}/${currentIndex}/account`,
308+
getAccountId(accounts, accountKey)!,
309+
);
310+
}
280311
lbUtil.splice(previousIndex, 1);
281312
}
313+
newLbUtils.push(lbOutput);
282314
}
283315

284316
const removeNames = lbUtil
285317
.map(lb => [
286318
`/${acceleratorPrefix}/${lbPrefix}/${type}/${lb.index}/name`,
287319
`/${acceleratorPrefix}/${lbPrefix}/${type}/${lb.index}/dns`,
288320
`/${acceleratorPrefix}/${lbPrefix}/${type}/${lb.index}/account`,
321+
`/${acceleratorPrefix}/${lbPrefix}/${type}/${lb.index}/arn`,
289322
])
290323
.flatMap(s => s);
291324
while (removeNames.length > 0) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export async function saveFirewallReplacementOutputs(props: SaveOutputsInput) {
105105
);
106106
}
107107
} else {
108-
const previousReplacements = Object.keys(outputUtils.firewalls[previousIndex].replacements);
108+
const previousReplacements = outputUtils.firewalls[previousIndex].replacements;
109109
const currentReplacements = Object.keys(output.replacements);
110110
for (const replacement of currentReplacements.filter(cr => !previousReplacements.includes(cr))) {
111111
await ssm.putParameter(

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { saveElbOutputs } from './elb-outputs';
88
import { saveEventOutputs } from './event-outputs';
99
import { saveEncryptsOutputs } from './encrypt-outputs';
1010
import { saveFirewallReplacementOutputs } from './firewall-outputs';
11+
import { loadAccounts } from './../utils/load-accounts';
1112

1213
export interface SaveOutputsToSsmInput extends LoadConfigurationInput {
1314
acceleratorPrefix: string;
@@ -16,6 +17,7 @@ export interface SaveOutputsToSsmInput extends LoadConfigurationInput {
1617
outputsTableName: string;
1718
assumeRoleName: string;
1819
outputUtilsTableName: string;
20+
accountsTableName: string;
1921
}
2022

2123
const dynamodb = new DynamoDB();
@@ -33,6 +35,7 @@ export const handler = async (input: SaveOutputsToSsmInput) => {
3335
assumeRoleName,
3436
region,
3537
outputUtilsTableName,
38+
accountsTableName,
3639
} = input;
3740
// Remove - if prefix ends with -
3841
const acceleratorPrefix = input.acceleratorPrefix.endsWith('-')
@@ -46,6 +49,9 @@ export const handler = async (input: SaveOutputsToSsmInput) => {
4649
commitId: configCommitId,
4750
});
4851

52+
// Retrive Accounts from DynamoDB
53+
const accounts = await loadAccounts(accountsTableName, dynamodb);
54+
4955
const globalRegions = config['global-options']['additional-global-output-regions'];
5056
const smRegion = config['global-options']['aws-org-master'].region;
5157

@@ -88,6 +94,7 @@ export const handler = async (input: SaveOutputsToSsmInput) => {
8894
outputUtilsTableName,
8995
outputsTableName,
9096
region,
97+
accounts,
9198
});
9299

93100
// Store Event Outputs to SSM Parameter Store

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ import { STS } from '@aws-accelerator/common/src/aws/sts';
1414
interface OutputUtilSubnet extends OutputUtilGenericType {
1515
azs: string[];
1616
}
17-
interface OutputUtilVpc {
18-
name: string;
17+
interface OutputUtilVpc extends OutputUtilGenericType {
1918
subnets: OutputUtilSubnet[];
2019
securityGroups: OutputUtilGenericType[];
21-
index: number;
2220
type: 'vpc' | 'lvpc';
2321
}
2422

@@ -254,6 +252,7 @@ export async function saveNetworkOutputs(props: SaveOutputsInput) {
254252
`/${acceleratorPrefix}/network/${removeObject.type}/${removeObject.index}/name`,
255253
`/${acceleratorPrefix}/network/${removeObject.type}/${removeObject.index}/id`,
256254
`/${acceleratorPrefix}/network/${removeObject.type}/${removeObject.index}/cidr`,
255+
`/${acceleratorPrefix}/network/${removeObject.type}/${removeObject.index}/cidr2`,
257256
];
258257
const removeNames = [...removalSgs, ...removalSns, ...removalVpc];
259258
while (removeNames.length > 0) {
@@ -277,11 +276,9 @@ async function saveVpcOutputs(props: {
277276
const { acceleratorPrefix, account, index, outputs, resolvedVpcConfig, ssm, vpcPrefix, sgOutputs, sharedVpc } = props;
278277
const { accountKey, vpcConfig } = resolvedVpcConfig;
279278
let vpcUtil: OutputUtilVpc;
280-
let updateRequired = false;
281279
if (props.vpcUtil) {
282280
vpcUtil = props.vpcUtil;
283281
} else {
284-
updateRequired = true;
285282
vpcUtil = {
286283
index,
287284
name: vpcConfig.name,
@@ -299,10 +296,24 @@ async function saveVpcOutputs(props: {
299296
console.warn(`VPC "${vpcConfig.name}" in account "${accountKey}" is not created`);
300297
return;
301298
}
302-
if (updateRequired) {
299+
if (!vpcUtil.parameters) {
300+
vpcUtil.parameters = [];
301+
}
302+
if (!vpcUtil.parameters.includes('name')) {
303303
await ssm.putParameter(`/${acceleratorPrefix}/network/${vpcPrefix}/${index}/name`, `${vpcOutput.vpcName}_vpc`);
304+
vpcUtil.parameters.push('name');
305+
}
306+
if (!vpcUtil.parameters.includes('id')) {
304307
await ssm.putParameter(`/${acceleratorPrefix}/network/${vpcPrefix}/${index}/id`, vpcOutput.vpcId);
308+
vpcUtil.parameters.push('id');
309+
}
310+
if (!vpcUtil.parameters.includes('cidr')) {
305311
await ssm.putParameter(`/${acceleratorPrefix}/network/${vpcPrefix}/${index}/cidr`, vpcOutput.cidrBlock);
312+
vpcUtil.parameters.push('cidr');
313+
}
314+
if (!vpcUtil.parameters.includes('cidr2') && vpcConfig.cidr2) {
315+
await ssm.putParameter(`/${acceleratorPrefix}/network/${vpcPrefix}/${index}/cidr2`, vpcConfig.cidr2.toCidrString());
316+
vpcUtil.parameters.push('cidr2');
306317
}
307318
let subnetsConfig = vpcConfig.subnets;
308319
if (sharedVpc) {
@@ -338,6 +349,7 @@ async function saveVpcOutputs(props: {
338349
securityGroupsUtil: vpcUtil.securityGroups,
339350
});
340351
}
352+
console.log(vpcUtil);
341353
return vpcUtil;
342354
}
343355

@@ -432,11 +444,11 @@ export async function saveSubnets(props: {
432444
} else {
433445
currentIndex = ++subnetMaxIndex;
434446
}
435-
updatedObjects.push({
447+
const newSubnetUtil: OutputUtilSubnet = {
436448
index: currentIndex,
437449
name: subnetConfig.name,
438450
azs: subnetConfig.definitions.filter(sn => !sn.disabled).map(s => s.az),
439-
});
451+
};
440452
for (const subnetDef of subnetConfig.definitions.filter(sn => !sn.disabled)) {
441453
const subnetOutput = subnetOutputs.find(vs => vs.subnetName === subnetConfig.name && vs.az === subnetDef.az);
442454
if (!subnetOutput) {
@@ -458,6 +470,8 @@ export async function saveSubnets(props: {
458470
);
459471
}
460472
}
473+
474+
updatedObjects.push(newSubnetUtil);
461475
const removalIndex = removalObjects?.findIndex(s => s.name === subnetConfig.name);
462476
if (removalIndex >= 0) {
463477
removalObjects?.splice(removalIndex, 1);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ export interface SaveOutputsInput {
1515
assumeRoleName: string;
1616
region: string;
1717
outputUtilsTableName: string;
18+
accounts?: Account[];
1819
}
1920

2021
export interface OutputUtilGenericType {
2122
name: string;
2223
index: number;
24+
parameters?: string[];
2325
}
2426

2527
export async function getOutput(tableName: string, key: string, dynamodb: DynamoDB): Promise<StackOutput[]> {

src/core/runtime/src/store-stack-output-step.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const handler = async (input: StoreStackOutputInput) => {
2929
const credentials = await sts.getCredentialsForAccountAndRole(account.id, assumeRoleName);
3030
const cfn = new CloudFormation(credentials, region);
3131
const stacks = cfn.listStacksGenerator({
32-
StackStatusFilter: ['CREATE_COMPLETE', 'UPDATE_COMPLETE'],
32+
StackStatusFilter: ['CREATE_COMPLETE', 'UPDATE_COMPLETE', 'UPDATE_ROLLBACK_COMPLETE'],
3333
});
3434

3535
const outputs: StackOutput[] = [];

src/deployments/cdk/src/deployments/alb/step-1.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ export function createAlb(
181181
hostedZoneId: balancer.hostedZoneId,
182182
name: albConfig.name,
183183
type: 'APPLICATION',
184+
arn: balancer.arn,
184185
});
185186
}
186187

0 commit comments

Comments
 (0)