-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(servicecatalogappregistry): synth error when associating a nested stack #23248
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
99b886e
Adding CfnOutput with App manager URL, handling conditonal nested stacks
sangosh 140da6e
Changing integration test
sangosh 0d7940f
Adding description for AM url
sangosh 2f065d6
Merge branch 'main' into AppRegistry_L2_AppManagerUrl
santanugho 72a2683
Removing un-necessary condition from resource association
sangosh 2c9eba0
Merge branch 'main' into AppRegistry_L2_AppManagerUrl
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,20 +134,26 @@ abstract class ApplicationBase extends cdk.Resource implements IApplication { | |
/** | ||
* Associate stack with the application in the stack passed as parameter. | ||
* | ||
* If the stack is already associated, it will ignore duplicate request. | ||
* A stack can only be associated with one application. | ||
*/ | ||
public associateApplicationWithStack(stack: cdk.Stack): void { | ||
if (!this.associatedResources.has(stack.node.addr)) { | ||
new CfnResourceAssociation(stack, 'AppRegistryAssociation', { | ||
const stackCondition = stack.nestedStackResource?.cfnOptions.condition; | ||
const association = new CfnResourceAssociation(stack, 'AppRegistryAssociation', { | ||
application: stack === cdk.Stack.of(this) ? this.applicationId : this.applicationName ?? this.applicationId, | ||
resource: stack.stackId, | ||
resourceType: 'CFN_STACK', | ||
}); | ||
|
||
this.associatedResources.add(stack.node.addr); | ||
if (stack !== cdk.Stack.of(this) && this.isSameAccount(stack) && !this.isStageScope(stack)) { | ||
stack.addDependency(cdk.Stack.of(this)); | ||
if (stackCondition) { | ||
association.addOverride('Condition', stackCondition.logicalId); | ||
} | ||
|
||
if (!stack.nested) { | ||
this.associatedResources.add(stack.node.addr); | ||
if (stack !== cdk.Stack.of(this) && this.isSameAccount(stack) && !this.isStageScope(stack)) { | ||
stack.addDependency(cdk.Stack.of(this)); | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -251,6 +257,11 @@ export class Application extends ApplicationBase { | |
}); | ||
} | ||
|
||
/** | ||
* Application manager URL for the Application. | ||
* @attribute | ||
*/ | ||
public readonly applicationManagerUrl?: cdk.CfnOutput; | ||
public readonly applicationArn: string; | ||
public readonly applicationId: string; | ||
public readonly applicationName?: string; | ||
|
@@ -270,6 +281,11 @@ export class Application extends ApplicationBase { | |
this.applicationId = application.attrId; | ||
this.applicationName = props.applicationName; | ||
this.nodeAddress = cdk.Names.nodeUniqueId(application.node); | ||
|
||
this.applicationManagerUrl = new cdk.CfnOutput(this, 'ApplicationManagerUrl', { | ||
value: `https://${this.env.region}.console.aws.amazon.com/systems-manager/appmanager/application/AWS_AppRegistry_Application-${this.applicationName}`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in the new revision. |
||
description: `Application manager url for application ${this.applicationName}`, | ||
}); | ||
} | ||
|
||
protected generateUniqueHash(resourceAddress: string): string { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/cdk.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"version":"21.0.0"} | ||
{"version":"22.0.0"} |
6 changes: 3 additions & 3 deletions
6
...est/integ.application.js.snapshot/integ-servicecatalogappregistry-application.assets.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.js.snapshot/integ.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"version": "20.0.0", | ||
"version": "22.0.0", | ||
"testCases": { | ||
"integ.application": { | ||
"stacks": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary? If the
ResourceAssociation
is INSIDE the nested stack, and the nested stack doesn't get created, then the resourceassociation wouldn't be created?Please describe in the PR body and title, from a user's point of view, what the situation and error were.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you have described is the exact situation here, AWS Solutions team had a stack with conditional nested stack. While they used our L2 construct, the association failed as the condition evaluated to be
false
whereas our L2 construct previously couldnt handle that condition inResourceAssociation
. This is a fix for the same. I will add this detail to the PR description.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that it has something to do with putting conditions on NestedStacks, but you missed one part of my question: if I recall the design is for the
ResourceAssocation
constructs to be INSIDE the stacks that are being associated.Allow me to explain with a diagram. This is what I think should be going on, purely looking at the CloudFormation template level:
If that is not what is going on (if instead the
ResourceAssociation
is inParentStack
instead ofChildStack
), then:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right, the diagram is correct and the problem never happens for the new
ApplicationAssociator
construct. However, this problem occurs only if customers try to explicitly associate a nested child stack like below:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually you are right, since
associateApplicationWithStack
is creating the association inside child stack, we dont need to add the condition forResourceAssociation
.