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 on module output/input when input used in destroy provisioner #14548

Closed
cfromm1911 opened this issue May 16, 2017 · 12 comments · Fixed by #24083
Closed

Cycle error on module output/input when input used in destroy provisioner #14548

cfromm1911 opened this issue May 16, 2017 · 12 comments · Fixed by #24083
Assignees
Labels
bug config v0.11 Issues (primarily bugs) reported against v0.11 releases v0.12 Issues (primarily bugs) reported against v0.12 releases

Comments

@cfromm1911
Copy link

It seems this issue i'm running into should have been fixed by 1835/1855. However, I am still getting a cycle when I have two modules, one with an output that the other is taking as an input. The only thing that I can tell differentiates me from 1835/1855 is that the input is used in a destroy provisioner.

Given:
main.tf

module "a_module" {
  source = "./a_module"
}
module "b_module" {
  source = "./b_module"
  a_id = "${module.a_module.a_output}"
}

a_module/main.tf

resource "null_resource" "a" {
}
output "a_output" {
  value = "${null_resource.a.id}"
}

b_module/main.tf

variable "a_id" {}
resource "null_resource" "b" {
  provisioner "local-exec" {
    command = "echo ${var.a_id}"
  }
  provisioner "local-exec" {
    when = "destroy" 
    command = "echo ${var.a_id}"
  }
}

Apply works

>terraform apply
module.a_module.null_resource.a: Creating...
module.a_module.null_resource.a: Creation complete (ID: 7834569308481174192)
module.b_module.null_resource.b: Creating...
module.b_module.null_resource.b: Provisioning with 'local-exec'...
module.b_module.null_resource.b (local-exec): Executing: cmd /C "echo 7834569308481174192"
module.b_module.null_resource.b (local-exec): 7834569308481174192
module.b_module.null_resource.b: Creation complete (ID: 6375952926384638186)

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.

The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the `terraform show` command.

State path:

Destroy calls Cycle!

>terraform destroy
Do you really want to destroy?
  Terraform will delete all your managed infrastructure.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes

null_resource.a: Refreshing state... (ID: 7834569308481174192)
null_resource.b: Refreshing state... (ID: 6375952926384638186)
Error applying plan:

1 error(s) occurred:

* Cycle: module.a_module.null_resource.a (destroy), module.a_module.output.a_output, module.b_module.var.a_id, module.b_module.null_resource.b (destroy)

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

Could the destroy graph just destroy the one with destroy provisioners first?

@mumblez
Copy link
Contributor

mumblez commented May 19, 2017

I have the same issue, plan and apply work fine, plan -destroy and apply gives cycle errors.
If I remove the resources from the terraform file and do a normal plan and apply, it destroys correctly without error.
(v 0.9.5)

@FearTheBadger
Copy link

(v0.9.8) This issue is still present and rather detrimental to clean up.
We have values stored in Consul and pull those values in via a module. Because of these errors, we now those variables have to be hard coded into our tfvars file.

@uplex-lf
Copy link

Just ran into this issue.
(v0.9.10)

@paulwelch
Copy link

(v0.9.11) Same here

@kaii-zen
Copy link

kaii-zen commented Aug 1, 2017

Getting this as well... 0.9.11

@aeneasr
Copy link

aeneasr commented Nov 16, 2017

Same issue on 0.10.8

@delphyne
Copy link

I'm hitting it on 0.11.1. I was able to get around it by issuing destroy target=(one of the two it says is a cycle), then the other.

@Dmitry1987
Copy link

same, v0.11.7

@apparentlymart apparentlymart added config and removed core labels Nov 7, 2018
@simonbirtles
Copy link

simonbirtles commented Jan 13, 2019

I see the same on v0.11.8 but with apply when a new resource is required (destroy then create) - Custom provider which works when no provisioner used.


-/+ aci_fvAp.app_profile (new resource required)
      id:             "uni/tn-TEN_TENANT/ap-AP_PROV_TEST_1" => <computed> (forces new resource)
      desc:           "desc 3" => "desc 3"
      dn:             "uni/tn-TEN_TENANT/ap-AP_PROV_TEST_1" => <computed>
      name:           "AP_PROV_TEST_1" => "AP_PROV_TEST_2" (forces new resource)
      priority_level: "unspecified" => "unspecified"
      tenant_id:      "uni/tn-TEN_TENANT" => "uni/tn-TEN_TENANT"

Plan: 1 to add, 0 to change, 1 to destroy.

    provider "aci" {
        username = "..."
        password = "..."
        apic = "0.0.0.0"
        sync_delay = 500
        allow_unverified_ssl = false  
    }

    data "aci_fvTenant" "tenant" {
        name    = "TEN_TENANT"
    }
    resource "aci_fvAp" "app_profile" {
        tenant_id               = "${data.aci_fvTenant.tenant.id}"
        name                    = "AP_PROV_TEST_2"
        desc                    = "desc 3"

        provisioner "local-exec" {
            command = "echo Create ${aci_fvAp.app_profile.tenant_id} >> output.txt"
        }

        provisioner "local-exec" {
            on_failure = "continue"
            when = "destroy"
            command = "echo Destroy ${aci_fvAp.app_profile.tenant_id} >> output.txt"
        }
    }

    resource "null_resource" "trigger" {

        triggers {
            name = "${aci_fvAp.app_profile.tenant_id}"
        }

        provisioner "local-exec" {
            command = "echo Trigger Change ${aci_fvAp.app_profile.tenant_id} >> output.txt"
        }

    }

On apply the "aci_fvAp" "name" which causes a new resource to be created on apply, cycle occurs

* Cycle: aci_fvAp.app_profile, aci_fvAp.app_profile (destroy)

Terraform v0.11.8

  • provider.aci (unversioned)
  • provider.null v1.0.0

@elfenlaid
Copy link

Same issue on v0.12.0 and v0.12.1

@meabed
Copy link

meabed commented Jun 17, 2019

Yes, same issue here, also happen when i change and re-apply.

@hashibot hashibot added v0.11 Issues (primarily bugs) reported against v0.11 releases v0.12 Issues (primarily bugs) reported against v0.12 releases labels Aug 22, 2019
@jbardin jbardin self-assigned this Dec 13, 2019
@ghost
Copy link

ghost commented Apr 1, 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 and limited conversation to collaborators Apr 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug config v0.11 Issues (primarily bugs) reported against v0.11 releases v0.12 Issues (primarily bugs) reported against v0.12 releases
Projects
None yet
Development

Successfully merging a pull request may close this issue.