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?
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)
(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.
Just ran into this issue.
(v0.9.10)
(v0.9.11) Same here
Getting this as well... 0.9.11
Same issue on 0.10.8
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.
same, v0.11.7
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
Same issue on v0.12.0 and v0.12.1
Yes, same issue here, also happen when i change and re-apply.
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.
Most helpful comment
same, v0.11.7