Skip to content

Commit d8ad02a

Browse files
authored
feat(service-catalog): allow Product Stack to override analytics reporting and stack descriptions (#31985)
### Issue # (if applicable) Closes #31924 ### Reason for this change Product Stack cannot override analytics reporting and descriptions. Support these two props. ### Description of changes The reason I didn't choose to allow ProductStackProps to extend StackProps and instead manually add these two properties are because all of the other properties, i.e. `stackName`, `env`, `notificationArns`, `terminationProtection`, `crossRegionReferences`, `permissionsBoundary`, `suppressTemplateIndentation`, do not mutate the stack template but are used by CDK CLI. These properties have no impact on the Product Stack template generated and thus I did not include them. ### Description of how you validated changes Unit and integ tests added. ### Checklist - [ ] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent b953b2a commit d8ad02a

11 files changed

+66
-26
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-servicecatalog/test/integ.product.js.snapshot/integ-servicecatalog-product.assets.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-servicecatalog/test/integ.product.js.snapshot/integ-servicecatalog-product.template.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -389,15 +389,15 @@
389389
"DisableTemplateValidation": false,
390390
"Info": {
391391
"LoadTemplateFromURL": {
392-
"Fn::Sub": "https://s3.test-region.${AWS::URLSuffix}/cdk-hnb659fds-assets-12345678-test-region/dd2d087eeb6ede1d2a9166639ccbde7bd1b10eef9ba2b4cb3d9855faa4fe8c1f.json"
392+
"Fn::Sub": "https://s3.test-region.${AWS::URLSuffix}/cdk-hnb659fds-assets-12345678-test-region/afd1257a565d91b3bdd02740160c6b1731533aef02f55ffdd9a865dce235414c.json"
393393
}
394394
}
395395
},
396396
{
397397
"DisableTemplateValidation": false,
398398
"Info": {
399399
"LoadTemplateFromURL": {
400-
"Fn::Sub": "https://s3.test-region.${AWS::URLSuffix}/cdk-hnb659fds-assets-12345678-test-region/dd2d087eeb6ede1d2a9166639ccbde7bd1b10eef9ba2b4cb3d9855faa4fe8c1f.json"
400+
"Fn::Sub": "https://s3.test-region.${AWS::URLSuffix}/cdk-hnb659fds-assets-12345678-test-region/afd1257a565d91b3bdd02740160c6b1731533aef02f55ffdd9a865dce235414c.json"
401401
}
402402
}
403403
},
@@ -414,7 +414,7 @@
414414
"DisableTemplateValidation": false,
415415
"Info": {
416416
"LoadTemplateFromURL": {
417-
"Fn::Sub": "https://s3.test-region.${AWS::URLSuffix}/cdk-hnb659fds-assets-12345678-test-region/dd2d087eeb6ede1d2a9166639ccbde7bd1b10eef9ba2b4cb3d9855faa4fe8c1f.json"
417+
"Fn::Sub": "https://s3.test-region.${AWS::URLSuffix}/cdk-hnb659fds-assets-12345678-test-region/afd1257a565d91b3bdd02740160c6b1731533aef02f55ffdd9a865dce235414c.json"
418418
}
419419
},
420420
"Name": "v1"

packages/@aws-cdk-testing/framework-integ/test/aws-servicecatalog/test/integ.product.js.snapshot/integservicecatalogproductSNSTopicProduct1B8D03934.product.template.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"Description": "foo bar",
23
"Resources": {
34
"TopicProductD757E287": {
45
"Type": "AWS::SNS::Topic"

packages/@aws-cdk-testing/framework-integ/test/aws-servicecatalog/test/integ.product.js.snapshot/integservicecatalogproductSNSTopicProduct24C7C16DA.product.template.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"Description": "foo bar",
23
"Resources": {
34
"TopicProductD757E287": {
45
"Type": "AWS::SNS::Topic"

packages/@aws-cdk-testing/framework-integ/test/aws-servicecatalog/test/integ.product.js.snapshot/integservicecatalogproductSNSTopicProduct3B51CF591.product.template.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"Description": "foo bar",
23
"Resources": {
34
"TopicProductD757E287": {
45
"Type": "AWS::SNS::Topic"

packages/@aws-cdk-testing/framework-integ/test/aws-servicecatalog/test/integ.product.js.snapshot/manifest.json

+2-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-servicecatalog/test/integ.product.js.snapshot/tree.json

+13-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-servicecatalog/test/integ.product.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ const stack = new cdk.Stack(app, 'integ-servicecatalog-product', {
7070

7171
class TestProductStack extends servicecatalog.ProductStack {
7272
constructor(scope: any, id: string) {
73-
super(scope, id);
73+
super(scope, id, {
74+
description: 'foo bar',
75+
});
7476

7577
new sns.Topic(this, 'TopicProduct');
7678
}

packages/@aws-cdk-testing/framework-integ/test/aws-servicecatalog/test/product-stack-snapshots/integservicecatalogproductProductStackHistory4D520FF1.integservicecatalogproductSNSTopicProduct3B51CF591.v1.product.template.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"Description": "foo bar",
23
"Resources": {
34
"TopicProductD757E287": {
45
"Type": "AWS::SNS::Topic"

packages/aws-cdk-lib/aws-servicecatalog/lib/product-stack.ts

+17
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,21 @@ export interface ProductStackProps {
4343
* @default 128
4444
*/
4545
readonly memoryLimit?: number;
46+
47+
/**
48+
* A description of the stack.
49+
*
50+
* @default - No description.
51+
*/
52+
readonly description?: string;
53+
54+
/**
55+
* Include runtime versioning information in this Stack
56+
*
57+
* @default - `analyticsReporting` setting of containing `App`, or value of
58+
* 'aws:cdk:version-reporting' context key
59+
*/
60+
readonly analyticsReporting?: boolean;
4661
}
4762

4863
/**
@@ -64,6 +79,8 @@ export class ProductStack extends cdk.Stack {
6479
constructor(scope: Construct, id: string, props: ProductStackProps = {}) {
6580
const parentStack = findParentStack(scope);
6681
super(scope, id, {
82+
analyticsReporting: props.analyticsReporting,
83+
description: props.description,
6784
synthesizer: new ProductStackSynthesizer({
6885
parentStack,
6986
assetBucket: props.assetBucket,

packages/aws-cdk-lib/aws-servicecatalog/test/product-stack.test.ts

+20
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,26 @@ describe('ProductStack', () => {
6969
expect(assembly.directory).toBe('/tmp/foobar');
7070
});
7171

72+
test.each([true, false])('Can enable or disable anlaytics reporting in product stack', (enabled) => {
73+
// GIVEN
74+
const app = new cdk.App();
75+
const mainStack = new cdk.Stack(app, 'MyStackAbsolutePath');
76+
const testAssetBucket = new s3.Bucket(mainStack, 'TestAssetBucket', {
77+
bucketName: 'test-asset-bucket',
78+
});
79+
const productStack = new ProductWithAnAsset(mainStack, 'MyProductStackAbsolutePath', {
80+
assetBucket: testAssetBucket,
81+
analyticsReporting: enabled,
82+
description: 'foo bar',
83+
});
84+
85+
// THEN
86+
const assembly = app.synth();
87+
const stackTemplate = JSON.parse(fs.readFileSync(path.join(assembly.directory, productStack.templateFile), 'utf-8'));
88+
Template.fromJSON(stackTemplate).resourceCountIs('AWS::CDK::Metadata', enabled ? 1 : 0);
89+
expect(Template.fromJSON(stackTemplate).toJSON().Description).toEqual('foo bar');
90+
});
91+
7292
test('Used defined Asset bucket in product stack with nested assets', () => {
7393
// GIVEN
7494
const app = new cdk.App(

0 commit comments

Comments
 (0)