Skip to content

Comments

[CLOUDS-7349] Prevent deletion when using CFT for existing account#277

Open
dhan0779 wants to merge 6 commits intomasterfrom
david.han/clouds-7349-existing-integration
Open

[CLOUDS-7349] Prevent deletion when using CFT for existing account#277
dhan0779 wants to merge 6 commits intomasterfrom
david.han/clouds-7349-existing-integration

Conversation

@dhan0779
Copy link
Contributor

@dhan0779 dhan0779 commented Feb 19, 2026

Note: Please remember to review the contribution guidelines
if you have not yet done so.

What does this PR do?

When deploying a CloudFormation stack/StackSet to an AWS account that already has a Datadog integration registered, the Lambda handler blindly POSTs to the Datadog API, gets a 409 Conflict, reports FAILED to CloudFormation, which triggers a rollback. The rollback sends a Delete event that removes the pre-existing integration. A similar effect occurs when using the same IAMRoleName.

Changes:
On Create, before blindly POSTing to the Datadog API, we now call GET to check if the account is already registered. If it is, we use PATCH (update) instead of POST (create), avoiding the 409 conflict.

When we detect a pre-existing integration and PATCH it, we set the CloudFormation PhysicalResourceId to "PREEXISTING". On the Delete handler (which fires during rollback), we check this ID — if it's "PREEXISTING", we skip the delete and return SUCCESS, preserving the customer's existing integration.

These two cases should prevent account deletion during unintentional rollbacks from the stack.

Motivation

What inspired you to submit this pull request?

Testing Guidelines

Tested in my sbx-david-playground account in staging.

Test 1: deployed the template using the same role name -
In this case, the first stack succeeds and the integration is created (verified on the main AWS tile). Then, I tried deploying again using the same role name. While this time the stack fails, the account is not deleted and kept with the same integration role name before.

Test 2: deployed the template using different role name -
Like in the first test, the first stack succeeds and the integration is created with no issue. Running the template again with a different role name updates the previous integration/account with the updated role name.

Additional Notes

Anything else we should know when reviewing?

@dhan0779 dhan0779 requested a review from a team as a code owner February 19, 2026 16:13
@dhan0779 dhan0779 changed the title [CLOUDS-7349] Use PATCH method when account integration exists [CLOUDS-7349] Prevent deletion when using CFT for existing account Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant