diff --git a/packages/@aws-cdk/custom-resources/lib/provider-framework/runtime/framework.ts b/packages/@aws-cdk/custom-resources/lib/provider-framework/runtime/framework.ts index 181968611d354..9c2d8a4bfc0fc 100644 --- a/packages/@aws-cdk/custom-resources/lib/provider-framework/runtime/framework.ts +++ b/packages/@aws-cdk/custom-resources/lib/provider-framework/runtime/framework.ts @@ -73,6 +73,7 @@ async function isComplete(event: AWSCDKAsyncCustomResource.IsCompleteRequest) { const response = { ...event, + ...isCompleteResult, Data: { ...event.Data, ...isCompleteResult.Data, diff --git a/packages/@aws-cdk/custom-resources/lib/provider-framework/types.d.ts b/packages/@aws-cdk/custom-resources/lib/provider-framework/types.d.ts index 9a9536eac078b..288dc217c7f82 100644 --- a/packages/@aws-cdk/custom-resources/lib/provider-framework/types.d.ts +++ b/packages/@aws-cdk/custom-resources/lib/provider-framework/types.d.ts @@ -4,7 +4,7 @@ /** * these types can be accessed without needing to `import` the module. * e.g. `AWSCDKAsyncCustomResource.OnEventRequest` - */ + */ export as namespace AWSCDKAsyncCustomResource; /** @@ -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`. */ diff --git a/packages/@aws-cdk/custom-resources/test/provider-framework/runtime.test.ts b/packages/@aws-cdk/custom-resources/test/provider-framework/runtime.test.ts index d2af0a4fafd2d..751e33e6408e0 100644 --- a/packages/@aws-cdk/custom-resources/test/provider-framework/runtime.test.ts +++ b/packages/@aws-cdk/custom-resources/test/provider-framework/runtime.test.ts @@ -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' });