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

Deposed resources do not call when = destroy provisioners #31266

Closed
arbourd opened this issue Jun 17, 2022 · 3 comments
Closed

Deposed resources do not call when = destroy provisioners #31266

arbourd opened this issue Jun 17, 2022 · 3 comments
Labels
bug new new issue not yet triaged

Comments

@arbourd
Copy link

arbourd commented Jun 17, 2022

When using create_before_destroy lifecycle hook, it appears that remote-exec provisioners are not called. Here's the pattern I'm trying to adapt (due to Equinix Metal not having a shutdown script function):

  1. A new metal_device is brought up
  2. A new null_resource is brought up to house the triggers
  3. The deposed null_resource is destroyed, executing the remote-exec which ensures that the node leaves the consul pool
  4. The deposed metal_device is destroyed

Terraform Version

Terraform v1.2.3
on darwin_arm64
+ provider registry.terraform.io/equinix/metal v3.3.0-alpha.4
+ provider registry.terraform.io/hashicorp/null v3.1.1

Terraform Configuration Files

resource "metal_device" "device" { 
  # ...

  lifecycle {
    create_before_destroy = true
  }
}

resource "null_resource" "device" {
  triggers = {
    name = metal_device.device.hostname
    host = metal_device.device.access_public_ipv4
    key  = var.metal_ssh_private_key
  }

  provisioner "remote-exec" {
    when = destroy

    inline = [
      "/opt/bin/consul leave"
    ]
    on_failure = continue

    connection {
      type        = "ssh"
      user        = "core"
      host        = self.triggers.host
      private_key = self.triggers.key
    }
  }

  lifecycle {
    create_before_destroy = true
  }
}

Debug Output

Nothing of immediately value popped up here.

Expected Behavior

The remote-exec script should run.

Actual Behavior

The remote-exec does not run.

metal_device.device: Creation complete after 10m9s [id=6d5385ee-128f-47f8-aaf5-338a3824790e]
null_resource.device: Creating...
null_resource.device: Creation complete after 0s [id=5852924778467424020]
null_resource.device (deposed object 1ec4e06d): Destroying... [id=7715824139324971453]
null_resource.device: Destruction complete after 0s
metal_device.device (deposed object 6307fae0): Destroying... [id=3c3711ac-18c6-4bd5-a174-be9ddd074b73]
metal_device.device: Destruction complete after 1s

There is no indication that the SSH script ran. Removing the lifecycle shows that it does:

null_resource.worker["da/0"]: Destroying... [id=5882924178467424020]
null_resource.worker["da/0"]: Provisioning with 'remote-exec'...
null_resource.worker["da/0"] (remote-exec): Connecting to remote host via SSH...
null_resource.worker["da/0"] (remote-exec):   Host: 1.1.1.1
null_resource.worker["da/0"] (remote-exec):   User: user
null_resource.worker["da/0"] (remote-exec):   Password: false
null_resource.worker["da/0"] (remote-exec):   Private key: true
null_resource.worker["da/0"] (remote-exec):   Certificate: false
null_resource.worker["da/0"] (remote-exec):   SSH Agent: false
null_resource.worker["da/0"] (remote-exec):   Checking Host Key: false
null_resource.worker["da/0"] (remote-exec):   Target Platform: unix
null_resource.worker["da/0"] (remote-exec): Connected!
null_resource.worker["da/0"] (remote-exec): Graceful leave complete
null_resource.worker["da/0"]: Destruction complete after 5s

Steps to Reproduce

  1. Create and apply Terraform similar to the above, where a remote-exec provision is also using the lifecycle hook.

Additional Context

Running in Terraform Cloud

@arbourd arbourd added bug new new issue not yet triaged labels Jun 17, 2022
@arbourd arbourd changed the title Deposed resources do not called when = destroy provisioners Deposed resources do not call when = destroy provisioners Jun 17, 2022
@jbardin
Copy link
Member

jbardin commented Jun 17, 2022

Thanks for filing the issue @arbourd. We are tracking this issue in #13549.

@jbardin jbardin closed this as completed Jun 17, 2022
@arbourd
Copy link
Author

arbourd commented Jun 17, 2022

Oh sorry, I searched but didn't find anything. Appreciate it @jbardin 🙏

@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug new new issue not yet triaged
Projects
None yet
Development

No branches or pull requests

2 participants