Skip to content

Commit

Permalink
fix(servicecatalogappregistry): creating ApplicationStack in AppScope…
Browse files Browse the repository at this point in the history
… to give user more control over the passed stackId (aws#22977)

As a user, I want to have full control over the stack ID, to maintain a naming convention when using AWS CDK Toolkit. AWS CDK Construct Library v2.51.0 allows to set the stack ID for TargetApplication, but prefixes the name with the containing construct ID. Fixes aws#22973 

BREAKING CHANGE: Stack inside ApplicationAssociator is no longer is created inside ApplicationAssociator Construct scope. The stack will now get created inside cdk.App scope.
* ** servicecatalogappregistry:** stackId  will no longer have ApplicationAssociator Construct scope.

### All Submissions:

* [ X] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
rohitagg0807 authored and Brennan Ho committed Jan 20, 2023
1 parent ef02394 commit 82edd24
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class ApplicationAssociator extends Construct {
}

const targetApplication = props.applications[0];
this.application = targetApplication.bind(this).application;
this.application = targetApplication.bind(scope).application;
cdk.Aspects.of(scope).add(new CheckedStageStackAssociator(this));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { IApplication, Application } from './application';
*/
export interface TargetApplicationCommonOptions extends cdk.StackProps {
/**
* Stack ID in which application will be created or imported.
* 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 {@link https://docs.aws.amazon.com/cdk/v2/guide/cli.html | AWS CDK Toolkit (cdk command)}.
*
* @default - ApplicationAssociatorStack
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "21.0.0",
"files": {
"4285054f947789e255e76c75b889b3b216adabb0b3f990c8966c18459cdf7b35": {
"096a2ebc1093f405e713a82ffa6755ace9d5244a06f746653f025546795d3a0a": {
"source": {
"path": "ApplicationAssociatorStack.template.json",
"path": "AppRegistryApplicationStack.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "4285054f947789e255e76c75b889b3b216adabb0b3f990c8966c18459cdf7b35.json",
"objectKey": "096a2ebc1093f405e713a82ffa6755ace9d5244a06f746653f025546795d3a0a.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"Description": "Stack that holds the AppRegistryAssociatedApplication application",
"Resources": {
"DefaultCdkApplication4573D5A3": {
"Type": "AWS::ServiceCatalogAppRegistry::Application",
"Properties": {
"Name": "AppRegistryAssociatedApplication",
"Description": "Testing AppRegistry ApplicationAssociator"
"Description": "Application containing stacks deployed via CDK."
}
},
"AppRegistryAssociation": {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"version": "21.0.0",
"artifacts": {
"Tree": {
"type": "cdk:tree",
"properties": {
"file": "tree.json"
}
},
"integservicecatalogappregistryapplicationresourcesStack4399A149.assets": {
"type": "cdk:asset-manifest",
"properties": {
Expand Down Expand Up @@ -36,7 +30,7 @@
}
},
"dependencies": [
"ApplicationAssociatorStack",
"AppRegistryApplicationStack",
"integservicecatalogappregistryapplicationresourcesStack4399A149.assets"
],
"metadata": {
Expand Down Expand Up @@ -100,7 +94,7 @@
}
},
"dependencies": [
"ApplicationAssociatorStack",
"AppRegistryApplicationStack",
"integ-servicecatalogappregistry-application.assets"
],
"metadata": {
Expand Down Expand Up @@ -135,27 +129,27 @@
},
"displayName": "integ-servicecatalogappregistry-application"
},
"ApplicationAssociatorStack.assets": {
"AppRegistryApplicationStack.assets": {
"type": "cdk:asset-manifest",
"properties": {
"file": "ApplicationAssociatorStack.assets.json",
"file": "AppRegistryApplicationStack.assets.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
}
},
"ApplicationAssociatorStack": {
"AppRegistryApplicationStack": {
"type": "aws:cloudformation:stack",
"environment": "aws://unknown-account/unknown-region",
"properties": {
"templateFile": "ApplicationAssociatorStack.template.json",
"templateFile": "AppRegistryApplicationStack.template.json",
"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}/4285054f947789e255e76c75b889b3b216adabb0b3f990c8966c18459cdf7b35.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/096a2ebc1093f405e713a82ffa6755ace9d5244a06f746653f025546795d3a0a.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
"ApplicationAssociatorStack.assets"
"AppRegistryApplicationStack.assets"
],
"lookupRole": {
"arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}",
Expand All @@ -165,10 +159,10 @@
"stackName": "AppRegistryApplicationAssociatorStack"
},
"dependencies": [
"ApplicationAssociatorStack.assets"
"AppRegistryApplicationStack.assets"
],
"metadata": {
"/ApplicationAssociatorStack": [
"/AppRegistryApplicationStack": [
{
"type": "aws:cdk:warning",
"data": "Environment agnostic stack determined, AppRegistry association might not work as expected in case you deploy cross-region or cross-account stack."
Expand All @@ -178,32 +172,38 @@
"data": "Environment agnostic stack determined, AppRegistry association might not work as expected in case you deploy cross-region or cross-account stack."
}
],
"/ApplicationAssociatorStack/DefaultCdkApplication/Resource": [
"/AppRegistryApplicationStack/DefaultCdkApplication/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "DefaultCdkApplication4573D5A3"
}
],
"/ApplicationAssociatorStack/AppRegistryAssociation": [
"/AppRegistryApplicationStack/AppRegistryAssociation": [
{
"type": "aws:cdk:logicalId",
"data": "AppRegistryAssociation"
}
],
"/ApplicationAssociatorStack/BootstrapVersion": [
"/AppRegistryApplicationStack/BootstrapVersion": [
{
"type": "aws:cdk:logicalId",
"data": "BootstrapVersion"
}
],
"/ApplicationAssociatorStack/CheckBootstrapVersion": [
"/AppRegistryApplicationStack/CheckBootstrapVersion": [
{
"type": "aws:cdk:logicalId",
"data": "CheckBootstrapVersion"
}
]
},
"displayName": "ApplicationAssociatorStack"
"displayName": "AppRegistryApplicationStack"
},
"Tree": {
"type": "cdk:tree",
"properties": {
"file": "tree.json"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@
"id": "App",
"path": "",
"children": {
"Tree": {
"id": "Tree",
"path": "Tree",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.1.95"
}
},
"integ-servicecatalogappregistry-application": {
"id": "integ-servicecatalogappregistry-application",
"path": "integ-servicecatalogappregistry-application",
Expand All @@ -37,6 +29,22 @@
"fqn": "@aws-cdk/aws-servicecatalogappregistry.CfnResourceAssociation",
"version": "0.0.0"
}
},
"BootstrapVersion": {
"id": "BootstrapVersion",
"path": "integ-servicecatalogappregistry-application/resourcesStack/BootstrapVersion",
"constructInfo": {
"fqn": "@aws-cdk/core.CfnParameter",
"version": "0.0.0"
}
},
"CheckBootstrapVersion": {
"id": "CheckBootstrapVersion",
"path": "integ-servicecatalogappregistry-application/resourcesStack/CheckBootstrapVersion",
"constructInfo": {
"fqn": "@aws-cdk/core.CfnRule",
"version": "0.0.0"
}
}
},
"constructInfo": {
Expand All @@ -61,6 +69,22 @@
"fqn": "@aws-cdk/aws-servicecatalogappregistry.CfnResourceAssociation",
"version": "0.0.0"
}
},
"BootstrapVersion": {
"id": "BootstrapVersion",
"path": "integ-servicecatalogappregistry-application/BootstrapVersion",
"constructInfo": {
"fqn": "@aws-cdk/core.CfnParameter",
"version": "0.0.0"
}
},
"CheckBootstrapVersion": {
"id": "CheckBootstrapVersion",
"path": "integ-servicecatalogappregistry-application/CheckBootstrapVersion",
"constructInfo": {
"fqn": "@aws-cdk/core.CfnRule",
"version": "0.0.0"
}
}
},
"constructInfo": {
Expand All @@ -76,22 +100,22 @@
"version": "0.0.0"
}
},
"ApplicationAssociatorStack": {
"id": "ApplicationAssociatorStack",
"path": "ApplicationAssociatorStack",
"AppRegistryApplicationStack": {
"id": "AppRegistryApplicationStack",
"path": "AppRegistryApplicationStack",
"children": {
"DefaultCdkApplication": {
"id": "DefaultCdkApplication",
"path": "ApplicationAssociatorStack/DefaultCdkApplication",
"path": "AppRegistryApplicationStack/DefaultCdkApplication",
"children": {
"Resource": {
"id": "Resource",
"path": "ApplicationAssociatorStack/DefaultCdkApplication/Resource",
"path": "AppRegistryApplicationStack/DefaultCdkApplication/Resource",
"attributes": {
"aws:cdk:cloudformation:type": "AWS::ServiceCatalogAppRegistry::Application",
"aws:cdk:cloudformation:props": {
"name": "AppRegistryAssociatedApplication",
"description": "Testing AppRegistry ApplicationAssociator"
"description": "Application containing stacks deployed via CDK."
}
},
"constructInfo": {
Expand All @@ -107,7 +131,7 @@
},
"AppRegistryAssociation": {
"id": "AppRegistryAssociation",
"path": "ApplicationAssociatorStack/AppRegistryAssociation",
"path": "AppRegistryApplicationStack/AppRegistryAssociation",
"attributes": {
"aws:cdk:cloudformation:type": "AWS::ServiceCatalogAppRegistry::ResourceAssociation",
"aws:cdk:cloudformation:props": {
Expand All @@ -127,12 +151,36 @@
"fqn": "@aws-cdk/aws-servicecatalogappregistry.CfnResourceAssociation",
"version": "0.0.0"
}
},
"BootstrapVersion": {
"id": "BootstrapVersion",
"path": "AppRegistryApplicationStack/BootstrapVersion",
"constructInfo": {
"fqn": "@aws-cdk/core.CfnParameter",
"version": "0.0.0"
}
},
"CheckBootstrapVersion": {
"id": "CheckBootstrapVersion",
"path": "AppRegistryApplicationStack/CheckBootstrapVersion",
"constructInfo": {
"fqn": "@aws-cdk/core.CfnRule",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/core.Stack",
"version": "0.0.0"
}
},
"Tree": {
"id": "Tree",
"path": "Tree",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.1.161"
}
}
},
"constructInfo": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ new appreg.ApplicationAssociator(app, 'RegisterCdkApplication', {
applications: [appreg.TargetApplication.createApplicationStack({
applicationName: 'AppRegistryAssociatedApplication',
stackName: 'AppRegistryApplicationAssociatorStack',
stackId: 'AppRegistryApplicationStack',
})],
});

Expand Down

0 comments on commit 82edd24

Please sign in to comment.