Skip to content

Commit

Permalink
fix(servicecatalogappregistry): Allow user to control stack id via st…
Browse files Browse the repository at this point in the history
…ack 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*
  • Loading branch information
jungle-amazon authored Feb 16, 2023
1 parent 5e0f44b commit 0c7c7e4
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export interface TargetApplicationCommonOptions extends cdk.StackProps {
* Stack ID in which application will be created or imported. The id of a stack is also the identifier that you use to
* refer to it in the [AWS CDK Toolkit](https://docs.aws.amazon.com/cdk/v2/guide/cli.html).
*
* @default - ApplicationAssociatorStack
* @deprecated - Use `stackName` instead to control the name of the stack
* @default - The value of `stackName` will be used as stack id
* @deprecated - Use `stackName` instead to control the name and id of the stack
*/
readonly stackId?: string;
}
Expand Down Expand Up @@ -91,9 +91,9 @@ class CreateTargetApplication extends TargetApplication {
super();
}
public bind(scope: Construct): BindTargetApplicationResult {
const stackId = this.applicationOptions.stackId ?? 'ApplicationAssociatorStack';
(this.applicationOptions.stackName as string) =
this.applicationOptions.stackName || `Application-${this.applicationOptions.applicationName}-Stack`;
const stackId = this.applicationOptions.stackName;
(this.applicationOptions.description as string) =
this.applicationOptions.description || 'Stack to create AppRegistry application';
(this.applicationOptions.env as cdk.Environment) =
Expand Down Expand Up @@ -122,9 +122,9 @@ class ExistingTargetApplication extends TargetApplication {
public bind(scope: Construct): BindTargetApplicationResult {
const arnComponents = cdk.Arn.split(this.applicationOptions.applicationArnValue, cdk.ArnFormat.SLASH_RESOURCE_SLASH_RESOURCE_NAME);
const applicationId = arnComponents.resourceName;
const stackId = this.applicationOptions.stackId ?? 'ApplicationAssociatorStack';
(this.applicationOptions.stackName as string) =
this.applicationOptions.stackName || `Application-${applicationId}-Stack`;
const stackId = this.applicationOptions.stackName;
const applicationStack = new cdk.Stack(scope, stackId, this.applicationOptions);
const appRegApplication = Application.fromApplicationArn(applicationStack, 'ExistingApplication', this.applicationOptions.applicationArnValue);
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"version": "29.0.0",
"version": "30.0.0",
"files": {
"c4d674e9642d6dbbd0df5c93890473101fc95bbc70de7e28d79ba771b5284de8": {
"source": {
"path": "ApplicationAssociatorStack.template.json",
"path": "Application-AppRegistryAssociatedApplication-Stack.template.json",
"packaging": "file"
},
"destinations": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "29.0.0",
"version": "30.0.0",
"files": {
"19dd33f3c17e59cafd22b9459b0a8d9bedbd42252737fedb06b2bcdbcf7809cc": {
"source": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"30.0.0"}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "29.0.0",
"version": "30.0.0",
"files": {
"19dd33f3c17e59cafd22b9459b0a8d9bedbd42252737fedb06b2bcdbcf7809cc": {
"source": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "29.0.0",
"version": "30.0.0",
"testCases": {
"ApplicationAssociatorTest/DefaultTest": {
"stacks": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "29.0.0",
"version": "30.0.0",
"files": {
"19dd33f3c17e59cafd22b9459b0a8d9bedbd42252737fedb06b2bcdbcf7809cc": {
"source": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "29.0.0",
"version": "30.0.0",
"artifacts": {
"integservicecatalogappregistryapplicationresourcesStack4399A149.assets": {
"type": "cdk:asset-manifest",
Expand Down Expand Up @@ -30,7 +30,7 @@
}
},
"dependencies": [
"ApplicationAssociatorStack",
"Application-AppRegistryAssociatedApplication-Stack",
"integservicecatalogappregistryapplicationresourcesStack4399A149.assets"
],
"metadata": {
Expand Down Expand Up @@ -94,7 +94,7 @@
}
},
"dependencies": [
"ApplicationAssociatorStack",
"Application-AppRegistryAssociatedApplication-Stack",
"integ-servicecatalogappregistry-application.assets"
],
"metadata": {
Expand Down Expand Up @@ -129,71 +129,70 @@
},
"displayName": "integ-servicecatalogappregistry-application"
},
"ApplicationAssociatorStack.assets": {
"Application-AppRegistryAssociatedApplication-Stack.assets": {
"type": "cdk:asset-manifest",
"properties": {
"file": "ApplicationAssociatorStack.assets.json",
"file": "Application-AppRegistryAssociatedApplication-Stack.assets.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
}
},
"ApplicationAssociatorStack": {
"Application-AppRegistryAssociatedApplication-Stack": {
"type": "aws:cloudformation:stack",
"environment": "aws://416623072619/us-east-1",
"properties": {
"templateFile": "ApplicationAssociatorStack.template.json",
"templateFile": "Application-AppRegistryAssociatedApplication-Stack.template.json",
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::416623072619:role/cdk-hnb659fds-deploy-role-416623072619-us-east-1",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::416623072619:role/cdk-hnb659fds-cfn-exec-role-416623072619-us-east-1",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-416623072619-us-east-1/c4d674e9642d6dbbd0df5c93890473101fc95bbc70de7e28d79ba771b5284de8.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
"ApplicationAssociatorStack.assets"
"Application-AppRegistryAssociatedApplication-Stack.assets"
],
"lookupRole": {
"arn": "arn:${AWS::Partition}:iam::416623072619:role/cdk-hnb659fds-lookup-role-416623072619-us-east-1",
"requiresBootstrapStackVersion": 8,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
},
"stackName": "Application-AppRegistryAssociatedApplication-Stack"
}
},
"dependencies": [
"ApplicationAssociatorStack.assets"
"Application-AppRegistryAssociatedApplication-Stack.assets"
],
"metadata": {
"/ApplicationAssociatorStack/DefaultCdkApplication/Resource": [
"/Application-AppRegistryAssociatedApplication-Stack/DefaultCdkApplication/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "DefaultCdkApplication4573D5A3"
}
],
"/ApplicationAssociatorStack/DefaultCdkApplication/ApplicationManagerUrl": [
"/Application-AppRegistryAssociatedApplication-Stack/DefaultCdkApplication/ApplicationManagerUrl": [
{
"type": "aws:cdk:logicalId",
"data": "DefaultCdkApplicationApplicationManagerUrl27C138EF"
}
],
"/ApplicationAssociatorStack/AppRegistryAssociation": [
"/Application-AppRegistryAssociatedApplication-Stack/AppRegistryAssociation": [
{
"type": "aws:cdk:logicalId",
"data": "AppRegistryAssociation"
}
],
"/ApplicationAssociatorStack/BootstrapVersion": [
"/Application-AppRegistryAssociatedApplication-Stack/BootstrapVersion": [
{
"type": "aws:cdk:logicalId",
"data": "BootstrapVersion"
}
],
"/ApplicationAssociatorStack/CheckBootstrapVersion": [
"/Application-AppRegistryAssociatedApplication-Stack/CheckBootstrapVersion": [
{
"type": "aws:cdk:logicalId",
"data": "CheckBootstrapVersion"
}
]
},
"displayName": "ApplicationAssociatorStack"
"displayName": "Application-AppRegistryAssociatedApplication-Stack"
},
"ApplicationAssociatorTestDefaultTestDeployAssert2A5F2DB9.assets": {
"type": "cdk:asset-manifest",
Expand Down Expand Up @@ -224,7 +223,7 @@
}
},
"dependencies": [
"ApplicationAssociatorStack",
"Application-AppRegistryAssociatedApplication-Stack",
"ApplicationAssociatorTestDefaultTestDeployAssert2A5F2DB9.assets"
],
"metadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,17 @@
"version": "0.0.0"
}
},
"ApplicationAssociatorStack": {
"id": "ApplicationAssociatorStack",
"path": "ApplicationAssociatorStack",
"Application-AppRegistryAssociatedApplication-Stack": {
"id": "Application-AppRegistryAssociatedApplication-Stack",
"path": "Application-AppRegistryAssociatedApplication-Stack",
"children": {
"DefaultCdkApplication": {
"id": "DefaultCdkApplication",
"path": "ApplicationAssociatorStack/DefaultCdkApplication",
"path": "Application-AppRegistryAssociatedApplication-Stack/DefaultCdkApplication",
"children": {
"Resource": {
"id": "Resource",
"path": "ApplicationAssociatorStack/DefaultCdkApplication/Resource",
"path": "Application-AppRegistryAssociatedApplication-Stack/DefaultCdkApplication/Resource",
"attributes": {
"aws:cdk:cloudformation:type": "AWS::ServiceCatalogAppRegistry::Application",
"aws:cdk:cloudformation:props": {
Expand All @@ -128,7 +128,7 @@
},
"ApplicationManagerUrl": {
"id": "ApplicationManagerUrl",
"path": "ApplicationAssociatorStack/DefaultCdkApplication/ApplicationManagerUrl",
"path": "Application-AppRegistryAssociatedApplication-Stack/DefaultCdkApplication/ApplicationManagerUrl",
"constructInfo": {
"fqn": "@aws-cdk/core.CfnOutput",
"version": "0.0.0"
Expand All @@ -142,7 +142,7 @@
},
"AppRegistryAssociation": {
"id": "AppRegistryAssociation",
"path": "ApplicationAssociatorStack/AppRegistryAssociation",
"path": "Application-AppRegistryAssociatedApplication-Stack/AppRegistryAssociation",
"attributes": {
"aws:cdk:cloudformation:type": "AWS::ServiceCatalogAppRegistry::ResourceAssociation",
"aws:cdk:cloudformation:props": {
Expand All @@ -165,15 +165,15 @@
},
"BootstrapVersion": {
"id": "BootstrapVersion",
"path": "ApplicationAssociatorStack/BootstrapVersion",
"path": "Application-AppRegistryAssociatedApplication-Stack/BootstrapVersion",
"constructInfo": {
"fqn": "@aws-cdk/core.CfnParameter",
"version": "0.0.0"
}
},
"CheckBootstrapVersion": {
"id": "CheckBootstrapVersion",
"path": "ApplicationAssociatorStack/CheckBootstrapVersion",
"path": "Application-AppRegistryAssociatedApplication-Stack/CheckBootstrapVersion",
"constructInfo": {
"fqn": "@aws-cdk/core.CfnRule",
"version": "0.0.0"
Expand Down

This file was deleted.

0 comments on commit 0c7c7e4

Please sign in to comment.