From 99b886ef775fe018644d298fc3c7b21848184686 Mon Sep 17 00:00:00 2001 From: Santanu Ghosh Date: Tue, 6 Dec 2022 10:39:45 -0800 Subject: [PATCH 1/4] Adding CfnOutput with App manager URL, handling conditonal nested stacks --- .../lib/application.ts | 29 ++++++-- .../test/application.test.ts | 68 +++++++++++++++++-- .../integ.application.js.snapshot/cdk.out | 2 +- ...catalogappregistry-application.assets.json | 6 +- ...talogappregistry-application.template.json | 20 +++++- .../integ.application.js.snapshot/integ.json | 2 +- .../manifest.json | 35 +++++++--- .../integ.application.js.snapshot/tree.json | 62 +++++++++++++---- 8 files changed, 180 insertions(+), 44 deletions(-) diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts index eb5112e45287e..4df50a9468d7d 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts @@ -34,6 +34,12 @@ export interface IApplication extends cdk.IResource { */ readonly applicationName?: string; + /** + * Application manager URL for the Application. + * @attribute + */ + readonly applicationManagerUrl?: cdk.CfnOutput; + /** * Associate this application with an attribute group. * @@ -94,6 +100,7 @@ abstract class ApplicationBase extends cdk.Resource implements IApplication { public abstract readonly applicationArn: string; public abstract readonly applicationId: string; public abstract readonly applicationName?: string; + public abstract readonly applicationManagerUrl?: cdk.CfnOutput; private readonly associatedAttributeGroups: Set = new Set(); private readonly associatedResources: Set = new Set(); @@ -134,20 +141,26 @@ abstract class ApplicationBase extends cdk.Resource implements IApplication { /** * Associate stack with the application in the stack passed as parameter. * - * If the stack is already associated, it will ignore duplicate request. * A stack can only be associated with one application. */ public associateApplicationWithStack(stack: cdk.Stack): void { if (!this.associatedResources.has(stack.node.addr)) { - new CfnResourceAssociation(stack, 'AppRegistryAssociation', { + const stackCondition = stack.nestedStackResource?.cfnOptions.condition; + const association = new CfnResourceAssociation(stack, 'AppRegistryAssociation', { application: stack === cdk.Stack.of(this) ? this.applicationId : this.applicationName ?? this.applicationId, resource: stack.stackId, resourceType: 'CFN_STACK', }); - this.associatedResources.add(stack.node.addr); - if (stack !== cdk.Stack.of(this) && this.isSameAccount(stack) && !this.isStageScope(stack)) { - stack.addDependency(cdk.Stack.of(this)); + if (stackCondition) { + association.addOverride('Condition', stackCondition.logicalId); + } + + if (!stack.nested) { + this.associatedResources.add(stack.node.addr); + if (stack !== cdk.Stack.of(this) && this.isSameAccount(stack) && !this.isStageScope(stack)) { + stack.addDependency(cdk.Stack.of(this)); + } } } } @@ -240,6 +253,7 @@ export class Application extends ApplicationBase { public readonly applicationArn = applicationArn; public readonly applicationId = applicationId!; public readonly applicationName = undefined; + public readonly applicationManagerUrl = undefined; protected generateUniqueHash(resourceAddress: string): string { return hashValues(this.applicationArn, resourceAddress); @@ -254,6 +268,7 @@ export class Application extends ApplicationBase { public readonly applicationArn: string; public readonly applicationId: string; public readonly applicationName?: string; + public readonly applicationManagerUrl?: cdk.CfnOutput; private readonly nodeAddress: string; constructor(scope: Construct, id: string, props: ApplicationProps) { @@ -270,6 +285,10 @@ export class Application extends ApplicationBase { this.applicationId = application.attrId; this.applicationName = props.applicationName; this.nodeAddress = cdk.Names.nodeUniqueId(application.node); + + this.applicationManagerUrl = new cdk.CfnOutput(this, 'ApplicationManagerUrl', { + value: `https://${this.env.region}.console.aws.amazon.com/systems-manager/appmanager/application/AWS_AppRegistry_Application-${this.applicationName}`, + }); } protected generateUniqueHash(resourceAddress: string): string { diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/application.test.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application.test.ts index dce0d1147ec44..8783de5605e4a 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/application.test.ts +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application.test.ts @@ -34,11 +34,13 @@ describe('Application', () => { test('application with explicit description', () => { const description = 'my test application description'; - new appreg.Application(stack, 'MyApplication', { + const application = new appreg.Application(stack, 'MyApplication', { applicationName: 'testApplication', description: description, }); + Template.fromStack(stack).hasOutput('MyApplicationApplicationManagerUrlB79EF34D', {}); + expect(application.applicationManagerUrl?.value).toContain('AWS_AppRegistry_Application-testApplication'); Template.fromStack(stack).hasResourceProperties('AWS::ServiceCatalogAppRegistry::Application', { Description: description, }); @@ -254,7 +256,7 @@ describe('Application', () => { Template.fromStack(stack).hasResourceProperties('AWS::RAM::ResourceShare', { AllowExternalPrincipals: false, - Name: 'RAMSharee6e0e560e6f8', + Name: 'RAMShare5bb637032063', Principals: ['arn:aws:organizations::123456789012:organization/o-70oi5564q1'], ResourceArns: [{ 'Fn::GetAtt': ['MyApplication5C63EC1D', 'Arn'] }], PermissionArns: ['arn:aws:ram::aws:permission/AWSRAMPermissionServiceCatalogAppRegistryApplicationReadOnly'], @@ -268,7 +270,7 @@ describe('Application', () => { Template.fromStack(stack).hasResourceProperties('AWS::RAM::ResourceShare', { AllowExternalPrincipals: false, - Name: 'RAMSharee6e0e560e6f8', + Name: 'RAMShare5bb637032063', Principals: ['123456789012'], ResourceArns: [{ 'Fn::GetAtt': ['MyApplication5C63EC1D', 'Arn'] }], PermissionArns: ['arn:aws:ram::aws:permission/AWSRAMPermissionServiceCatalogAppRegistryApplicationReadOnly'], @@ -284,7 +286,7 @@ describe('Application', () => { Template.fromStack(stack).hasResourceProperties('AWS::RAM::ResourceShare', { AllowExternalPrincipals: false, - Name: 'RAMSharee6e0e560e6f8', + Name: 'RAMShare5bb637032063', Principals: ['arn:aws:iam::123456789012:role/myRole'], ResourceArns: [{ 'Fn::GetAtt': ['MyApplication5C63EC1D', 'Arn'] }], PermissionArns: ['arn:aws:ram::aws:permission/AWSRAMPermissionServiceCatalogAppRegistryApplicationReadOnly'], @@ -300,7 +302,7 @@ describe('Application', () => { Template.fromStack(stack).hasResourceProperties('AWS::RAM::ResourceShare', { AllowExternalPrincipals: false, - Name: 'RAMSharee6e0e560e6f8', + Name: 'RAMShare5bb637032063', Principals: ['arn:aws:iam::123456789012:user/myUser'], ResourceArns: [{ 'Fn::GetAtt': ['MyApplication5C63EC1D', 'Arn'] }], PermissionArns: ['arn:aws:ram::aws:permission/AWSRAMPermissionServiceCatalogAppRegistryApplicationReadOnly'], @@ -315,7 +317,7 @@ describe('Application', () => { Template.fromStack(stack).hasResourceProperties('AWS::RAM::ResourceShare', { AllowExternalPrincipals: false, - Name: 'RAMSharee6e0e560e6f8', + Name: 'RAMShare5bb637032063', Principals: ['arn:aws:organizations::123456789012:organization/o-70oi5564q1'], ResourceArns: [{ 'Fn::GetAtt': ['MyApplication5C63EC1D', 'Arn'] }], PermissionArns: ['arn:aws:ram::aws:permission/AWSRAMPermissionServiceCatalogAppRegistryApplicationReadOnly'], @@ -330,7 +332,7 @@ describe('Application', () => { Template.fromStack(stack).hasResourceProperties('AWS::RAM::ResourceShare', { AllowExternalPrincipals: false, - Name: 'RAMSharee6e0e560e6f8', + Name: 'RAMShare5bb637032063', Principals: ['arn:aws:organizations::123456789012:organization/o-70oi5564q1'], ResourceArns: [{ 'Fn::GetAtt': ['MyApplication5C63EC1D', 'Arn'] }], PermissionArns: ['arn:aws:ram::aws:permission/AWSRAMPermissionServiceCatalogAppRegistryApplicationAllowAssociation'], @@ -446,8 +448,60 @@ describe('Scope based Associations with Application with Cross Region/Account', }); }); +describe('Conditional nested stack Associations with Application within Same Account', () => { + let app: cdk.App; + beforeEach(() => { + app = new cdk.App({ + context: { + '@aws-cdk/core:newStyleStackSynthesis': false, + }, + }); + }); + + test('Associate conditional nested stack with application', () => { + const stack = new MainStack(app, 'cdkApplication'); + const application = new appreg.Application(stack, 'MyApplication', { + applicationName: 'MyApplication', + }); + application.associateApplicationWithStack(stack); + application.associateApplicationWithStack(stack.nestedStack); + Template.fromStack(stack.nestedStack).hasResource('AWS::ServiceCatalogAppRegistry::ResourceAssociation', { + Properties: { + Application: 'MyApplication', + Resource: { Ref: 'AWS::StackId' }, + ResourceType: 'CFN_STACK', + }, + Condition: 'ShouldCreateStackCondition', + }); + Template.fromStack(stack.nestedStack).hasCondition('ShouldCreateStackCondition', { + 'Fn::Equals': ['us-east-1'], + }); + }); + +}); + + class AppRegistrySampleStack extends cdk.Stack { public constructor(scope: Construct, id: string, props?: cdk.StackProps) { super(scope, id, props); } } + +class MainStack extends cdk.Stack { + public readonly nestedStack: cdk.Stack; + public constructor(parent: cdk.App, id: string, props?: cdk.StackProps) { + super(parent, id, props); + this.nestedStack = new AppRegistryNestedStack(this, 'nested-stack'); + } +} + +class AppRegistryNestedStack extends cdk.NestedStack { + public constructor(scope: Construct, id: string, props?: cdk.NestedStackProps) { + super(scope, id, props); + + const shouldCreateStack = new cdk.CfnCondition(this, 'ShouldCreateStackCondition', { + expression: cdk.Fn.conditionEquals(process.env.CDK_DEFAULT_REGION, 'us-east-1'), + }); + (this.nestedStackResource as cdk.CfnStack).cfnOptions.condition = shouldCreateStack; + } +} diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/cdk.out b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/cdk.out index 8ecc185e9dbee..145739f539580 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/cdk.out +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/cdk.out @@ -1 +1 @@ -{"version":"21.0.0"} \ No newline at end of file +{"version":"22.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.assets.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.assets.json index 7f5db7d1e1328..095db348cca9e 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.assets.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.assets.json @@ -1,7 +1,7 @@ { - "version": "20.0.0", + "version": "22.0.0", "files": { - "d03aa6239eb3b20f4b72fb3dd44a4082d06d7a5451d0ac3855bd1aa78aecfbe9": { + "9865325ce7d796431795070b89be47ba38a72d3daf71cf6958de99f1850c6013": { "source": { "path": "integ-servicecatalogappregistry-application.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "d03aa6239eb3b20f4b72fb3dd44a4082d06d7a5451d0ac3855bd1aa78aecfbe9.json", + "objectKey": "9865325ce7d796431795070b89be47ba38a72d3daf71cf6958de99f1850c6013.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.template.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.template.json index e36d7a3b58794..2a42e5cbd26d2 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.template.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.template.json @@ -39,10 +39,10 @@ } } }, - "TestApplicationRAMSharead8ba81b8cdd40199FD1": { + "TestApplicationRAMShare3dc6227daec11BF3E108": { "Type": "AWS::RAM::ResourceShare", "Properties": { - "Name": "RAMSharead8ba81b8cdd", + "Name": "RAMShare3dc6227daec1", "AllowExternalPrincipals": false, "PermissionArns": [ "arn:aws:ram::aws:permission/AWSRAMPermissionServiceCatalogAppRegistryApplicationReadOnly" @@ -121,6 +121,22 @@ } } }, + "Outputs": { + "TestApplicationApplicationManagerUrlE1058321": { + "Value": { + "Fn::Join": [ + "", + [ + "https://", + { + "Ref": "AWS::Region" + }, + ".console.aws.amazon.com/systems-manager/appmanager/application/AWS_AppRegistry_Application-myApplicationtest" + ] + ] + } + } + }, "Parameters": { "BootstrapVersion": { "Type": "AWS::SSM::Parameter::Value", diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ.json index 5178be112c70a..7db84c3e5dfa8 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ.json @@ -1,5 +1,5 @@ { - "version": "20.0.0", + "version": "22.0.0", "testCases": { "integ.application": { "stacks": [ diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/manifest.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/manifest.json index d78791dfe49aa..7a17a097be2a1 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/manifest.json @@ -1,12 +1,6 @@ { - "version": "20.0.0", + "version": "22.0.0", "artifacts": { - "Tree": { - "type": "cdk:tree", - "properties": { - "file": "tree.json" - } - }, "integ-servicecatalogappregistry-application.assets": { "type": "cdk:asset-manifest", "properties": { @@ -23,7 +17,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/d03aa6239eb3b20f4b72fb3dd44a4082d06d7a5451d0ac3855bd1aa78aecfbe9.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/9865325ce7d796431795070b89be47ba38a72d3daf71cf6958de99f1850c6013.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -45,6 +39,12 @@ "data": "TestApplication2FBC585F" } ], + "/integ-servicecatalogappregistry-application/TestApplication/ApplicationManagerUrl": [ + { + "type": "aws:cdk:logicalId", + "data": "TestApplicationApplicationManagerUrlE1058321" + } + ], "/integ-servicecatalogappregistry-application/TestApplication/ResourceAssociationd232b63e52a8": [ { "type": "aws:cdk:logicalId", @@ -57,10 +57,10 @@ "data": "TestApplicationAttributeGroupAssociation4ba7f5842818B8EE1C6F" } ], - "/integ-servicecatalogappregistry-application/TestApplication/RAMSharead8ba81b8cdd": [ + "/integ-servicecatalogappregistry-application/TestApplication/RAMShare3dc6227daec1": [ { "type": "aws:cdk:logicalId", - "data": "TestApplicationRAMSharead8ba81b8cdd40199FD1" + "data": "TestApplicationRAMShare3dc6227daec11BF3E108" } ], "/integ-servicecatalogappregistry-application/TestAttributeGroup/Resource": [ @@ -86,9 +86,24 @@ "type": "aws:cdk:logicalId", "data": "CheckBootstrapVersion" } + ], + "TestApplicationRAMSharead8ba81b8cdd40199FD1": [ + { + "type": "aws:cdk:logicalId", + "data": "TestApplicationRAMSharead8ba81b8cdd40199FD1", + "trace": [ + "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" + ] + } ] }, "displayName": "integ-servicecatalogappregistry-application" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } } } } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/tree.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/tree.json index f54792dcdef5c..b3e2b954b89d1 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/tree.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/tree.json @@ -4,14 +4,6 @@ "id": "App", "path": "", "children": { - "Tree": { - "id": "Tree", - "path": "Tree", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" - } - }, "integ-servicecatalogappregistry-application": { "id": "integ-servicecatalogappregistry-application", "path": "integ-servicecatalogappregistry-application", @@ -35,6 +27,14 @@ "version": "0.0.0" } }, + "ApplicationManagerUrl": { + "id": "ApplicationManagerUrl", + "path": "integ-servicecatalogappregistry-application/TestApplication/ApplicationManagerUrl", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnOutput", + "version": "0.0.0" + } + }, "ResourceAssociationd232b63e52a8": { "id": "ResourceAssociationd232b63e52a8", "path": "integ-servicecatalogappregistry-application/TestApplication/ResourceAssociationd232b63e52a8", @@ -83,13 +83,13 @@ "version": "0.0.0" } }, - "RAMSharead8ba81b8cdd": { - "id": "RAMSharead8ba81b8cdd", - "path": "integ-servicecatalogappregistry-application/TestApplication/RAMSharead8ba81b8cdd", + "RAMShare3dc6227daec1": { + "id": "RAMShare3dc6227daec1", + "path": "integ-servicecatalogappregistry-application/TestApplication/RAMShare3dc6227daec1", "attributes": { "aws:cdk:cloudformation:type": "AWS::RAM::ResourceShare", "aws:cdk:cloudformation:props": { - "name": "RAMSharead8ba81b8cdd", + "name": "RAMShare3dc6227daec1", "allowExternalPrincipals": false, "permissionArns": [ "arn:aws:ram::aws:permission/AWSRAMPermissionServiceCatalogAppRegistryApplicationReadOnly" @@ -168,6 +168,14 @@ "id": "MyRole", "path": "integ-servicecatalogappregistry-application/MyRole", "children": { + "ImportMyRole": { + "id": "ImportMyRole", + "path": "integ-servicecatalogappregistry-application/MyRole/ImportMyRole", + "constructInfo": { + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" + } + }, "Resource": { "id": "Resource", "path": "integ-servicecatalogappregistry-application/MyRole/Resource", @@ -213,17 +221,41 @@ "fqn": "@aws-cdk/aws-iam.Role", "version": "0.0.0" } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "integ-servicecatalogappregistry-application/BootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "integ-servicecatalogappregistry-application/CheckBootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnRule", + "version": "0.0.0" + } } }, + "constructInfo": { + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", "constructInfo": { "fqn": "constructs.Construct", - "version": "10.1.85" + "version": "10.1.168" } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.App", + "version": "0.0.0" } } } \ No newline at end of file From 140da6e02c7abe3e7f5cb48701f19bcdd9ada94c Mon Sep 17 00:00:00 2001 From: Santanu Ghosh Date: Tue, 6 Dec 2022 11:47:30 -0800 Subject: [PATCH 2/4] Changing integration test --- ...-servicecatalogappregistry-application.assets.json | 4 ++-- ...ervicecatalogappregistry-application.template.json | 6 +++--- .../test/integ.application.js.snapshot/manifest.json | 11 +---------- .../test/integ.application.js.snapshot/tree.json | 4 ++-- .../test/integ.application.ts | 4 ++-- 5 files changed, 10 insertions(+), 19 deletions(-) diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.assets.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.assets.json index 095db348cca9e..34ea8da07b973 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.assets.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.assets.json @@ -1,7 +1,7 @@ { "version": "22.0.0", "files": { - "9865325ce7d796431795070b89be47ba38a72d3daf71cf6958de99f1850c6013": { + "98d56556ece0e12b5e819d33e303424de1f579cdc95dd798bb2ee407ab2bda89": { "source": { "path": "integ-servicecatalogappregistry-application.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "9865325ce7d796431795070b89be47ba38a72d3daf71cf6958de99f1850c6013.json", + "objectKey": "98d56556ece0e12b5e819d33e303424de1f579cdc95dd798bb2ee407ab2bda89.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.template.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.template.json index 2a42e5cbd26d2..7bb4697945693 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.template.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.template.json @@ -3,7 +3,7 @@ "TestApplication2FBC585F": { "Type": "AWS::ServiceCatalogAppRegistry::Application", "Properties": { - "Name": "myApplicationtest", + "Name": "myCdkApplication", "Description": "my application description" } }, @@ -84,7 +84,7 @@ "release": "go time" } }, - "Name": "myAttributeGroupTest", + "Name": "myCdkAttributeGroup", "Description": "my attribute group description" } }, @@ -131,7 +131,7 @@ { "Ref": "AWS::Region" }, - ".console.aws.amazon.com/systems-manager/appmanager/application/AWS_AppRegistry_Application-myApplicationtest" + ".console.aws.amazon.com/systems-manager/appmanager/application/AWS_AppRegistry_Application-myCdkApplication" ] ] } diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/manifest.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/manifest.json index 7a17a097be2a1..a60c47b72662f 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/manifest.json @@ -17,7 +17,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/9865325ce7d796431795070b89be47ba38a72d3daf71cf6958de99f1850c6013.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/98d56556ece0e12b5e819d33e303424de1f579cdc95dd798bb2ee407ab2bda89.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -86,15 +86,6 @@ "type": "aws:cdk:logicalId", "data": "CheckBootstrapVersion" } - ], - "TestApplicationRAMSharead8ba81b8cdd40199FD1": [ - { - "type": "aws:cdk:logicalId", - "data": "TestApplicationRAMSharead8ba81b8cdd40199FD1", - "trace": [ - "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" - ] - } ] }, "displayName": "integ-servicecatalogappregistry-application" diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/tree.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/tree.json index b3e2b954b89d1..da9f344585ed2 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/tree.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/tree.json @@ -18,7 +18,7 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::ServiceCatalogAppRegistry::Application", "aws:cdk:cloudformation:props": { - "name": "myApplicationtest", + "name": "myCdkApplication", "description": "my application description" } }, @@ -149,7 +149,7 @@ "release": "go time" } }, - "name": "myAttributeGroupTest", + "name": "myCdkAttributeGroup", "description": "my attribute group description" } }, diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.ts index d51cad051252c..30f5e2bb88829 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.ts +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.ts @@ -6,12 +6,12 @@ const app = new cdk.App(); const stack = new cdk.Stack(app, 'integ-servicecatalogappregistry-application'); const application = new appreg.Application(stack, 'TestApplication', { - applicationName: 'myApplicationtest', + applicationName: 'myCdkApplication', description: 'my application description', }); const attributeGroup = new appreg.AttributeGroup(stack, 'TestAttributeGroup', { - attributeGroupName: 'myAttributeGroupTest', + attributeGroupName: 'myCdkAttributeGroup', description: 'my attribute group description', attributes: { stage: 'alpha', From 0d7940f5de9784da681376747076d333a6219a0b Mon Sep 17 00:00:00 2001 From: Santanu Ghosh Date: Thu, 8 Dec 2022 10:29:26 -0800 Subject: [PATCH 3/4] Adding description for AM url --- .../lib/application.ts | 15 ++++++--------- ...vicecatalogappregistry-application.assets.json | 4 ++-- ...cecatalogappregistry-application.template.json | 1 + .../integ.application.js.snapshot/manifest.json | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts index 4df50a9468d7d..6cc6e7a2c9f1c 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts @@ -34,12 +34,6 @@ export interface IApplication extends cdk.IResource { */ readonly applicationName?: string; - /** - * Application manager URL for the Application. - * @attribute - */ - readonly applicationManagerUrl?: cdk.CfnOutput; - /** * Associate this application with an attribute group. * @@ -100,7 +94,6 @@ abstract class ApplicationBase extends cdk.Resource implements IApplication { public abstract readonly applicationArn: string; public abstract readonly applicationId: string; public abstract readonly applicationName?: string; - public abstract readonly applicationManagerUrl?: cdk.CfnOutput; private readonly associatedAttributeGroups: Set = new Set(); private readonly associatedResources: Set = new Set(); @@ -253,7 +246,6 @@ export class Application extends ApplicationBase { public readonly applicationArn = applicationArn; public readonly applicationId = applicationId!; public readonly applicationName = undefined; - public readonly applicationManagerUrl = undefined; protected generateUniqueHash(resourceAddress: string): string { return hashValues(this.applicationArn, resourceAddress); @@ -265,10 +257,14 @@ export class Application extends ApplicationBase { }); } + /** + * Application manager URL for the Application. + * @attribute + */ + public readonly applicationManagerUrl?: cdk.CfnOutput; public readonly applicationArn: string; public readonly applicationId: string; public readonly applicationName?: string; - public readonly applicationManagerUrl?: cdk.CfnOutput; private readonly nodeAddress: string; constructor(scope: Construct, id: string, props: ApplicationProps) { @@ -288,6 +284,7 @@ export class Application extends ApplicationBase { this.applicationManagerUrl = new cdk.CfnOutput(this, 'ApplicationManagerUrl', { value: `https://${this.env.region}.console.aws.amazon.com/systems-manager/appmanager/application/AWS_AppRegistry_Application-${this.applicationName}`, + description: `Application manager url for application ${this.applicationName}`, }); } diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.assets.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.assets.json index 34ea8da07b973..225ef80716295 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.assets.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.assets.json @@ -1,7 +1,7 @@ { "version": "22.0.0", "files": { - "98d56556ece0e12b5e819d33e303424de1f579cdc95dd798bb2ee407ab2bda89": { + "806ae543572346400832fe865c1bdfa243ef2c1f07c3ce10aa0bd27ed4613a42": { "source": { "path": "integ-servicecatalogappregistry-application.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "98d56556ece0e12b5e819d33e303424de1f579cdc95dd798bb2ee407ab2bda89.json", + "objectKey": "806ae543572346400832fe865c1bdfa243ef2c1f07c3ce10aa0bd27ed4613a42.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.template.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.template.json index 7bb4697945693..33f4f2a1912fb 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.template.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.template.json @@ -123,6 +123,7 @@ }, "Outputs": { "TestApplicationApplicationManagerUrlE1058321": { + "Description": "Application manager url for application myCdkApplication", "Value": { "Fn::Join": [ "", diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/manifest.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/manifest.json index a60c47b72662f..a8cd9a83688d7 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/manifest.json @@ -17,7 +17,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/98d56556ece0e12b5e819d33e303424de1f579cdc95dd798bb2ee407ab2bda89.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/806ae543572346400832fe865c1bdfa243ef2c1f07c3ce10aa0bd27ed4613a42.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ From 72a2683c91b4ac91487ab5523e7f97104308d7b3 Mon Sep 17 00:00:00 2001 From: Santanu Ghosh Date: Tue, 13 Dec 2022 10:03:24 -0800 Subject: [PATCH 4/4] Removing un-necessary condition from resource association --- .../lib/application.ts | 15 ++++----------- .../test/application.test.ts | 1 - 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts index 6cc6e7a2c9f1c..ee0465eae5d12 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts @@ -138,22 +138,15 @@ abstract class ApplicationBase extends cdk.Resource implements IApplication { */ public associateApplicationWithStack(stack: cdk.Stack): void { if (!this.associatedResources.has(stack.node.addr)) { - const stackCondition = stack.nestedStackResource?.cfnOptions.condition; - const association = new CfnResourceAssociation(stack, 'AppRegistryAssociation', { + new CfnResourceAssociation(stack, 'AppRegistryAssociation', { application: stack === cdk.Stack.of(this) ? this.applicationId : this.applicationName ?? this.applicationId, resource: stack.stackId, resourceType: 'CFN_STACK', }); - if (stackCondition) { - association.addOverride('Condition', stackCondition.logicalId); - } - - if (!stack.nested) { - this.associatedResources.add(stack.node.addr); - if (stack !== cdk.Stack.of(this) && this.isSameAccount(stack) && !this.isStageScope(stack)) { - stack.addDependency(cdk.Stack.of(this)); - } + this.associatedResources.add(stack.node.addr); + if (stack !== cdk.Stack.of(this) && this.isSameAccount(stack) && !this.isStageScope(stack) && !stack.nested) { + stack.addDependency(cdk.Stack.of(this)); } } } diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/application.test.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application.test.ts index 8783de5605e4a..7a14cda920d28 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/application.test.ts +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application.test.ts @@ -471,7 +471,6 @@ describe('Conditional nested stack Associations with Application within Same Acc Resource: { Ref: 'AWS::StackId' }, ResourceType: 'CFN_STACK', }, - Condition: 'ShouldCreateStackCondition', }); Template.fromStack(stack.nestedStack).hasCondition('ShouldCreateStackCondition', { 'Fn::Equals': ['us-east-1'],