I am looking for a solution for the following issue.
I have an existing module A with a resource A that writes a consul policy.
*name = "${ var.application }.${ var.component }"*
consul_policy = <<EOT
..... (suppressed)
EOT
}
and this resource is currently applied in the environment.
Now I created a new Module B (to replace Module A), which has a new resource B (and no more of Resource A)
resource "vault_consul_secret_backend_role" "vault-backend-role" {
name = "${ var.application }.${ var.component }"
backend = "consul"
policies = [
"${ var.application }-${ var.component }",
]
}
On execution of Module B, I am expecting the resource “vault_consul_role” “consul-policy” to be deleted, and new resource “vault_consul_secret_backend_role” "vault-backend-role get created.
Now here is the issue I run into.
Since both Resource A and Resource B writes the same policy in Consul, during the terraform execution, occasionally the deletion of Resource A happens after Resource B creation, thereby deleting the policy from Consul.
I am trying to see if there is way to force the Resource B to execute only after Resource A is deleted. I cannot put a depends condition, as the Resource A is not in Module B.
Here is an actual O/p from terraform apply for clarity of the issue
Creation of Resource B in Module B
module.k8s-istioproxy-vault-policy.vault_consul_secret_backend_role.vault-backend-role: Creation complete after 0s (ID: consul/roles/k8s.istioproxy)
Deletion of Resource A (Since it is no longer in module B)
module.k8s-istioproxy-vault-policy.vault_consul_role.consul-policy: Destruction complete after 0s
This causes the policy to be deleted, and I have to rerun the apply step once more to get the policy create thru Resource B.
My terraform version is 11.7
Any help to solve this is much appreciated.