Skip to content
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(custom-resources): physical resource id must be determined before isComplete #18630

Merged
merged 3 commits into from
Feb 26, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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