Skip to content

Commit c190367

Browse files
authored
fix(custom-resources): physical resource id must be determined before isComplete (#18630)
For some resource on event can only generate an intermediary physical resource id. On isComplete the actual physical resource id can be retrieved from the created resource. Therefor it's useful to override the temporary one. Fixes #18670 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 2ea9da1 commit c190367

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

packages/@aws-cdk/custom-resources/lib/provider-framework/runtime/framework.ts

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ async function isComplete(event: AWSCDKAsyncCustomResource.IsCompleteRequest) {
7373

7474
const response = {
7575
...event,
76+
...isCompleteResult,
7677
Data: {
7778
...event.Data,
7879
...isCompleteResult.Data,

packages/@aws-cdk/custom-resources/lib/provider-framework/types.d.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/**
55
* these types can be accessed without needing to `import` the module.
66
* e.g. `AWSCDKAsyncCustomResource.OnEventRequest`
7-
*/
7+
*/
88
export as namespace AWSCDKAsyncCustomResource;
99

1010
/**
@@ -105,6 +105,11 @@ export interface IsCompleteResponse {
105105
*/
106106
readonly IsComplete: boolean;
107107

108+
/**
109+
* If present, overrides the PhysicalResourceId of OnEventResponse with the PhysicalResourceId of IsCompleteResponse.
110+
*/
111+
readonly PhysicalResourceId?: string;
112+
108113
/**
109114
* Additional/changes to resource attributes. This hash will be merged with the one returned from `OnEventResponse`.
110115
*/

packages/@aws-cdk/custom-resources/test/provider-framework/runtime.test.ts

+17
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,23 @@ describe('PhysicalResourceId', () => {
169169
});
170170
});
171171

172+
test('UPDATE: can override the physical ID with the actual on isComplete', async () => {
173+
// GIVEN
174+
mocks.onEventImplMock = async () => ({ PhysicalResourceId: 'TemporaryPhysicalId' });
175+
mocks.isCompleteImplMock = async () => ({ IsComplete: true, PhysicalResourceId: 'NewPhysicalId' });
176+
177+
// WHEN
178+
await simulateEvent({
179+
RequestType: 'Update',
180+
PhysicalResourceId: 'CurrentPhysicalId',
181+
});
182+
183+
// THEN
184+
expectCloudFormationSuccess({
185+
PhysicalResourceId: 'NewPhysicalId',
186+
});
187+
});
188+
172189
test('DELETE: cannot change the physical resource ID during a delete', async () => {
173190
// GIVEN
174191
mocks.onEventImplMock = async () => ({ PhysicalResourceId: 'NewPhysicalId' });

0 commit comments

Comments
 (0)