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

Tainted null_resource with destroy provisioner does not run the destroy command. #14403

Closed
zhaohanweng opened this issue May 11, 2017 · 18 comments
Labels
bug provisioner/local-exec v0.9 Issues (primarily bugs) reported against v0.9 releases v0.10 Issues (primarily bugs) reported against v0.10 releases v0.11 Issues (primarily bugs) reported against v0.11 releases v0.12 Issues (primarily bugs) reported against v0.12 releases

Comments

@zhaohanweng
Copy link

Hi there,

I am using destroy provisioner on null_resource, this works great on terraform destroy. When I try to taint this resource and re-apply, the destroy script does not run. Is this expected?

Terraform Version

Terraform v0.9.5

Affected Resource(s)

  • null_resource

Terraform Configuration Files

{
  "provider": {
    "azurerm": {
      "client_id": "${var.client_id}",
      "client_secret": "${var.client_secret}",
      "subscription_id": "${var.subscription_id}",
      "tenant_id": "${var.tenant_id}"
    }
  },
  "resource": {
    "null_resource": {
      "test2_add_group_role": {
        "provisioner": [
          {
            "local-exec": {
              "command": "\naz ad group create --display-name dev-group --mail-nickname dev-group\n\n"
            }
          },
          {
            "local-exec": {
              "command": "\naz ad group delete -g dev-group\n\n",
              "on_failure": "continue",
              "when": "destroy"
            }
          }
        ]
      }
    }
  }
}

Expected Behavior

The destroy provisioner should run when the resource is tainted, and re-applied.

Actual Behavior

The destroy provisioner did not run.

Steps to Reproduce

  1. terraform taint null_resource.test2_add_group_role
  2. terraform plan
  3. terraform apply
@burdiyan
Copy link

burdiyan commented Jun 7, 2017

Destroy provisioners neither run if null_resource is removed or commented out from the .tf file. Maybe the information about destroy provisioning should be stored in the state file somehow, so that Terraform will now what to do without looking into the resource itself.

@elafarge
Copy link

That would be great indeed, I worked around the issue by putting by destroy provisioner on "real" resources that are destroyed along with my null_resources for now but that's not ideal and clear for everyone in my team.

@bbakersmith
Copy link

+1

@borsboom
Copy link

Since it's been a while, I can confirm that this is still happening on version 0.11.1.

@h4m24
Copy link

h4m24 commented Jan 12, 2018

+1

2 similar comments
@MagicMicky
Copy link

+1

@tata2000
Copy link

tata2000 commented Jul 5, 2018

+1

@piotr-napadlek
Copy link

+1

@apparentlymart
Copy link
Contributor

Please do not post "+1" comments, since they just create noise for those monitoring this issue and don't contribute to prioritization (because we can't report on them).

Instead, leave a 👍 reaction on the original comment of this issue, which we can and do report on as an input to prioritization.

@scross01
Copy link
Contributor

scross01 commented Nov 5, 2018

This issue doesn't seem to be limited to just the null_resource. I have a real resource that has a destroy time remote-exec which works fine on destroy, or when setting the resource count to 0, but does not run when manually tainting the resource.

@Priteshkal
Copy link

Have we gotten any traction on this?

I also have the same problem as @scross01 and @zhaohanweng.

Suppose instead of using taint, I used a terraform destroy -target=xxx, but this is also destroying the dependent resources connected to the target xxx. I want the ability to be able to either taint specific resources and have my on destroy "remote-exec" run when I do plan and apply or the ability to destroy just specific resources using -target.

How can I go about this?

@tholu
Copy link

tholu commented Feb 19, 2019

I'm using terraform taint to mark resources for recreating, used e.g. for redeployments. This issue bites me as well here, as destroy time provisioners only seem to run when terraform destroy is used, not with terraform taint. This is unexpected, as the resource is also destroyed and recreated when tainting it. Or is there any other reasoning behind it?

@hashibot hashibot added v0.10 Issues (primarily bugs) reported against v0.10 releases v0.11 Issues (primarily bugs) reported against v0.11 releases v0.12 Issues (primarily bugs) reported against v0.12 releases v0.9 Issues (primarily bugs) reported against v0.9 releases labels Aug 29, 2019
@josh-pritchard-fcx
Copy link

Is there any traction in on this issue? I feel like destroy provisioner information should be stored in the state to resolve this.

@AshMenhennett
Copy link

Use case that is causing issues for me is an on-destroy local-exec that needs to be triggered when a generic resource type is destroyed via GitOps based workflow (config dropped).

@mgzenitech
Copy link

Definitely what our team needs too! We expected to use null_resource with local provisioner as a cleanup script for another resource (which creates physical files but does not delete them if destroyed)

@haidaraM
Copy link

haidaraM commented Mar 5, 2021

Just wondering if there is any plan to fully support taint on null_resource with destroy time provisioner ? This issue is there for almost 4 years

@apparentlymart
Copy link
Contributor

Hi all,

This isn't an issue with any particular resource type or provider, and is instead an artifact of the design of destroy-time provisioners, which in current Terraform are really only for situations where an object is being destroyed as part of either a full destroy (terraform destroy) or a "replace" operation (which includes both a destroy and a create).

We've been using #13549 as an umbrella issue for all of these feature requests for destroy-time provisioners to be run in more situations, and so I'm going to close this one just to consolidate the discussion over there. We are currently only really maintaining the behavior of provisioners as they currently exist and not investing further in the concept, because provisioners are a last resort. However, we'll keep the other issue open to track the underlying use-case for whatever mechanisms will eventually replace all of the remaining reasons to use provisioners.

If you upvoted here and are still interested in this, please transfer your upvote to #13549. Thanks!

@apparentlymart apparentlymart closed this as not planned Won't fix, can't repro, duplicate, stale Sep 28, 2022
@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 Oct 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug provisioner/local-exec v0.9 Issues (primarily bugs) reported against v0.9 releases v0.10 Issues (primarily bugs) reported against v0.10 releases v0.11 Issues (primarily bugs) reported against v0.11 releases v0.12 Issues (primarily bugs) reported against v0.12 releases
Projects
None yet
Development

No branches or pull requests