diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/attribute-group.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/attribute-group.ts index 52681adc08371..fed45f31099e9 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/attribute-group.ts +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/attribute-group.ts @@ -32,6 +32,12 @@ export interface IAttributeGroup extends cdk.IResource { * @param shareOptions The options for the share. */ shareAttributeGroup(id: string, shareOptions: ShareOptions): void; + + /** + * Associate an application with attribute group + * If the attribute group is already associated, it will ignore duplicate request. + */ + associateWith(application: IApplication): void; } /** @@ -61,10 +67,6 @@ abstract class AttributeGroupBase extends cdk.Resource implements IAttributeGrou public abstract readonly attributeGroupId: string; private readonly associatedApplications: Set = new Set(); - /** - * Associate an application with attribute group - * If the attribute group is already associated, it will ignore duplicate request. - */ public associateWith(application: IApplication): void { if (!this.associatedApplications.has(application.node.addr)) { const hashId = this.generateUniqueHash(application.node.addr); diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/attribute-group.test.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/test/attribute-group.test.ts index fcee2de79ac16..f8fbf6fa5e2d7 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/attribute-group.test.ts +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/attribute-group.test.ts @@ -78,6 +78,20 @@ describe('Attribute Group', () => { expect(attributeGroup.attributeGroupId).toEqual('0aqmvxvgmry0ecc4mjhwypun6i'); }), + test('Associate an application to an imported attribute group', () => { + const attributeGroup = appreg.AttributeGroup.fromAttributeGroupArn(stack, 'MyAttributeGroup', + 'arn:aws:servicecatalog:us-east-1:123456789012:/attribute-groups/0aqmvxvgmry0ecc4mjhwypun6i'); + const application = new appreg.Application(stack, 'MyApplication', { + applicationName: 'MyTestApplication', + }); + attributeGroup.associateWith(application); + Template.fromStack(stack).hasResourceProperties('AWS::ServiceCatalogAppRegistry::AttributeGroupAssociation', { + Application: { 'Fn::GetAtt': ['MyApplication5C63EC1D', 'Id'] }, + AttributeGroup: '0aqmvxvgmry0ecc4mjhwypun6i', + }); + + }); + test('fails for attribute group imported by ARN missing attributeGroupId', () => { expect(() => { appreg.AttributeGroup.fromAttributeGroupArn(stack, 'MyAttributeGroup', diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.attribute-group.js.snapshot/integ-servicecatalogappregistry-attribute-group.assets.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.attribute-group.js.snapshot/integ-servicecatalogappregistry-attribute-group.assets.json index 9fa752fb4f3db..8459879835210 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.attribute-group.js.snapshot/integ-servicecatalogappregistry-attribute-group.assets.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.attribute-group.js.snapshot/integ-servicecatalogappregistry-attribute-group.assets.json @@ -1,7 +1,7 @@ { "version": "31.0.0", "files": { - "82d95f02f48b1a318e263f9ed8a8bffdeb427088f26115168bac269d7c1d92fb": { + "9dae111f7879c2c97f5b16fbc40629d676f0cf7d329d77da3a5bb25ece0faabd": { "source": { "path": "integ-servicecatalogappregistry-attribute-group.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "82d95f02f48b1a318e263f9ed8a8bffdeb427088f26115168bac269d7c1d92fb.json", + "objectKey": "9dae111f7879c2c97f5b16fbc40629d676f0cf7d329d77da3a5bb25ece0faabd.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.attribute-group.js.snapshot/integ-servicecatalogappregistry-attribute-group.template.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.attribute-group.js.snapshot/integ-servicecatalogappregistry-attribute-group.template.json index 5c2c3820801b4..7bf1aa632b7d5 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.attribute-group.js.snapshot/integ-servicecatalogappregistry-attribute-group.template.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.attribute-group.js.snapshot/integ-servicecatalogappregistry-attribute-group.template.json @@ -1,5 +1,12 @@ { "Resources": { + "TestApplication2FBC585F": { + "Type": "AWS::ServiceCatalogAppRegistry::Application", + "Properties": { + "Name": "TestApplication", + "Description": "My application description" + } + }, "TestAttributeGroupB1CB284F": { "Type": "AWS::ServiceCatalogAppRegistry::AttributeGroup", "Properties": { @@ -19,6 +26,23 @@ "Description": "test attribute group description" } }, + "TestAttributeGroupApplicationAttributeGroupAssociation73d834483ae31BB2BA9A": { + "Type": "AWS::ServiceCatalogAppRegistry::AttributeGroupAssociation", + "Properties": { + "Application": { + "Fn::GetAtt": [ + "TestApplication2FBC585F", + "Id" + ] + }, + "AttributeGroup": { + "Fn::GetAtt": [ + "TestAttributeGroupB1CB284F", + "Id" + ] + } + } + }, "TestAttributeGroupMyShareIdBAA9E628": { "Type": "AWS::RAM::ResourceShare", "Properties": { diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.attribute-group.js.snapshot/manifest.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.attribute-group.js.snapshot/manifest.json index 1a9a3f87dffe4..a5fde03634890 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.attribute-group.js.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.attribute-group.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}/82d95f02f48b1a318e263f9ed8a8bffdeb427088f26115168bac269d7c1d92fb.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/9dae111f7879c2c97f5b16fbc40629d676f0cf7d329d77da3a5bb25ece0faabd.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -33,12 +33,24 @@ "integ-servicecatalogappregistry-attribute-group.assets" ], "metadata": { + "/integ-servicecatalogappregistry-attribute-group/TestApplication/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "TestApplication2FBC585F" + } + ], "/integ-servicecatalogappregistry-attribute-group/TestAttributeGroup/Resource": [ { "type": "aws:cdk:logicalId", "data": "TestAttributeGroupB1CB284F" } ], + "/integ-servicecatalogappregistry-attribute-group/TestAttributeGroup/ApplicationAttributeGroupAssociation73d834483ae3": [ + { + "type": "aws:cdk:logicalId", + "data": "TestAttributeGroupApplicationAttributeGroupAssociation73d834483ae31BB2BA9A" + } + ], "/integ-servicecatalogappregistry-attribute-group/TestAttributeGroup/MyShareId": [ { "type": "aws:cdk:logicalId", @@ -68,15 +80,6 @@ "type": "aws:cdk:logicalId", "data": "CheckBootstrapVersion" } - ], - "TestAttributeGroupRAMSharec67f7d80e5baA10EFB4E": [ - { - "type": "aws:cdk:logicalId", - "data": "TestAttributeGroupRAMSharec67f7d80e5baA10EFB4E", - "trace": [ - "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" - ] - } ] }, "displayName": "integ-servicecatalogappregistry-attribute-group" diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.attribute-group.js.snapshot/tree.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.attribute-group.js.snapshot/tree.json index d1527c3a7be67..d0e264b6441b9 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.attribute-group.js.snapshot/tree.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.attribute-group.js.snapshot/tree.json @@ -8,6 +8,31 @@ "id": "integ-servicecatalogappregistry-attribute-group", "path": "integ-servicecatalogappregistry-attribute-group", "children": { + "TestApplication": { + "id": "TestApplication", + "path": "integ-servicecatalogappregistry-attribute-group/TestApplication", + "children": { + "Resource": { + "id": "Resource", + "path": "integ-servicecatalogappregistry-attribute-group/TestApplication/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ServiceCatalogAppRegistry::Application", + "aws:cdk:cloudformation:props": { + "name": "TestApplication", + "description": "My application description" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_servicecatalogappregistry.CfnApplication", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-servicecatalogappregistry-alpha.Application", + "version": "0.0.0" + } + }, "TestAttributeGroup": { "id": "TestAttributeGroup", "path": "integ-servicecatalogappregistry-attribute-group/TestAttributeGroup", @@ -35,7 +60,32 @@ } }, "constructInfo": { - "fqn": "@aws-cdk/aws-servicecatalogappregistry.CfnAttributeGroup", + "fqn": "aws-cdk-lib.aws_servicecatalogappregistry.CfnAttributeGroup", + "version": "0.0.0" + } + }, + "ApplicationAttributeGroupAssociation73d834483ae3": { + "id": "ApplicationAttributeGroupAssociation73d834483ae3", + "path": "integ-servicecatalogappregistry-attribute-group/TestAttributeGroup/ApplicationAttributeGroupAssociation73d834483ae3", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ServiceCatalogAppRegistry::AttributeGroupAssociation", + "aws:cdk:cloudformation:props": { + "application": { + "Fn::GetAtt": [ + "TestApplication2FBC585F", + "Id" + ] + }, + "attributeGroup": { + "Fn::GetAtt": [ + "TestAttributeGroupB1CB284F", + "Id" + ] + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_servicecatalogappregistry.CfnAttributeGroupAssociation", "version": "0.0.0" } }, @@ -75,13 +125,13 @@ } }, "constructInfo": { - "fqn": "@aws-cdk/aws-ram.CfnResourceShare", + "fqn": "aws-cdk-lib.aws_ram.CfnResourceShare", "version": "0.0.0" } } }, "constructInfo": { - "fqn": "@aws-cdk/aws-servicecatalogappregistry.AttributeGroup", + "fqn": "@aws-cdk/aws-servicecatalogappregistry-alpha.AttributeGroup", "version": "0.0.0" } }, @@ -93,7 +143,7 @@ "id": "ImportMyRole", "path": "integ-servicecatalogappregistry-attribute-group/MyRole/ImportMyRole", "constructInfo": { - "fqn": "@aws-cdk/core.Resource", + "fqn": "aws-cdk-lib.Resource", "version": "0.0.0" } }, @@ -133,13 +183,13 @@ } }, "constructInfo": { - "fqn": "@aws-cdk/aws-iam.CfnRole", + "fqn": "aws-cdk-lib.aws_iam.CfnRole", "version": "0.0.0" } } }, "constructInfo": { - "fqn": "@aws-cdk/aws-iam.Role", + "fqn": "aws-cdk-lib.aws_iam.Role", "version": "0.0.0" } }, @@ -151,7 +201,7 @@ "id": "ImportMySecondRole", "path": "integ-servicecatalogappregistry-attribute-group/MySecondRole/ImportMySecondRole", "constructInfo": { - "fqn": "@aws-cdk/core.Resource", + "fqn": "aws-cdk-lib.Resource", "version": "0.0.0" } }, @@ -191,13 +241,13 @@ } }, "constructInfo": { - "fqn": "@aws-cdk/aws-iam.CfnRole", + "fqn": "aws-cdk-lib.aws_iam.CfnRole", "version": "0.0.0" } } }, "constructInfo": { - "fqn": "@aws-cdk/aws-iam.Role", + "fqn": "aws-cdk-lib.aws_iam.Role", "version": "0.0.0" } }, @@ -205,7 +255,7 @@ "id": "BootstrapVersion", "path": "integ-servicecatalogappregistry-attribute-group/BootstrapVersion", "constructInfo": { - "fqn": "@aws-cdk/core.CfnParameter", + "fqn": "aws-cdk-lib.CfnParameter", "version": "0.0.0" } }, @@ -213,13 +263,13 @@ "id": "CheckBootstrapVersion", "path": "integ-servicecatalogappregistry-attribute-group/CheckBootstrapVersion", "constructInfo": { - "fqn": "@aws-cdk/core.CfnRule", + "fqn": "aws-cdk-lib.CfnRule", "version": "0.0.0" } } }, "constructInfo": { - "fqn": "@aws-cdk/core.Stack", + "fqn": "aws-cdk-lib.Stack", "version": "0.0.0" } }, @@ -233,7 +283,7 @@ } }, "constructInfo": { - "fqn": "@aws-cdk/core.App", + "fqn": "aws-cdk-lib.App", "version": "0.0.0" } } diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.attribute-group.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.attribute-group.ts index c17d21a7a4a8c..b8c2ee86a568f 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.attribute-group.ts +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.attribute-group.ts @@ -5,6 +5,11 @@ import * as appreg from '../lib'; const app = new cdk.App(); const stack = new cdk.Stack(app, 'integ-servicecatalogappregistry-attribute-group'); +const application = new appreg.Application(stack, 'TestApplication', { + applicationName: 'TestApplication', + description: 'My application description', +}); + const attributeGroup = new appreg.AttributeGroup(stack, 'TestAttributeGroup', { attributeGroupName: 'myFirstAttributeGroup', description: 'test attribute group description', @@ -21,6 +26,9 @@ const attributeGroup = new appreg.AttributeGroup(stack, 'TestAttributeGroup', { }, }, }); + +attributeGroup.associateWith(application); + const myRole = new iam.Role(stack, 'MyRole', { assumedBy: new iam.AccountPrincipal(stack.account), });