Skip to content

Commit 0c7c7e4

Browse files
fix(servicecatalogappregistry): Allow user to control stack id via stack name for Application stack (#24171)
* Assign value of `stackName` to `stackId` for Application stack, so the stack id will always be the same as stack name. Users wanting to control stack id can do so via `stackName`. Closes #24160. Background: * Customers wish to control or modify the stack id of the Application stack to follow their project conventions within CDK. * In previous [fix](#23823), we had deprecated the stack id to push users towards using stack name as the main mechanism for stack identification. Note on backward-compatibility: After this change, the `stackId` parameter can no longer be used to control the application stack id. The stack id will always match stack name, and the default stack name if not specified will be `Application-${APPLICATION_IDENTIFIER}-Stack`. `${APPLICATION_IDENTIFIER}` is application name for CreateTargetApplication and application id for ExistingTargetApplication. If you created an application stack prior to aws-cdk [release v2.64.0](https://github.com/aws/aws-cdk/releases/tag/v2.64.0) and did not specify a stack id or name, you may run into the following error during deployment due to the creation attempt of a new stack with the same application: ```log Resource handler returned message: "You already own an application 'MyApplicationName' (Service: ServiceCatalogAppRegistry, Status Code: 409, Request ID: xxxx)" (RequestToken: yyyy, HandlerErrorCode: InvalidRequest) ``` To address this error, you can set the `stackName` value to match your existing stack. For example: ```typescript const associatedApp = new ApplicationAssociator(app, 'MyApplicationAssociator', { applications: [ TargetApplication.createApplicationStack({ applicationName: 'MyApplicationName', stackName: 'ApplicationAssociatorStack', // Add your existing stack name here ... ``` This will result in the existing stack deploying with the previous name, and the id in CDK will reflect this same stack name. Related links: * Previous PR: #23823 * Previous GitHub issue: #23861 * Original reason that introduced `stackId`: #22508 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 5e0f44b commit 0c7c7e4

15 files changed

+37
-38
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export interface TargetApplicationCommonOptions extends cdk.StackProps {
1010
* Stack ID in which application will be created or imported. The id of a stack is also the identifier that you use to
1111
* refer to it in the [AWS CDK Toolkit](https://docs.aws.amazon.com/cdk/v2/guide/cli.html).
1212
*
13-
* @default - ApplicationAssociatorStack
14-
* @deprecated - Use `stackName` instead to control the name of the stack
13+
* @default - The value of `stackName` will be used as stack id
14+
* @deprecated - Use `stackName` instead to control the name and id of the stack
1515
*/
1616
readonly stackId?: string;
1717
}
@@ -91,9 +91,9 @@ class CreateTargetApplication extends TargetApplication {
9191
super();
9292
}
9393
public bind(scope: Construct): BindTargetApplicationResult {
94-
const stackId = this.applicationOptions.stackId ?? 'ApplicationAssociatorStack';
9594
(this.applicationOptions.stackName as string) =
9695
this.applicationOptions.stackName || `Application-${this.applicationOptions.applicationName}-Stack`;
96+
const stackId = this.applicationOptions.stackName;
9797
(this.applicationOptions.description as string) =
9898
this.applicationOptions.description || 'Stack to create AppRegistry application';
9999
(this.applicationOptions.env as cdk.Environment) =
@@ -122,9 +122,9 @@ class ExistingTargetApplication extends TargetApplication {
122122
public bind(scope: Construct): BindTargetApplicationResult {
123123
const arnComponents = cdk.Arn.split(this.applicationOptions.applicationArnValue, cdk.ArnFormat.SLASH_RESOURCE_SLASH_RESOURCE_NAME);
124124
const applicationId = arnComponents.resourceName;
125-
const stackId = this.applicationOptions.stackId ?? 'ApplicationAssociatorStack';
126125
(this.applicationOptions.stackName as string) =
127126
this.applicationOptions.stackName || `Application-${applicationId}-Stack`;
127+
const stackId = this.applicationOptions.stackName;
128128
const applicationStack = new cdk.Stack(scope, stackId, this.applicationOptions);
129129
const appRegApplication = Application.fromApplicationArn(applicationStack, 'ExistingApplication', this.applicationOptions.applicationArnValue);
130130
return {
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"version": "29.0.0",
2+
"version": "30.0.0",
33
"files": {
44
"c4d674e9642d6dbbd0df5c93890473101fc95bbc70de7e28d79ba771b5284de8": {
55
"source": {
6-
"path": "ApplicationAssociatorStack.template.json",
6+
"path": "Application-AppRegistryAssociatedApplication-Stack.template.json",
77
"packaging": "file"
88
},
99
"destinations": {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "29.0.0",
2+
"version": "30.0.0",
33
"files": {
44
"19dd33f3c17e59cafd22b9459b0a8d9bedbd42252737fedb06b2bcdbcf7809cc": {
55
"source": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"30.0.0"}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "29.0.0",
2+
"version": "30.0.0",
33
"files": {
44
"19dd33f3c17e59cafd22b9459b0a8d9bedbd42252737fedb06b2bcdbcf7809cc": {
55
"source": {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "29.0.0",
2+
"version": "30.0.0",
33
"testCases": {
44
"ApplicationAssociatorTest/DefaultTest": {
55
"stacks": [
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "29.0.0",
2+
"version": "30.0.0",
33
"files": {
44
"19dd33f3c17e59cafd22b9459b0a8d9bedbd42252737fedb06b2bcdbcf7809cc": {
55
"source": {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "29.0.0",
2+
"version": "30.0.0",
33
"artifacts": {
44
"integservicecatalogappregistryapplicationresourcesStack4399A149.assets": {
55
"type": "cdk:asset-manifest",
@@ -30,7 +30,7 @@
3030
}
3131
},
3232
"dependencies": [
33-
"ApplicationAssociatorStack",
33+
"Application-AppRegistryAssociatedApplication-Stack",
3434
"integservicecatalogappregistryapplicationresourcesStack4399A149.assets"
3535
],
3636
"metadata": {
@@ -94,7 +94,7 @@
9494
}
9595
},
9696
"dependencies": [
97-
"ApplicationAssociatorStack",
97+
"Application-AppRegistryAssociatedApplication-Stack",
9898
"integ-servicecatalogappregistry-application.assets"
9999
],
100100
"metadata": {
@@ -129,71 +129,70 @@
129129
},
130130
"displayName": "integ-servicecatalogappregistry-application"
131131
},
132-
"ApplicationAssociatorStack.assets": {
132+
"Application-AppRegistryAssociatedApplication-Stack.assets": {
133133
"type": "cdk:asset-manifest",
134134
"properties": {
135-
"file": "ApplicationAssociatorStack.assets.json",
135+
"file": "Application-AppRegistryAssociatedApplication-Stack.assets.json",
136136
"requiresBootstrapStackVersion": 6,
137137
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
138138
}
139139
},
140-
"ApplicationAssociatorStack": {
140+
"Application-AppRegistryAssociatedApplication-Stack": {
141141
"type": "aws:cloudformation:stack",
142142
"environment": "aws://416623072619/us-east-1",
143143
"properties": {
144-
"templateFile": "ApplicationAssociatorStack.template.json",
144+
"templateFile": "Application-AppRegistryAssociatedApplication-Stack.template.json",
145145
"validateOnSynth": false,
146146
"assumeRoleArn": "arn:${AWS::Partition}:iam::416623072619:role/cdk-hnb659fds-deploy-role-416623072619-us-east-1",
147147
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::416623072619:role/cdk-hnb659fds-cfn-exec-role-416623072619-us-east-1",
148148
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-416623072619-us-east-1/c4d674e9642d6dbbd0df5c93890473101fc95bbc70de7e28d79ba771b5284de8.json",
149149
"requiresBootstrapStackVersion": 6,
150150
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
151151
"additionalDependencies": [
152-
"ApplicationAssociatorStack.assets"
152+
"Application-AppRegistryAssociatedApplication-Stack.assets"
153153
],
154154
"lookupRole": {
155155
"arn": "arn:${AWS::Partition}:iam::416623072619:role/cdk-hnb659fds-lookup-role-416623072619-us-east-1",
156156
"requiresBootstrapStackVersion": 8,
157157
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
158-
},
159-
"stackName": "Application-AppRegistryAssociatedApplication-Stack"
158+
}
160159
},
161160
"dependencies": [
162-
"ApplicationAssociatorStack.assets"
161+
"Application-AppRegistryAssociatedApplication-Stack.assets"
163162
],
164163
"metadata": {
165-
"/ApplicationAssociatorStack/DefaultCdkApplication/Resource": [
164+
"/Application-AppRegistryAssociatedApplication-Stack/DefaultCdkApplication/Resource": [
166165
{
167166
"type": "aws:cdk:logicalId",
168167
"data": "DefaultCdkApplication4573D5A3"
169168
}
170169
],
171-
"/ApplicationAssociatorStack/DefaultCdkApplication/ApplicationManagerUrl": [
170+
"/Application-AppRegistryAssociatedApplication-Stack/DefaultCdkApplication/ApplicationManagerUrl": [
172171
{
173172
"type": "aws:cdk:logicalId",
174173
"data": "DefaultCdkApplicationApplicationManagerUrl27C138EF"
175174
}
176175
],
177-
"/ApplicationAssociatorStack/AppRegistryAssociation": [
176+
"/Application-AppRegistryAssociatedApplication-Stack/AppRegistryAssociation": [
178177
{
179178
"type": "aws:cdk:logicalId",
180179
"data": "AppRegistryAssociation"
181180
}
182181
],
183-
"/ApplicationAssociatorStack/BootstrapVersion": [
182+
"/Application-AppRegistryAssociatedApplication-Stack/BootstrapVersion": [
184183
{
185184
"type": "aws:cdk:logicalId",
186185
"data": "BootstrapVersion"
187186
}
188187
],
189-
"/ApplicationAssociatorStack/CheckBootstrapVersion": [
188+
"/Application-AppRegistryAssociatedApplication-Stack/CheckBootstrapVersion": [
190189
{
191190
"type": "aws:cdk:logicalId",
192191
"data": "CheckBootstrapVersion"
193192
}
194193
]
195194
},
196-
"displayName": "ApplicationAssociatorStack"
195+
"displayName": "Application-AppRegistryAssociatedApplication-Stack"
197196
},
198197
"ApplicationAssociatorTestDefaultTestDeployAssert2A5F2DB9.assets": {
199198
"type": "cdk:asset-manifest",
@@ -224,7 +223,7 @@
224223
}
225224
},
226225
"dependencies": [
227-
"ApplicationAssociatorStack",
226+
"Application-AppRegistryAssociatedApplication-Stack",
228227
"ApplicationAssociatorTestDefaultTestDeployAssert2A5F2DB9.assets"
229228
],
230229
"metadata": {
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,17 @@
100100
"version": "0.0.0"
101101
}
102102
},
103-
"ApplicationAssociatorStack": {
104-
"id": "ApplicationAssociatorStack",
105-
"path": "ApplicationAssociatorStack",
103+
"Application-AppRegistryAssociatedApplication-Stack": {
104+
"id": "Application-AppRegistryAssociatedApplication-Stack",
105+
"path": "Application-AppRegistryAssociatedApplication-Stack",
106106
"children": {
107107
"DefaultCdkApplication": {
108108
"id": "DefaultCdkApplication",
109-
"path": "ApplicationAssociatorStack/DefaultCdkApplication",
109+
"path": "Application-AppRegistryAssociatedApplication-Stack/DefaultCdkApplication",
110110
"children": {
111111
"Resource": {
112112
"id": "Resource",
113-
"path": "ApplicationAssociatorStack/DefaultCdkApplication/Resource",
113+
"path": "Application-AppRegistryAssociatedApplication-Stack/DefaultCdkApplication/Resource",
114114
"attributes": {
115115
"aws:cdk:cloudformation:type": "AWS::ServiceCatalogAppRegistry::Application",
116116
"aws:cdk:cloudformation:props": {
@@ -128,7 +128,7 @@
128128
},
129129
"ApplicationManagerUrl": {
130130
"id": "ApplicationManagerUrl",
131-
"path": "ApplicationAssociatorStack/DefaultCdkApplication/ApplicationManagerUrl",
131+
"path": "Application-AppRegistryAssociatedApplication-Stack/DefaultCdkApplication/ApplicationManagerUrl",
132132
"constructInfo": {
133133
"fqn": "@aws-cdk/core.CfnOutput",
134134
"version": "0.0.0"
@@ -142,7 +142,7 @@
142142
},
143143
"AppRegistryAssociation": {
144144
"id": "AppRegistryAssociation",
145-
"path": "ApplicationAssociatorStack/AppRegistryAssociation",
145+
"path": "Application-AppRegistryAssociatedApplication-Stack/AppRegistryAssociation",
146146
"attributes": {
147147
"aws:cdk:cloudformation:type": "AWS::ServiceCatalogAppRegistry::ResourceAssociation",
148148
"aws:cdk:cloudformation:props": {
@@ -165,15 +165,15 @@
165165
},
166166
"BootstrapVersion": {
167167
"id": "BootstrapVersion",
168-
"path": "ApplicationAssociatorStack/BootstrapVersion",
168+
"path": "Application-AppRegistryAssociatedApplication-Stack/BootstrapVersion",
169169
"constructInfo": {
170170
"fqn": "@aws-cdk/core.CfnParameter",
171171
"version": "0.0.0"
172172
}
173173
},
174174
"CheckBootstrapVersion": {
175175
"id": "CheckBootstrapVersion",
176-
"path": "ApplicationAssociatorStack/CheckBootstrapVersion",
176+
"path": "Application-AppRegistryAssociatedApplication-Stack/CheckBootstrapVersion",
177177
"constructInfo": {
178178
"fqn": "@aws-cdk/core.CfnRule",
179179
"version": "0.0.0"

packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application-associator.all-stacks-association-no-stack-name.js.snapshot/cdk.out

-1
This file was deleted.

0 commit comments

Comments
 (0)