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

Provisioner when destroy cycle #23196

Closed
eddytrex opened this issue Oct 26, 2019 · 2 comments · Fixed by #24083
Closed

Provisioner when destroy cycle #23196

eddytrex opened this issue Oct 26, 2019 · 2 comments · Fixed by #24083
Assignees
Labels
bug core v0.12 Issues (primarily bugs) reported against v0.12 releases

Comments

@eddytrex
Copy link

Terraform Version

terraform -v
Terraform v0.12.12
+ provider.null v2.1.2

Terraform Configuration Files

Module 1:

variable A {
    type = map(string)
}

resource "null_resource" "A" {
    for_each = var.A
    triggers = {
        v=each.value
    }
    provisioner "local-exec" {
        command = "echo Create Resource ${each.key}-${each.value} "
    } 
}

output "Object" {
  value = [for k,v in null_resource.A:
      {
          key   = k
          value = var.A[k]
          AID   = v.id
      }
  ]
}

Module 2:

variable "A" {
  type = list(object({
      key   = string
      value = string
      AID   = string
    }))
}

variable "Count_configs" {type = number}

resource "null_resource" "Config" {
  count = var.Count_configs
  triggers = {
    v = var.A[count.index].value
  } 
  provisioner "local-exec" {
    command = "echo Configure ${var.A[count.index].key}-${var.A[count.index].value} "
  }

  provisioner "local-exec" {
    when = "destroy"
    command = "echo Destroy config ${var.A[count.index].key}-${var.A[count.index].value} "
  }
}

Module 3:

variable A {
    type = map(string)
    default = {
        Key1 = "V1"
        Key2 = "V2"
        Key3 = "V3"
    }
}

module "Resources" {
  source = "../module1"
  A      = var.A
}

module "Configs" {
  source        = "../module2"
  Count_configs = length(var.A)
  A             = module.Resources.Object
}

v1.tfvars

A = {
    Key1 = "V10"
    Key2 = "V20"
    Key3 = "V30"
}

Debug Output

Crash Output

https://gist.github.com/eddytrex/d2be154d5172b9053dcb2c7ba62c3037

Expected Behavior

In the second apply it should: destroy the the null_resource.Config resource with the previous values, destroy the null_resource.A with the previous values, recreate null_resource.A and lastly recreate null_resource.Config

Actual Behavior

module.Resources.null_resource.A["Key3"]: Refreshing state... [id=3417427815421531061]
module.Resources.null_resource.A["Key1"]: Refreshing state... [id=148907161230582130]
module.Resources.null_resource.A["Key2"]: Refreshing state... [id=1963858428133357225]
module.Configs.null_resource.Config[0]: Refreshing state... [id=3303131520289021751]
module.Configs.null_resource.Config[2]: Refreshing state... [id=1900602850461495067]
module.Configs.null_resource.Config[1]: Refreshing state... [id=6212963663486443828]

Error: Cycle: module.Resources.null_resource.A["Key1"], module.Resources.null_resource.A["Key2"], module.Resources.null_resource.A["Key2"] (destroy), module.Configs.null_resource.Config[0] (destroy), module.Configs.null_resource.Config[2] (destroy), module.Resources.null_resource.A["Key1"] (destroy), module.Resources.null_resource.A["Key3"], module.Resources.output.Object, module.Configs.var.A, module.Configs.null_resource.Config[1] (destroy), module.Resources.null_resource.A["Key3"] (destroy)

Steps to Reproduce

Please list the full steps required to reproduce the issue, for example:

  1. terraform init
  2. terraform apply -auto-approve module3
  3. terraform apply -var-file="v1.tfvars" -auto-approve module3

Additional Context

If you remove the provisioner in the module2.null_resource.Config:

provisioner "local-exec" {
    when = "destroy"
    command = "echo Destroy config ${var.A[count.index].key}-${var.A[count.index].value} "
  }

it works, also if you add

  lifecycle {
    create_before_destroy = true
  }

But it does not execute the: echo Destroy config ${var.A[count.index].key}-${var.A[count.index].value }

I don't know if is possible to run echo Destroy config ${var.A[count.index].key}-${var.A[count.index].value } with the previous values because there are not in the state file (maybe it should render the command when apply).

Thanks.

References

@hashibot hashibot added bug core v0.12 Issues (primarily bugs) reported against v0.12 releases labels Oct 28, 2019
@eddytrex
Copy link
Author

eddytrex commented Nov 1, 2019

The issue is present in also in in the version 0.12.13

@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 core v0.12 Issues (primarily bugs) reported against v0.12 releases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants