I'm migrating some stuff in a terraform repo and replacing Resource A with Resource B, of different types. If the details are important, A is a CloudFormation stack, B is a native terraform resource for the same thing.
I want to tell Terraform to delete resource A before it tries to create resource B, as they set up the same thing and otherwise I get errors from AWS about duplicate things.
Can I be clever with my use of depends_on
in order to get it to delete in the order I want?
From the docs:
The depends_on meta-argument instructs Terraform to complete all actions on the dependency object (including Read actions) before performing actions on the object declaring the dependency.
Does it do the same in reverse for a deletion? Can I therefore say that B depends_on A
and get it to do all the actions on A (deletion) before creating B? Or is there another way of doing this?
At the moment, I just have to do 2 runs and let the first one fail. But it feels like there /should/ be a way to get this to work in 1...