Skip to content

Commit

Permalink
fix: construct paths are not printed for nested stacks in CLI output (#…
Browse files Browse the repository at this point in the history
…18725)

This fixes issue #18724


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
visadb committed Feb 26, 2022
1 parent c190367 commit b0e0155
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 6 deletions.
Expand Up @@ -37,9 +37,10 @@ export class CloudFormationStackArtifact extends CloudArtifact {
public readonly stackName: string;

/**
* A string that represents this stack. Should only be used in user interfaces.
* If the stackName and artifactId are the same, it will just return that. Otherwise,
* it will return something like "<artifactId> (<stackName>)"
* A string that represents this stack. Should only be used in user
* interfaces. If the stackName has not been set explicitly, or has been set
* to artifactId, it will return the hierarchicalId of the stack. Otherwise,
* it will return something like "<hierarchicalId> (<stackName>)"
*/
public readonly displayName: string;

Expand Down Expand Up @@ -148,8 +149,8 @@ export class CloudFormationStackArtifact extends CloudArtifact {
this.assets = this.findMetadataByType(cxschema.ArtifactMetadataEntryType.ASSET).map(e => e.data as cxschema.AssetMetadataEntry);

this.displayName = this.stackName === artifactId
? this.stackName
: `${artifactId} (${this.stackName})`;
? this.hierarchicalId
: `${this.hierarchicalId} (${this.stackName})`;

this.name = this.stackName; // backwards compat
this.originalName = this.stackName;
Expand Down
17 changes: 16 additions & 1 deletion packages/@aws-cdk/cx-api/test/cloud-assembly.test.ts
Expand Up @@ -132,7 +132,22 @@ test('getStackArtifact retrieves a stack by artifact id', () => {
expect(assembly.getStackArtifact('stack1').id).toEqual('stack1');
});

test('displayName shows both artifact ID and stack name if needed', () => {
test('displayName shows hierarchical ID for nested stack without explicit stackName', () => {
const assembly = new CloudAssembly(path.join(FIXTURES, 'nested-stacks'));
const stackArtifact = assembly.getStackArtifact('topLevelStackNestedStackDAC87084');
expect(stackArtifact.hierarchicalId).toStrictEqual('topLevelStack/nestedStack');
expect(stackArtifact.displayName).toStrictEqual('topLevelStack/nestedStack');
});

test('displayName shows hierarchical ID and stackName for nested stack with explicit stackName', () => {
const assembly = new CloudAssembly(path.join(FIXTURES, 'nested-stacks'));
const nestedStack = assembly.getStackArtifact('topLevelStackNestedStackWithStackName6D28EAEF');
expect(nestedStack.hierarchicalId).toStrictEqual('topLevelStack/nestedStackWithStackName');
expect(nestedStack.stackName).toStrictEqual('explicitStackName');
expect(nestedStack.displayName).toStrictEqual('topLevelStack/nestedStackWithStackName (explicitStackName)');
});

test('displayName shows both hierarchical ID and stack name if needed', () => {
const a1 = new CloudAssembly(path.join(FIXTURES, 'multiple-stacks-same-name'));
expect(a1.getStackArtifact('stack1').displayName).toStrictEqual('stack1 (the-physical-name-of-the-stack)');
expect(a1.getStackArtifact('stack2').displayName).toStrictEqual('stack2 (the-physical-name-of-the-stack)');
Expand Down
30 changes: 30 additions & 0 deletions packages/@aws-cdk/cx-api/test/fixtures/nested-stacks/manifest.json
@@ -0,0 +1,30 @@
{
"version": "0.0.0",
"artifacts": {
"topLevelStack": {
"type": "aws:cloudformation:stack",
"environment": "aws://111111111111/us-east-1",
"properties": {
"templateFile": "topLevelStack.template.json"
},
"displayName": "topLevelStack"
},
"topLevelStackNestedStackDAC87084": {
"type": "aws:cloudformation:stack",
"environment": "aws://111111111111/us-east-1",
"properties": {
"templateFile": "nestedStack.template.json"
},
"displayName": "topLevelStack/nestedStack"
},
"topLevelStackNestedStackWithStackName6D28EAEF": {
"type": "aws:cloudformation:stack",
"environment": "aws://111111111111/us-east-1",
"properties": {
"templateFile": "nestedStackWithStackName.template.json",
"stackName": "explicitStackName"
},
"displayName": "topLevelStack/nestedStackWithStackName"
}
}
}
Empty file.
Empty file.
Empty file.

0 comments on commit b0e0155

Please sign in to comment.