Skip to content

Commit 4c2e7d6

Browse files
fix(servicecatalogappregistry): Imported attribute group cannot be associated to an application (#24960)
`associateWith` was not in `IAttributeGroup` interface. This makes `AttributeGroup.fromAttributeGroupArn()` couldn't use `associateWith` method. This commit moves `associateWith` to`IAttributeGroup` interface, so that imported attribute group can use `associateWith` to an application. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 55906bb commit 4c2e7d6

File tree

7 files changed

+130
-29
lines changed

7 files changed

+130
-29
lines changed

packages/@aws-cdk/aws-servicecatalogappregistry/lib/attribute-group.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ export interface IAttributeGroup extends cdk.IResource {
3232
* @param shareOptions The options for the share.
3333
*/
3434
shareAttributeGroup(id: string, shareOptions: ShareOptions): void;
35+
36+
/**
37+
* Associate an application with attribute group
38+
* If the attribute group is already associated, it will ignore duplicate request.
39+
*/
40+
associateWith(application: IApplication): void;
3541
}
3642

3743
/**
@@ -61,10 +67,6 @@ abstract class AttributeGroupBase extends cdk.Resource implements IAttributeGrou
6167
public abstract readonly attributeGroupId: string;
6268
private readonly associatedApplications: Set<string> = new Set();
6369

64-
/**
65-
* Associate an application with attribute group
66-
* If the attribute group is already associated, it will ignore duplicate request.
67-
*/
6870
public associateWith(application: IApplication): void {
6971
if (!this.associatedApplications.has(application.node.addr)) {
7072
const hashId = this.generateUniqueHash(application.node.addr);

packages/@aws-cdk/aws-servicecatalogappregistry/test/attribute-group.test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@ describe('Attribute Group', () => {
7878
expect(attributeGroup.attributeGroupId).toEqual('0aqmvxvgmry0ecc4mjhwypun6i');
7979
}),
8080

81+
test('Associate an application to an imported attribute group', () => {
82+
const attributeGroup = appreg.AttributeGroup.fromAttributeGroupArn(stack, 'MyAttributeGroup',
83+
'arn:aws:servicecatalog:us-east-1:123456789012:/attribute-groups/0aqmvxvgmry0ecc4mjhwypun6i');
84+
const application = new appreg.Application(stack, 'MyApplication', {
85+
applicationName: 'MyTestApplication',
86+
});
87+
attributeGroup.associateWith(application);
88+
Template.fromStack(stack).hasResourceProperties('AWS::ServiceCatalogAppRegistry::AttributeGroupAssociation', {
89+
Application: { 'Fn::GetAtt': ['MyApplication5C63EC1D', 'Id'] },
90+
AttributeGroup: '0aqmvxvgmry0ecc4mjhwypun6i',
91+
});
92+
93+
});
94+
8195
test('fails for attribute group imported by ARN missing attributeGroupId', () => {
8296
expect(() => {
8397
appreg.AttributeGroup.fromAttributeGroupArn(stack, 'MyAttributeGroup',

packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.attribute-group.js.snapshot/integ-servicecatalogappregistry-attribute-group.assets.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"version": "31.0.0",
33
"files": {
4-
"82d95f02f48b1a318e263f9ed8a8bffdeb427088f26115168bac269d7c1d92fb": {
4+
"9dae111f7879c2c97f5b16fbc40629d676f0cf7d329d77da3a5bb25ece0faabd": {
55
"source": {
66
"path": "integ-servicecatalogappregistry-attribute-group.template.json",
77
"packaging": "file"
88
},
99
"destinations": {
1010
"current_account-current_region": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12-
"objectKey": "82d95f02f48b1a318e263f9ed8a8bffdeb427088f26115168bac269d7c1d92fb.json",
12+
"objectKey": "9dae111f7879c2c97f5b16fbc40629d676f0cf7d329d77da3a5bb25ece0faabd.json",
1313
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
1414
}
1515
}

packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.attribute-group.js.snapshot/integ-servicecatalogappregistry-attribute-group.template.json

+24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
{
22
"Resources": {
3+
"TestApplication2FBC585F": {
4+
"Type": "AWS::ServiceCatalogAppRegistry::Application",
5+
"Properties": {
6+
"Name": "TestApplication",
7+
"Description": "My application description"
8+
}
9+
},
310
"TestAttributeGroupB1CB284F": {
411
"Type": "AWS::ServiceCatalogAppRegistry::AttributeGroup",
512
"Properties": {
@@ -19,6 +26,23 @@
1926
"Description": "test attribute group description"
2027
}
2128
},
29+
"TestAttributeGroupApplicationAttributeGroupAssociation73d834483ae31BB2BA9A": {
30+
"Type": "AWS::ServiceCatalogAppRegistry::AttributeGroupAssociation",
31+
"Properties": {
32+
"Application": {
33+
"Fn::GetAtt": [
34+
"TestApplication2FBC585F",
35+
"Id"
36+
]
37+
},
38+
"AttributeGroup": {
39+
"Fn::GetAtt": [
40+
"TestAttributeGroupB1CB284F",
41+
"Id"
42+
]
43+
}
44+
}
45+
},
2246
"TestAttributeGroupMyShareIdBAA9E628": {
2347
"Type": "AWS::RAM::ResourceShare",
2448
"Properties": {

packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.attribute-group.js.snapshot/manifest.json

+13-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"validateOnSynth": false,
1818
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
1919
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
20-
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/82d95f02f48b1a318e263f9ed8a8bffdeb427088f26115168bac269d7c1d92fb.json",
20+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/9dae111f7879c2c97f5b16fbc40629d676f0cf7d329d77da3a5bb25ece0faabd.json",
2121
"requiresBootstrapStackVersion": 6,
2222
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
2323
"additionalDependencies": [
@@ -33,12 +33,24 @@
3333
"integ-servicecatalogappregistry-attribute-group.assets"
3434
],
3535
"metadata": {
36+
"/integ-servicecatalogappregistry-attribute-group/TestApplication/Resource": [
37+
{
38+
"type": "aws:cdk:logicalId",
39+
"data": "TestApplication2FBC585F"
40+
}
41+
],
3642
"/integ-servicecatalogappregistry-attribute-group/TestAttributeGroup/Resource": [
3743
{
3844
"type": "aws:cdk:logicalId",
3945
"data": "TestAttributeGroupB1CB284F"
4046
}
4147
],
48+
"/integ-servicecatalogappregistry-attribute-group/TestAttributeGroup/ApplicationAttributeGroupAssociation73d834483ae3": [
49+
{
50+
"type": "aws:cdk:logicalId",
51+
"data": "TestAttributeGroupApplicationAttributeGroupAssociation73d834483ae31BB2BA9A"
52+
}
53+
],
4254
"/integ-servicecatalogappregistry-attribute-group/TestAttributeGroup/MyShareId": [
4355
{
4456
"type": "aws:cdk:logicalId",
@@ -68,15 +80,6 @@
6880
"type": "aws:cdk:logicalId",
6981
"data": "CheckBootstrapVersion"
7082
}
71-
],
72-
"TestAttributeGroupRAMSharec67f7d80e5baA10EFB4E": [
73-
{
74-
"type": "aws:cdk:logicalId",
75-
"data": "TestAttributeGroupRAMSharec67f7d80e5baA10EFB4E",
76-
"trace": [
77-
"!!DESTRUCTIVE_CHANGES: WILL_DESTROY"
78-
]
79-
}
8083
]
8184
},
8285
"displayName": "integ-servicecatalogappregistry-attribute-group"

packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.attribute-group.js.snapshot/tree.json

+63-13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,31 @@
88
"id": "integ-servicecatalogappregistry-attribute-group",
99
"path": "integ-servicecatalogappregistry-attribute-group",
1010
"children": {
11+
"TestApplication": {
12+
"id": "TestApplication",
13+
"path": "integ-servicecatalogappregistry-attribute-group/TestApplication",
14+
"children": {
15+
"Resource": {
16+
"id": "Resource",
17+
"path": "integ-servicecatalogappregistry-attribute-group/TestApplication/Resource",
18+
"attributes": {
19+
"aws:cdk:cloudformation:type": "AWS::ServiceCatalogAppRegistry::Application",
20+
"aws:cdk:cloudformation:props": {
21+
"name": "TestApplication",
22+
"description": "My application description"
23+
}
24+
},
25+
"constructInfo": {
26+
"fqn": "aws-cdk-lib.aws_servicecatalogappregistry.CfnApplication",
27+
"version": "0.0.0"
28+
}
29+
}
30+
},
31+
"constructInfo": {
32+
"fqn": "@aws-cdk/aws-servicecatalogappregistry-alpha.Application",
33+
"version": "0.0.0"
34+
}
35+
},
1136
"TestAttributeGroup": {
1237
"id": "TestAttributeGroup",
1338
"path": "integ-servicecatalogappregistry-attribute-group/TestAttributeGroup",
@@ -35,7 +60,32 @@
3560
}
3661
},
3762
"constructInfo": {
38-
"fqn": "@aws-cdk/aws-servicecatalogappregistry.CfnAttributeGroup",
63+
"fqn": "aws-cdk-lib.aws_servicecatalogappregistry.CfnAttributeGroup",
64+
"version": "0.0.0"
65+
}
66+
},
67+
"ApplicationAttributeGroupAssociation73d834483ae3": {
68+
"id": "ApplicationAttributeGroupAssociation73d834483ae3",
69+
"path": "integ-servicecatalogappregistry-attribute-group/TestAttributeGroup/ApplicationAttributeGroupAssociation73d834483ae3",
70+
"attributes": {
71+
"aws:cdk:cloudformation:type": "AWS::ServiceCatalogAppRegistry::AttributeGroupAssociation",
72+
"aws:cdk:cloudformation:props": {
73+
"application": {
74+
"Fn::GetAtt": [
75+
"TestApplication2FBC585F",
76+
"Id"
77+
]
78+
},
79+
"attributeGroup": {
80+
"Fn::GetAtt": [
81+
"TestAttributeGroupB1CB284F",
82+
"Id"
83+
]
84+
}
85+
}
86+
},
87+
"constructInfo": {
88+
"fqn": "aws-cdk-lib.aws_servicecatalogappregistry.CfnAttributeGroupAssociation",
3989
"version": "0.0.0"
4090
}
4191
},
@@ -75,13 +125,13 @@
75125
}
76126
},
77127
"constructInfo": {
78-
"fqn": "@aws-cdk/aws-ram.CfnResourceShare",
128+
"fqn": "aws-cdk-lib.aws_ram.CfnResourceShare",
79129
"version": "0.0.0"
80130
}
81131
}
82132
},
83133
"constructInfo": {
84-
"fqn": "@aws-cdk/aws-servicecatalogappregistry.AttributeGroup",
134+
"fqn": "@aws-cdk/aws-servicecatalogappregistry-alpha.AttributeGroup",
85135
"version": "0.0.0"
86136
}
87137
},
@@ -93,7 +143,7 @@
93143
"id": "ImportMyRole",
94144
"path": "integ-servicecatalogappregistry-attribute-group/MyRole/ImportMyRole",
95145
"constructInfo": {
96-
"fqn": "@aws-cdk/core.Resource",
146+
"fqn": "aws-cdk-lib.Resource",
97147
"version": "0.0.0"
98148
}
99149
},
@@ -133,13 +183,13 @@
133183
}
134184
},
135185
"constructInfo": {
136-
"fqn": "@aws-cdk/aws-iam.CfnRole",
186+
"fqn": "aws-cdk-lib.aws_iam.CfnRole",
137187
"version": "0.0.0"
138188
}
139189
}
140190
},
141191
"constructInfo": {
142-
"fqn": "@aws-cdk/aws-iam.Role",
192+
"fqn": "aws-cdk-lib.aws_iam.Role",
143193
"version": "0.0.0"
144194
}
145195
},
@@ -151,7 +201,7 @@
151201
"id": "ImportMySecondRole",
152202
"path": "integ-servicecatalogappregistry-attribute-group/MySecondRole/ImportMySecondRole",
153203
"constructInfo": {
154-
"fqn": "@aws-cdk/core.Resource",
204+
"fqn": "aws-cdk-lib.Resource",
155205
"version": "0.0.0"
156206
}
157207
},
@@ -191,35 +241,35 @@
191241
}
192242
},
193243
"constructInfo": {
194-
"fqn": "@aws-cdk/aws-iam.CfnRole",
244+
"fqn": "aws-cdk-lib.aws_iam.CfnRole",
195245
"version": "0.0.0"
196246
}
197247
}
198248
},
199249
"constructInfo": {
200-
"fqn": "@aws-cdk/aws-iam.Role",
250+
"fqn": "aws-cdk-lib.aws_iam.Role",
201251
"version": "0.0.0"
202252
}
203253
},
204254
"BootstrapVersion": {
205255
"id": "BootstrapVersion",
206256
"path": "integ-servicecatalogappregistry-attribute-group/BootstrapVersion",
207257
"constructInfo": {
208-
"fqn": "@aws-cdk/core.CfnParameter",
258+
"fqn": "aws-cdk-lib.CfnParameter",
209259
"version": "0.0.0"
210260
}
211261
},
212262
"CheckBootstrapVersion": {
213263
"id": "CheckBootstrapVersion",
214264
"path": "integ-servicecatalogappregistry-attribute-group/CheckBootstrapVersion",
215265
"constructInfo": {
216-
"fqn": "@aws-cdk/core.CfnRule",
266+
"fqn": "aws-cdk-lib.CfnRule",
217267
"version": "0.0.0"
218268
}
219269
}
220270
},
221271
"constructInfo": {
222-
"fqn": "@aws-cdk/core.Stack",
272+
"fqn": "aws-cdk-lib.Stack",
223273
"version": "0.0.0"
224274
}
225275
},
@@ -233,7 +283,7 @@
233283
}
234284
},
235285
"constructInfo": {
236-
"fqn": "@aws-cdk/core.App",
286+
"fqn": "aws-cdk-lib.App",
237287
"version": "0.0.0"
238288
}
239289
}

packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.attribute-group.ts

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import * as appreg from '../lib';
55
const app = new cdk.App();
66
const stack = new cdk.Stack(app, 'integ-servicecatalogappregistry-attribute-group');
77

8+
const application = new appreg.Application(stack, 'TestApplication', {
9+
applicationName: 'TestApplication',
10+
description: 'My application description',
11+
});
12+
813
const attributeGroup = new appreg.AttributeGroup(stack, 'TestAttributeGroup', {
914
attributeGroupName: 'myFirstAttributeGroup',
1015
description: 'test attribute group description',
@@ -21,6 +26,9 @@ const attributeGroup = new appreg.AttributeGroup(stack, 'TestAttributeGroup', {
2126
},
2227
},
2328
});
29+
30+
attributeGroup.associateWith(application);
31+
2432
const myRole = new iam.Role(stack, 'MyRole', {
2533
assumedBy: new iam.AccountPrincipal(stack.account),
2634
});

0 commit comments

Comments
 (0)