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

null_resource and templatefile using with deposed elements raise cycle error #23957

Closed
okgolove opened this issue Jan 26, 2020 · 1 comment · Fixed by #24083
Closed

null_resource and templatefile using with deposed elements raise cycle error #23957

okgolove opened this issue Jan 26, 2020 · 1 comment · Fixed by #24083
Labels
bug core v0.12 Issues (primarily bugs) reported against v0.12 releases

Comments

@okgolove
Copy link

okgolove commented Jan 26, 2020

Terraform Version

Terraform v0.12.20

Terraform Configuration Files

resource "digitalocean_droplet" "test" {
  count  = 5
  image  = 57114112
  name   = "test-${format("%03d", count.index + 1)}"
  region = "ams3"
  private_networking = true
  monitoring = true
  size       = "s-2vcpu-2gb"
  tags       = ["test"]

  lifecycle {
    create_before_destroy = true
  }

  connection {
    host        = self.ipv4_address
    type        = "ssh"
    user        = "developer"
    private_key = file(pathexpand(var.private_key_path))
    certificate = file(pathexpand(var.certificate_key_path))
  }
}

resource "digitalocean_droplet" "haproxy_test" {
  count  = 1
  image  = 57065468
  name   = "haproxy-test-${format("%03d", count.index + 1)}"
  region = "ams3"
  private_networking = true
  monitoring         = true
  size = "s-2vcpu-2gb"
  tags = ["haproxy-test"]

  lifecycle {
    create_before_destroy = true
  }

  connection {
    host        = self.ipv4_address
    type        = "ssh"
    user        = "developer"
    private_key = file(pathexpand(var.private_key_path))
    certificate = file(pathexpand(var.certificate_key_path))
  }
}

resource "null_resource" "haproxy_test_config" {
  count = 1

  triggers = {
    droplets = templatefile("${path.module}/templates/haproxy/test.tpl", {droplets = digitalocean_droplet.test})
    haproxy  = digitalocean_droplet.haproxy_test[count.index].id
  }

  lifecycle {
    create_before_destroy = true
  }

  connection {
    host        = digitalocean_droplet.haproxy_test[count.index].ipv4_address
    user        = "developer"
    private_key = file(pathexpand(var.private_key_path))
    certificate = file(pathexpand(var.certificate_key_path))
  }

  provisioner "file" {
    content     = templatefile("${path.module}/templates/haproxy/test.tpl", {droplets = digitalocean_droplet.test})
    destination = "/tmp/haproxy"
  }

  provisioner "remote-exec" {
    inline = [
      "sudo cp /tmp/haproxy /etc/haproxy/haproxy.cfg",
      "sudo systemctl reload haproxy",
    ]
  }
}

test.tpl:

backend torg
    mode http
    http-check expect status 200
    option httpchk GET /health-check
    balance roundrobin
    %{ for test in droplets ~}
server ${test.name} ${test.ipv4_address_private}:8080 check fall 3 rise 2
    %{ endfor }

Debug Output

https://gist.github.com/okgolove/2a126205e8bf92871c5dbc1cbdccd069

Crash Output

Expected Behavior

test droplet has been destroyed, null_resource has been reprovisioned

Actual Behavior

Error: Cycle: null_resource.haproxy_test_config[0], null_resource.haproxy_test_config[0] (destroy deposed bca85ac3), digitalocean_droplet.test[2] (destroy)

Steps to Reproduce

  1. terraform init
  2. terraform apply
  3. Reduce test's count to 4
  4. terraform apply

Additional Context

References

@hashibot hashibot added bug core v0.12 Issues (primarily bugs) reported against v0.12 releases labels Jan 28, 2020
@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.

2 participants