Terraform version 0.13.7
I have a resource which uses a provider that is configured using the outputs of a module. According to the state file, my dependent resource directly depends on the resource of that module:
module "service_account_old" { ... }
provider "kafka" {
bootstrap_servers = [module.service_account_old.bootstrap_servers]
sasl_username = module.service_account_old.sasl_user
sasl_password = module.service_account_old.sasl_password
}
resource "kafka_topic" "my_topic" {
name = "my-topic"
lifecycle {
prevent_destroy = true
}
}
In the state file, I can see the dependency for the topic as "dependencies": ["module.service_account_old.restapi_object.service_account"]
Now, I want to replace the old module with a new one, so I have applied the following:
module "service_account_old" { ... }
module "service_account_new" { ... } # Has no references to old module
provider "kafka" {
bootstrap_servers = [module.service_account_new.bootstrap_servers]
sasl_username = module.service_account_new.sasl_user
sasl_password = module.service_account_new.sasl_password
}
resource "kafka_topic" "my_topic" {
name = "my-topic"
lifecycle {
prevent_destroy = true
}
}
Even after the apply, the kafka_topic dependency still points to the old module, and thus when I attempt to destroy the old module (which I have to do with a manual target since it has a nested provider), it also tries to destroy the kafka_topic resource, which is blocked due to it’s lifecycle config.
My question is, why does the topic resource still have the old module resources as a dependency? Is there some way for me to change this dependency without destroying the kafka_topic resource?