-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Cycle error when using create_before_destroy with depends_on referencing a module #26166
Description
Version
Terraform v0.13.0
+ provider registry.terraform.io/hashicorp/aws v3.4.0
+ provider registry.terraform.io/hashicorp/external v1.2.0
+ provider registry.terraform.io/hashicorp/null v2.1.2
Usecase
We have two modules A and B. A depends on module B. Module A has a create_before_destroy lifecycle policy on it. Module B contains a null resource. The initial creation of the resource using module A goes through fine but any further update runs into cycle error.
This was tested in terraform 0.12.26 and the dependency was specified using module_depends_on variable and there were no issues.
Terraform files
Folder Structure
- moduleA /
moduleA.tf
- moduleB /
moduleB.tf
test.py
- example /
example.tf
moduleA.tf
module test_package {
source = "../moduleB"
}
resource "aws_sns_topic" "user_updates" {
lifecycle {
create_before_destroy = true
}
depends_on = [module.test_package]
name = "user-updates-topic"
}
moduleB.tf
resource "null_resource" "test_service" {
triggers = {
always_run = "${timestamp()}"
}
provisioner "local-exec" {
working_dir = path.module
interpreter = ["python3"]
command = "test.py"
}
}
test.py
def main():
print("hello world")
if __name__ == "__main__":
main()
example.tf
module "test_module" {
source = "../moduleA"
}
Steps to Reproduce
Apply example.tf and it should go through fine. Change the sns topic name in moduleA and run the terraform apply again and it will run into cycle error.
Expected Behaviour
Updates to go through without errors
Actual Behaviour
Error: Cycle: module.test_module.aws_sns_topic.user_updates, module.test_module.aws_sns_topic.user_updates (destroy deposed d55db4bf), module.test_module.module.test_package.null_resource.test_service (destroy deposed 84aabca6), module.test_module.module.test_package (close)