Reputation: 11708
My use case is that we already have a stack created out of AWS Cloudformation.
Now I want to update that stack and my requirement is that I want to delete a resource that was already created and add the new modified resource but I want to make sure that the delete happens before the create part.
I explored the dependsOn but that helps me with setting the order of resource creation. It doesn't help with ensuring the delete and the create ordering (or atleast nothing that i could find)
How to make sure that the resource deletion happens before resource creation while doing the cloudformation update
Upvotes: 11
Views: 9115
Reputation: 63
What you are looking for here is actually the default behavior for Terraform, which will be to delete the resource and only then create the modified one.
With Terraform you can also change this to align with the CloudFormation style - create the modified resource and only then delete the old one: Terraform Lifecycle capability (block) with attribute create_before_destroy = true
, but unfortunately this is not available with CloudFormation (or CDK).
Upvotes: 1
Reputation: 2982
There is no other option unless dividing your operation into two steps:
You will need to update the stack, using the current template, changing only the name of the resources which you will modify later.
Update the stack - uploading a new template with your modifications - but remember to set the resource name with the previous value.
Upvotes: 3
Reputation: 785
I understand you want to,
delete a resource that was already created and add the new modified resource
Below is my understanding, let me know if it helps,
It is very trickey to Delete and Create resource having same resource name/dependency in a single CloudFormation deployment.
Easiest approach :
Other approach might be:
Also I think anyway you will receive an error if you try to create/modify on deleted/ delete in-progress resource
Upvotes: 2