Is terraform destroy
needed before terraform apply
? If not, what is a workflow you follow when updating existing infrastructure and how do you decide if destroy
is needed?
That would be pretty non-standard, in my opinion. Terraform destroy
is only used in cases where you want to completely wipe your infrastructure. One of the biggest features of terraform is that it can do an intelligent delta of your desired infrastructure and your existing infrastructure and only make the changes needed. By performing a refresh
, plan
and apply
you can ensure that terraform:
refresh
- Has an up-to-date understanding of your current infrastructure. This is important in case anything was changed manually, outside of your terraform script. plan
- Prepares a list for you to review of what terraform intends to modify, or delete (or leave alone). apply
- Performs the changes laid out in the plan.By executing these 3 commands in sequence terraform will only perform the changes necessary, in the order required, to bring your environments in line with any changes to your terraform file.
Where I find destroy to be useful is in non-production environments or in cases where you are performing a restructure that's so invasive that starting from scratch would ensure a safer build.
*There are also edge cases where terraform may fail to understand the correct order of operations (do I modify a security group first or a security group rule?), or it will find itself in a dependency cycle and will be unable to perform an operation. In those cases, however, running destroy is a nuclear solution. In general, I would perform the problem change manually (via command line, or AWS Console, if I'm in AWS), to nudge it along and then run a refresh
, plan
, apply
sequence to get back on track.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With