Skip to content

Commit

Permalink
feat(service-catalog): allow Product Stack to override analytics repo…
Browse files Browse the repository at this point in the history
…rting 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*
  • Loading branch information
GavinZZ authored Nov 7, 2024
1 parent b953b2a commit d8ad02a
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 26 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,15 @@
"DisableTemplateValidation": false,
"Info": {
"LoadTemplateFromURL": {
"Fn::Sub": "https://s3.test-region.${AWS::URLSuffix}/cdk-hnb659fds-assets-12345678-test-region/dd2d087eeb6ede1d2a9166639ccbde7bd1b10eef9ba2b4cb3d9855faa4fe8c1f.json"
"Fn::Sub": "https://s3.test-region.${AWS::URLSuffix}/cdk-hnb659fds-assets-12345678-test-region/afd1257a565d91b3bdd02740160c6b1731533aef02f55ffdd9a865dce235414c.json"
}
}
},
{
"DisableTemplateValidation": false,
"Info": {
"LoadTemplateFromURL": {
"Fn::Sub": "https://s3.test-region.${AWS::URLSuffix}/cdk-hnb659fds-assets-12345678-test-region/dd2d087eeb6ede1d2a9166639ccbde7bd1b10eef9ba2b4cb3d9855faa4fe8c1f.json"
"Fn::Sub": "https://s3.test-region.${AWS::URLSuffix}/cdk-hnb659fds-assets-12345678-test-region/afd1257a565d91b3bdd02740160c6b1731533aef02f55ffdd9a865dce235414c.json"
}
}
},
Expand All @@ -414,7 +414,7 @@
"DisableTemplateValidation": false,
"Info": {
"LoadTemplateFromURL": {
"Fn::Sub": "https://s3.test-region.${AWS::URLSuffix}/cdk-hnb659fds-assets-12345678-test-region/dd2d087eeb6ede1d2a9166639ccbde7bd1b10eef9ba2b4cb3d9855faa4fe8c1f.json"
"Fn::Sub": "https://s3.test-region.${AWS::URLSuffix}/cdk-hnb659fds-assets-12345678-test-region/afd1257a565d91b3bdd02740160c6b1731533aef02f55ffdd9a865dce235414c.json"
}
},
"Name": "v1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"Description": "foo bar",
"Resources": {
"TopicProductD757E287": {
"Type": "AWS::SNS::Topic"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"Description": "foo bar",
"Resources": {
"TopicProductD757E287": {
"Type": "AWS::SNS::Topic"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"Description": "foo bar",
"Resources": {
"TopicProductD757E287": {
"Type": "AWS::SNS::Topic"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ const stack = new cdk.Stack(app, 'integ-servicecatalog-product', {

class TestProductStack extends servicecatalog.ProductStack {
constructor(scope: any, id: string) {
super(scope, id);
super(scope, id, {
description: 'foo bar',
});

new sns.Topic(this, 'TopicProduct');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"Description": "foo bar",
"Resources": {
"TopicProductD757E287": {
"Type": "AWS::SNS::Topic"
Expand Down
17 changes: 17 additions & 0 deletions packages/aws-cdk-lib/aws-servicecatalog/lib/product-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ export interface ProductStackProps {
* @default 128
*/
readonly memoryLimit?: number;

/**
* A description of the stack.
*
* @default - No description.
*/
readonly description?: string;

/**
* Include runtime versioning information in this Stack
*
* @default - `analyticsReporting` setting of containing `App`, or value of
* 'aws:cdk:version-reporting' context key
*/
readonly analyticsReporting?: boolean;
}

/**
Expand All @@ -64,6 +79,8 @@ export class ProductStack extends cdk.Stack {
constructor(scope: Construct, id: string, props: ProductStackProps = {}) {
const parentStack = findParentStack(scope);
super(scope, id, {
analyticsReporting: props.analyticsReporting,
description: props.description,
synthesizer: new ProductStackSynthesizer({
parentStack,
assetBucket: props.assetBucket,
Expand Down
20 changes: 20 additions & 0 deletions packages/aws-cdk-lib/aws-servicecatalog/test/product-stack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@ describe('ProductStack', () => {
expect(assembly.directory).toBe('/tmp/foobar');
});

test.each([true, false])('Can enable or disable anlaytics reporting in product stack', (enabled) => {
// GIVEN
const app = new cdk.App();
const mainStack = new cdk.Stack(app, 'MyStackAbsolutePath');
const testAssetBucket = new s3.Bucket(mainStack, 'TestAssetBucket', {
bucketName: 'test-asset-bucket',
});
const productStack = new ProductWithAnAsset(mainStack, 'MyProductStackAbsolutePath', {
assetBucket: testAssetBucket,
analyticsReporting: enabled,
description: 'foo bar',
});

// THEN
const assembly = app.synth();
const stackTemplate = JSON.parse(fs.readFileSync(path.join(assembly.directory, productStack.templateFile), 'utf-8'));
Template.fromJSON(stackTemplate).resourceCountIs('AWS::CDK::Metadata', enabled ? 1 : 0);
expect(Template.fromJSON(stackTemplate).toJSON().Description).toEqual('foo bar');
});

test('Used defined Asset bucket in product stack with nested assets', () => {
// GIVEN
const app = new cdk.App(
Expand Down

0 comments on commit d8ad02a

Please sign in to comment.