Skip to content

Commit 08dba58

Browse files
fix(core): Fix adding stack level tags and handling duplicate Accelerator tag (#763)
* Adding new tag for cfn stacks * regular expression fix for testMatch with jest for cross os * Fixing store outputs
1 parent b35b1c5 commit 08dba58

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ export const handler = async (input: StoreStackOutputInput) => {
4040
console.warn(`Could not load stack with name "${summary.StackName}"`);
4141
continue;
4242
}
43-
const acceleratorTag = stack.Tags?.find(t => t.Key === 'Accelerator');
43+
const acceleratorTag = stack.Tags?.find(t => t.Key === 'AcceleratorName');
4444
if (!acceleratorTag) {
45-
console.warn(`Could not find Accelerator tag in stack with name "${summary.StackName}"`);
45+
console.warn(`Could not find AcceleratorName tag in stack with name "${summary.StackName}"`);
4646
continue;
4747
}
4848

src/deployments/cdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
"preset": "ts-jest",
153153
"testEnvironment": "node",
154154
"testMatch": [
155-
"<rootDir>/test/**/(*.)+(spec|test).ts"
155+
"<rootDir>/test/**/*(*.)@(spec|test).[t]s?(x)"
156156
]
157157
}
158158
}

src/deployments/cdk/toolkit.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ function tagsForStack(stack: CloudFormationStackArtifact): Tag[] {
302302
// unfortunately.
303303
x => toCloudFormationTags(x.data as cxschema.Tag[]),
304304
);
305-
return Array.prototype.concat([], ...tagLists);
305+
// Conditional operator to remove undefined (Will get for Accelerator)
306+
return Array.prototype.concat([], tagLists.length > 0 ? tagLists[0].filter(t => !!t) : []);
306307
}
307308

308309
/**
@@ -312,5 +313,10 @@ function tagsForStack(stack: CloudFormationStackArtifact): Tag[] {
312313
* to the way that CloudFormation expects them. (Different casing).
313314
*/
314315
function toCloudFormationTags(tags: cxschema.Tag[]): Tag[] {
315-
return tags.map(t => ({ Key: t.key, Value: t.value }));
316+
return tags.map(t => {
317+
// Ignoring Accelerator tag in CFN since that is duplicated
318+
if (t.key !== 'Accelerator') {
319+
return { Key: t.key, Value: t.value };
320+
}
321+
});
316322
}

src/lib/cdk-accelerator/src/core/accelerator-stack.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export class AcceleratorStack extends cdk.Stack {
1616
this.acceleratorName = props.acceleratorName;
1717
this.acceleratorPrefix = props.acceleratorPrefix;
1818

19+
// Add Stack level tags using this.tags, so that CDK won't add them to resource in CFN
20+
this.tags.setTag('AcceleratorName', this.acceleratorName);
1921
cdk.Aspects.of(this).add(new cdk.Tag('Accelerator', this.acceleratorName));
2022
cdk.Aspects.of(this).add(new AcceleratorNameTagger());
2123
cdk.Aspects.of(this).add(new AcceleratorProtectedTagger(this.acceleratorName));

0 commit comments

Comments
 (0)