I’m having some challenges with terraform. I’m not even sure if this is doable, but I’m hoping someone could help me out
Take the following code as an example. You can run it and test the behavior I’m about to explain.
resource "terraform_data" "nothing_one" {
lifecycle {
create_before_destroy = true
}
}
resource "terraform_data" "nothing_two" {
lifecycle {
create_before_destroy = true
}
depends_on = [
resource.terraform_data.nothing_one
]
}
resource "terraform_data" "nothing_three" {
depends_on = [
resource.terraform_data.nothing_one,
resource.terraform_data.nothing_two
]
triggers_replace = {
always_run = timestamp()
}
}
I would like nothing_three
to always execute. It’s a certain resource that always needs to be created (it’s local-exec
it my actual code). However it needs to run AFTER all the creations and deletions of both nothing_one and nothing_two.
Problem: Right now if I delete nothing_two
, the deletion will always occur after nothing_three
.
The main reason for this behavior is due to nothing_one
and nothing_two
having create_before_destroy = true
, but that is a limitation from the provider we are using and we need to keep that lifecycle on both resources.
So my question is: Is there ANY way I can make nothing_three
always execute only once and as the absolute LAST task (after creations, updates, destroys)?
Thank you for your help in advance, really appreciate it!