Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cycle error when using create_before_destroy with depends_on referencing a module #26166

Closed
lakshmi-gopalakrishnan opened this issue Sep 8, 2020 · 2 comments · Fixed by #26186
Labels
bug confirmed a Terraform Core team member has reproduced this issue core v0.13 Issues (primarily bugs) reported against v0.13 releases

Comments

@lakshmi-gopalakrishnan
Copy link

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)

@jbardin
Copy link
Member

jbardin commented Sep 8, 2020

Hi @laks1206

Thanks for reporting this, and for the example.
I'll also add that since test_service always shows changes in the plan, without any modifications to the user_updates you will get an error in the form of:

provider "X" changed the planned action from
CreateThenDelete to DeleteThenCreate.

This will take a little more investigation to determine if they are related or not.

@jbardin jbardin added bug confirmed a Terraform Core team member has reproduced this issue core labels Sep 8, 2020
@jbardin jbardin changed the title Cycle error : null resource with create_before_destroy dependency Cycle error when using create_before_destroy with depends_on referencing a module Sep 9, 2020
@jbardin jbardin added the v0.13 Issues (primarily bugs) reported against v0.13 releases label Sep 9, 2020
@ghost
Copy link

ghost commented Oct 13, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked as resolved and limited conversation to collaborators Oct 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug confirmed a Terraform Core team member has reproduced this issue core v0.13 Issues (primarily bugs) reported against v0.13 releases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants