-
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
Changes from 2 commits
99b886e
140da6e
0d7940f
2f065d6
72a2683
2c9eba0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,12 @@ export interface IApplication extends cdk.IResource { | |
*/ | ||
readonly applicationName?: string; | ||
|
||
/** | ||
* Application manager URL for the Application. | ||
* @attribute | ||
*/ | ||
readonly applicationManagerUrl?: cdk.CfnOutput; | ||
|
||
/** | ||
* Associate this application with an attribute group. | ||
* | ||
|
@@ -94,6 +100,7 @@ abstract class ApplicationBase extends cdk.Resource implements IApplication { | |
public abstract readonly applicationArn: string; | ||
public abstract readonly applicationId: string; | ||
public abstract readonly applicationName?: string; | ||
public abstract readonly applicationManagerUrl?: cdk.CfnOutput; | ||
private readonly associatedAttributeGroups: Set<string> = new Set(); | ||
private readonly associatedResources: Set<string> = new Set(); | ||
|
||
|
@@ -134,20 +141,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); | ||
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. Why is this necessary? If the 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 commentThe 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 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. 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
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
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. you are right, the diagram is correct and the problem never happens for the new
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. Actually you are right, since |
||
} | ||
|
||
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)); | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -240,6 +253,7 @@ export class Application extends ApplicationBase { | |
public readonly applicationArn = applicationArn; | ||
public readonly applicationId = applicationId!; | ||
public readonly applicationName = undefined; | ||
public readonly applicationManagerUrl = undefined; | ||
|
||
protected generateUniqueHash(resourceAddress: string): string { | ||
return hashValues(this.applicationArn, resourceAddress); | ||
|
@@ -254,6 +268,7 @@ export class Application extends ApplicationBase { | |
public readonly applicationArn: string; | ||
public readonly applicationId: string; | ||
public readonly applicationName?: string; | ||
public readonly applicationManagerUrl?: cdk.CfnOutput; | ||
private readonly nodeAddress: string; | ||
|
||
constructor(scope: Construct, id: string, props: ApplicationProps) { | ||
|
@@ -270,6 +285,10 @@ 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. |
||
}); | ||
} | ||
|
||
protected generateUniqueHash(resourceAddress: string): string { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"version":"21.0.0"} | ||
{"version":"22.0.0"} |
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": [ | ||
|
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.
Don't put it on
IApplication
. By its very nature it's optional, which is not very useful.More useful to put it definitely on
Application
.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.
Addressed in the new revision.