Skip to content

Commit b20b1f2

Browse files
fix(servicecatalogappregistry): Revert deprecated method removing PR to keep deprecated method in alpha version (#25454)
Revert PR of deprecating method AssociateAttributeGroup and AssociateStack since we would like to allow our v1 customer to continue to use deprecated method in v2 alpha version to offer them more time to switch to stable version. **We will remove these deprecated method in stable version** This reverts commit [9222f21.](9222f21) **Here is some context about this change:** Recently, we found that we do not mark these two methods as deprecated in v1 cdk. Also, we cannot update v1 cdk now to send deprecation notification to them. Thus, v1 customer cannot receive any notification for the methods’ deprecation forever. Therefore, if we directly remove these methods in v2, then v1 customers have to update their code to depreciate these two methods. We think that this migration’s customer experience is not good. In order to offer a better customer experience to customers, we decide to keep deprecated method in alpha version. Thus, if v1 customs do not want to update their code to deprecate the methods when they want to migrate to v2, they can use our v2 alpha version temporarily Also, there are some customer are still using these deprecated methods in alpha version, and we do not want to break their customer experience. They can update their code when they are moving to v2-stable version ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 4d23801 commit b20b1f2

File tree

7 files changed

+338
-16
lines changed

7 files changed

+338
-16
lines changed

packages/@aws-cdk/aws-servicecatalogappregistry-alpha/lib/application.ts

+52
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,29 @@ export interface IApplication extends cdk.IResource {
5656
*/
5757
readonly applicationName?: string;
5858

59+
/**
60+
* Associate this application with an attribute group.
61+
*
62+
* @param attributeGroup AppRegistry attribute group
63+
*/
64+
associateAttributeGroup(attributeGroup: IAttributeGroup): void;
65+
5966
/**
6067
* Create an attribute group and associate this application with the created attribute group.
6168
*
6269
* @param id name of the AttributeGroup construct to be created.
6370
* @param attributeGroupProps AppRegistry attribute group props
6471
*/
6572
addAttributeGroup(id: string, attributeGroupProps: AttributeGroupAssociationProps): IAttributeGroup;
73+
74+
/**
75+
* Associate this application with a CloudFormation stack.
76+
*
77+
* @deprecated Use `associateApplicationWithStack` instead.
78+
* @param stack a CFN stack
79+
*/
80+
associateStack(stack: cdk.Stack): void;
81+
6682
/**
6783
* Associate a Cloudformation statck with the application in the given stack.
6884
*
@@ -112,6 +128,23 @@ abstract class ApplicationBase extends cdk.Resource implements IApplication {
112128
private readonly associatedAttributeGroups: Set<string> = new Set();
113129
private readonly associatedResources: Set<string> = new Set();
114130

131+
/**
132+
* Associate an attribute group with application
133+
* If the attribute group is already associated, it will ignore duplicate request.
134+
*
135+
* @deprecated Use `AttributeGroup.associateWith` instead.
136+
*/
137+
public associateAttributeGroup(attributeGroup: IAttributeGroup): void {
138+
if (!this.associatedAttributeGroups.has(attributeGroup.node.addr)) {
139+
const hashId = this.generateUniqueHash(attributeGroup.node.addr);
140+
new CfnAttributeGroupAssociation(this, `AttributeGroupAssociation${hashId}`, {
141+
application: this.applicationId,
142+
attributeGroup: attributeGroup.attributeGroupId,
143+
});
144+
this.associatedAttributeGroups.add(attributeGroup.node.addr);
145+
}
146+
}
147+
115148
/**
116149
* Create an attribute group and associate this application with the created attribute group.
117150
*/
@@ -129,6 +162,25 @@ abstract class ApplicationBase extends cdk.Resource implements IApplication {
129162
return attributeGroup;
130163
}
131164

165+
/**
166+
* Associate a stack with the application
167+
* If the resource is already associated, it will ignore duplicate request.
168+
* A stack can only be associated with one application.
169+
*
170+
* @deprecated Use `associateApplicationWithStack` instead.
171+
*/
172+
public associateStack(stack: cdk.Stack): void {
173+
if (!this.associatedResources.has(stack.node.addr)) {
174+
const hashId = this.generateUniqueHash(stack.node.addr);
175+
new CfnResourceAssociation(this, `ResourceAssociation${hashId}`, {
176+
application: this.applicationId,
177+
resource: stack.stackId,
178+
resourceType: 'CFN_STACK',
179+
});
180+
this.associatedResources.add(stack.node.addr);
181+
}
182+
}
183+
132184
/**
133185
* Associate stack with the application in the stack passed as parameter.
134186
*

packages/@aws-cdk/aws-servicecatalogappregistry-alpha/test/application.test.ts

+86
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,20 @@ describe('Application', () => {
146146
});
147147
});
148148

149+
test('associate attribute group', () => {
150+
const attributeGroup = new appreg.AttributeGroup(stack, 'AttributeGroup', {
151+
attributeGroupName: 'AttributeGroupName',
152+
attributes: {},
153+
});
154+
155+
application.associateAttributeGroup(attributeGroup);
156+
157+
Template.fromStack(stack).hasResourceProperties('AWS::ServiceCatalogAppRegistry::AttributeGroupAssociation', {
158+
Application: { 'Fn::GetAtt': ['MyApplication5C63EC1D', 'Id'] },
159+
AttributeGroup: { 'Fn::GetAtt': ['AttributeGroup409C6335', 'Id'] },
160+
});
161+
}),
162+
149163
test('associate new attribute group', () => {
150164
application.addAttributeGroup('AttributeGroup', {
151165
attributeGroupName: 'AttributeGroupName',
@@ -169,6 +183,78 @@ describe('Application', () => {
169183
},
170184
},
171185
});
186+
}),
187+
188+
test('duplicate attribute group association are idempotent', () => {
189+
const attributeGroup = new appreg.AttributeGroup(stack, 'AttributeGroup', {
190+
attributeGroupName: 'attributeGroupName',
191+
attributes: { key: 'value' },
192+
});
193+
194+
// If these were not idempotent, the second call would produce an error for duplicate construct ID.
195+
application.associateAttributeGroup(attributeGroup);
196+
application.associateAttributeGroup(attributeGroup);
197+
198+
Template.fromStack(stack).resourceCountIs('AWS::ServiceCatalogAppRegistry::AttributeGroupAssociation', 1);
199+
}),
200+
201+
test('multiple applications and attribute groups can associate', () => {
202+
const application2 = new appreg.Application(stack, 'MyApplication2', {
203+
applicationName: 'MyApplication2',
204+
});
205+
206+
const attributeGroup1 = new appreg.AttributeGroup(stack, 'AttributeGroup', {
207+
attributeGroupName: 'attributeGroupName',
208+
attributes: { key: 'value' },
209+
});
210+
211+
const attributeGroup2 = new appreg.AttributeGroup(stack, 'AttributeGroup2', {
212+
attributeGroupName: 'attributeGroupName2',
213+
attributes: { key: 'value' },
214+
});
215+
216+
application.associateAttributeGroup(attributeGroup1);
217+
application.associateAttributeGroup(attributeGroup2);
218+
219+
application2.associateAttributeGroup(attributeGroup1);
220+
application2.associateAttributeGroup(attributeGroup2);
221+
222+
Template.fromStack(stack).resourceCountIs('AWS::ServiceCatalogAppRegistry::AttributeGroupAssociation', 4);
223+
}),
224+
225+
test('associate resource', () => {
226+
const resource = new cdk.Stack(stack, 'MyStack');
227+
228+
application.associateStack(resource);
229+
230+
Template.fromStack(stack).hasResourceProperties('AWS::ServiceCatalogAppRegistry::ResourceAssociation', {
231+
Application: { 'Fn::GetAtt': ['MyApplication5C63EC1D', 'Id'] },
232+
Resource: { 'Fn::ImportValue': 'MyStack:ExportsOutputRefAWSStackIdB2DD5BAA' },
233+
});
234+
}),
235+
236+
test('associate resource on imported application', () => {
237+
const resource = new cdk.Stack(stack, 'MyStack');
238+
239+
const importedApplication = appreg.Application.fromApplicationArn(stack, 'ImportedApplication',
240+
'arn:aws:servicecatalog:us-east-1:123456789012:/applications/0bqmvxvgmry0ecc4mjhwypun6i');
241+
242+
importedApplication.associateStack(resource);
243+
244+
Template.fromStack(stack).hasResourceProperties('AWS::ServiceCatalogAppRegistry::ResourceAssociation', {
245+
Application: '0bqmvxvgmry0ecc4mjhwypun6i',
246+
Resource: { 'Fn::ImportValue': 'MyStack:ExportsOutputRefAWSStackIdB2DD5BAA' },
247+
});
248+
}),
249+
250+
test('duplicate resource assocations are idempotent', () => {
251+
const resource = new cdk.Stack(stack, 'MyStack');
252+
253+
// If these were not idempotent, the second call would produce an error for duplicate construct ID.
254+
application.associateStack(resource);
255+
application.associateStack(resource);
256+
257+
Template.fromStack(stack).resourceCountIs('AWS::ServiceCatalogAppRegistry::ResourceAssociation', 1);
172258
});
173259
});
174260

packages/@aws-cdk/aws-servicecatalogappregistry-alpha/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.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-
"f45a8edb41940665356c72f600a1955d3c2799708e54040592669f4fcaec6500": {
4+
"461d235e9497deb16b9209be4a927c7d0dc7aa06d668e38bfb19a90db8e4a4b2": {
55
"source": {
66
"path": "integ-servicecatalogappregistry-application.template.json",
77
"packaging": "file"
88
},
99
"destinations": {
1010
"current_account-current_region": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12-
"objectKey": "f45a8edb41940665356c72f600a1955d3c2799708e54040592669f4fcaec6500.json",
12+
"objectKey": "461d235e9497deb16b9209be4a927c7d0dc7aa06d668e38bfb19a90db8e4a4b2.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-alpha/test/integ.application.js.snapshot/integ-servicecatalogappregistry-application.template.json

+55
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,38 @@
77
"Description": "My application description"
88
}
99
},
10+
"TestApplicationResourceAssociationd232b63e52a8414E905D": {
11+
"Type": "AWS::ServiceCatalogAppRegistry::ResourceAssociation",
12+
"Properties": {
13+
"Application": {
14+
"Fn::GetAtt": [
15+
"TestApplication2FBC585F",
16+
"Id"
17+
]
18+
},
19+
"Resource": {
20+
"Ref": "AWS::StackId"
21+
},
22+
"ResourceType": "CFN_STACK"
23+
}
24+
},
25+
"TestApplicationAttributeGroupAssociation4ba7f5842818B8EE1C6F": {
26+
"Type": "AWS::ServiceCatalogAppRegistry::AttributeGroupAssociation",
27+
"Properties": {
28+
"Application": {
29+
"Fn::GetAtt": [
30+
"TestApplication2FBC585F",
31+
"Id"
32+
]
33+
},
34+
"AttributeGroup": {
35+
"Fn::GetAtt": [
36+
"TestAttributeGroupB1CB284F",
37+
"Id"
38+
]
39+
}
40+
}
41+
},
1042
"TestApplicationmyAnotherAttributeGroup375F79DB": {
1143
"Type": "AWS::ServiceCatalogAppRegistry::AttributeGroup",
1244
"Properties": {
@@ -84,6 +116,29 @@
84116
]
85117
}
86118
},
119+
"TestAttributeGroupB1CB284F": {
120+
"Type": "AWS::ServiceCatalogAppRegistry::AttributeGroup",
121+
"Properties": {
122+
"Attributes": {
123+
"stage": "alpha",
124+
"teamMembers": [
125+
"markI",
126+
"markII",
127+
"markIII"
128+
],
129+
"public": false,
130+
"publishYear": 2021,
131+
"plannedRoadMap": {
132+
"alpha": "some time",
133+
"beta": "another time",
134+
"gamma": "penultimate time",
135+
"release": "go time"
136+
}
137+
},
138+
"Name": "myAttributeGroup",
139+
"Description": "my attribute group description"
140+
}
141+
},
87142
"MyRoleF48FFE04": {
88143
"Type": "AWS::IAM::Role",
89144
"Properties": {

packages/@aws-cdk/aws-servicecatalogappregistry-alpha/test/integ.application.js.snapshot/manifest.json

+19-1
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}/f45a8edb41940665356c72f600a1955d3c2799708e54040592669f4fcaec6500.json",
20+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/461d235e9497deb16b9209be4a927c7d0dc7aa06d668e38bfb19a90db8e4a4b2.json",
2121
"requiresBootstrapStackVersion": 6,
2222
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
2323
"additionalDependencies": [
@@ -39,6 +39,18 @@
3939
"data": "TestApplication2FBC585F"
4040
}
4141
],
42+
"/integ-servicecatalogappregistry-application/TestApplication/ResourceAssociationd232b63e52a8": [
43+
{
44+
"type": "aws:cdk:logicalId",
45+
"data": "TestApplicationResourceAssociationd232b63e52a8414E905D"
46+
}
47+
],
48+
"/integ-servicecatalogappregistry-application/TestApplication/AttributeGroupAssociation4ba7f5842818": [
49+
{
50+
"type": "aws:cdk:logicalId",
51+
"data": "TestApplicationAttributeGroupAssociation4ba7f5842818B8EE1C6F"
52+
}
53+
],
4254
"/integ-servicecatalogappregistry-application/TestApplication/myAnotherAttributeGroup/Resource": [
4355
{
4456
"type": "aws:cdk:logicalId",
@@ -57,6 +69,12 @@
5769
"data": "TestApplicationMyShareIdE1044482"
5870
}
5971
],
72+
"/integ-servicecatalogappregistry-application/TestAttributeGroup/Resource": [
73+
{
74+
"type": "aws:cdk:logicalId",
75+
"data": "TestAttributeGroupB1CB284F"
76+
}
77+
],
6078
"/integ-servicecatalogappregistry-application/MyRole/Resource": [
6179
{
6280
"type": "aws:cdk:logicalId",

0 commit comments

Comments
 (0)