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

(core): delete should be done prioritized over create for the same resource type in the same context #27094

Closed
JonWallsten opened this issue Sep 11, 2023 · 4 comments
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug.

Comments

@JonWallsten
Copy link
Contributor

Describe the bug

I had to change the logical ID for an IP-RecordSet but it failed to create it because the A-Record already exists.
image

image
Checking the diff we can see that one will be destroyed and one will be created.

But they are executed in the opposite order.

Expected Behavior

I expect the delete to take place before the destroy, since if you have one create and one destroy, the created one should always be the end result. You cannot get a destroy action if you don't have an existing one. So there's only one logical outcome. If I'm not mistaken.
I understand that these are two different resources with no connections and I'm not trying to make it sound like an easy thing to fix.. But if they belong to the same service, and a called from the same context, it should be possible to analyze this scenario.

Current Behavior

The process tried to create the new resource before removing the old one causing an error.

Reproduction Steps

  1. Create an IP-RecordSet (A)
  2. Rename the logical ID but keep the same values

Possible Solution

In the cases where it's possible, prioritize the delete actions.

Additional Information/Context

No response

CDK CLI Version

2.95.0

Framework Version

No response

Node.js Version

18.14.1

OS

Windows 10 x64

Language

Typescript

Language Version

5.1.6

Other information

No response

@JonWallsten JonWallsten added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 11, 2023
@github-actions github-actions bot added the @aws-cdk/core Related to core CDK functionality label Sep 11, 2023
@indrora indrora removed the needs-triage This issue or PR still needs to be triaged. label Sep 11, 2023
@indrora
Copy link
Contributor

indrora commented Sep 11, 2023

Curious if this is because the created resource and the resource to destroy are of different types.

@JonWallsten
Copy link
Contributor Author

JonWallsten commented Sep 11, 2023

Curious if this is because the created resource and the resource to destroy are of different types.

They are both AWS::Route53::RecordSet in the same construct. They only change I did was removing the word Public from the ID. Everything else is exactly the same. This is just one example, I've seen this before with other resources as well.

@peterwoodworth
Copy link
Contributor

This is just how CloudFormation works, we call this out in our docs:

Logical ID stability
Avoid changing the logical ID of a resource after it has been created. AWS CloudFormation identifies resources by their logical ID. Therefore, if you change the logical ID of a resource, AWS CloudFormation creates a new resource with the new logical ID, then deletes the existing one. Depending on the type of resource, this might cause service interruption, data loss, or both.

Any sort of feature request on this isn't something we could consider, since we don't own CloudFormation and as such cannot do anything about this behavior. All we can do is document the behavior and recommend how to avoid the situation in the first place

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants