Skip to content

Commit

Permalink
Merge branch 'master' into huijbers/triggers-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Feb 26, 2022
2 parents bd92a0a + b0e0155 commit 743cf3d
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ async function isComplete(event: AWSCDKAsyncCustomResource.IsCompleteRequest) {

const response = {
...event,
...isCompleteResult,
Data: {
...event.Data,
...isCompleteResult.Data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/**
* these types can be accessed without needing to `import` the module.
* e.g. `AWSCDKAsyncCustomResource.OnEventRequest`
*/
*/
export as namespace AWSCDKAsyncCustomResource;

/**
Expand Down Expand Up @@ -105,6 +105,11 @@ export interface IsCompleteResponse {
*/
readonly IsComplete: boolean;

/**
* If present, overrides the PhysicalResourceId of OnEventResponse with the PhysicalResourceId of IsCompleteResponse.
*/
readonly PhysicalResourceId?: string;

/**
* Additional/changes to resource attributes. This hash will be merged with the one returned from `OnEventResponse`.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,23 @@ describe('PhysicalResourceId', () => {
});
});

test('UPDATE: can override the physical ID with the actual on isComplete', async () => {
// GIVEN
mocks.onEventImplMock = async () => ({ PhysicalResourceId: 'TemporaryPhysicalId' });
mocks.isCompleteImplMock = async () => ({ IsComplete: true, PhysicalResourceId: 'NewPhysicalId' });

// WHEN
await simulateEvent({
RequestType: 'Update',
PhysicalResourceId: 'CurrentPhysicalId',
});

// THEN
expectCloudFormationSuccess({
PhysicalResourceId: 'NewPhysicalId',
});
});

test('DELETE: cannot change the physical resource ID during a delete', async () => {
// GIVEN
mocks.onEventImplMock = async () => ({ PhysicalResourceId: 'NewPhysicalId' });
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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 743cf3d

Please sign in to comment.