# Terraform null\_resources does not detect changes , I have to manually do taint to recreate it

**URL:** <https://discuss.hashicorp.com/t/terraform-null-resources-does-not-detect-changes-i-have-to-manually-do-taint-to-recreate-it/23443>\
**Category:** Terraform\
**Tags:** k8s\
**Created:** [April 21, 2021, 2:47pm UTC](https://discuss.hashicorp.com/t/terraform-null-resources-does-not-detect-changes-i-have-to-manually-do-taint-to-recreate-it/23443 "2021-04-21T14:47:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Snehil03](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/snehil03/32/15574_2.png) [@Snehil03](https://discuss.hashicorp.com/u/Snehil03)\
**Post date:** [April 21, 2021, 2:47pm UTC](https://discuss.hashicorp.com/t/terraform-null-resources-does-not-detect-changes-i-have-to-manually-do-taint-to-recreate-it/23443/1 "2021-04-21T14:47:35Z")

</div>

Hello,

I am using null\_resource for the generation of few modules , I am running terraform plan,  
these resources does not exist still terraform plan not able to detect , i have to manually do taint like below command to get the resource created for me .

terraform taint module.ingress.module.letsencrypt\_issuers.null\_resource.kubernetes\_manifest

how I can make these resource triggered automatically as part of terraform plan/apply

---

<div class="post-metadata">

**Author:** ![jbardin](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/jbardin/32/3325_2.png) [@jbardin](https://discuss.hashicorp.com/u/jbardin)\
**Post date:** [April 21, 2021, 3:08pm UTC](https://discuss.hashicorp.com/t/terraform-null-resources-does-not-detect-changes-i-have-to-manually-do-taint-to-recreate-it/23443/2 "2021-04-21T15:08:53Z")

</div>

Hi @Snehil03,

We would need to see a more complete example of the configuration in order to know what is happening. Any change to the `triggers` attribute of `null_resource.kubernetes_manifest` will cause it to be replaced.

My only guess would be that the data referenced from `null_resource.kubernetes_manifest` is statically known in the config and not changing, even though it may also be used in a resource which is being replaced. If that is the case, the solution is to ensure that any resource you want to trigger the null resource replacement has a computed attribute somehow combined into the `triggers` map.

---

<div class="post-metadata">

**Author:** ![Snehil03](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/snehil03/32/15574_2.png) [@Snehil03](https://discuss.hashicorp.com/u/Snehil03)\
**Post date:** [April 21, 2021, 3:20pm UTC](https://discuss.hashicorp.com/t/terraform-null-resources-does-not-detect-changes-i-have-to-manually-do-taint-to-recreate-it/23443/3 "2021-04-21T15:20:56Z")

</div>

Hello @jbardin  
I am using the solution suggested as part of these thread,

> [@Resolve interpolation issue for terraform code as part of upgrade to version 0.13.2](https://discuss.hashicorp.com/t/resolve-interpolation-issue-for-terraform-code-as-part-of-upgrade-to-version-0-13-2/20891/9):
>
> Thanks @apparentlymart for giving some time for these issue. I made the changes what you have suggested for provisioner\_script added as part of trigger and executed terraform apply, I ended with below error stack for missing map elements during terraform apply. module.k8s\_cluster\_config.module.k8s\_pod\_security\_policy.null\_resource.kubernetes\_manifest: Destroying... [id=2405609833578210128] module.ingress.module.wildcard-domain-certificate.module.k8s\_manifest\_domain\_wildcard.null\_resource.kube…

this is how , I am invoking trigger

```
    locals {
      template_input = {
      url = var.url
      manifest = var.data
      validate = var.validate
      namespace = var.namespace
      kubeconfig = var.kubeconfig
      }
    }

resource "null_resource" "kubernetes_manifest" {
  

  triggers = {
    manifest_sha1 = sha1(jsonencode(var.trigger == null ? local.template_input : var.trigger))
    provisioner_script = templatefile("${path.module}/kubectl_apply.tpl.sh", local.template_input)
  }

  provisioner "local-exec" {
    environment = {
      KUBECONFIG = "/tmp/kubeconfig_${uuid()}"
    }
    command = self.triggers.provisioner_script
    //command = templatefile("${path.module}/kubectl_apply.tpl.sh", local.template_input)
  }

```

---

<div class="post-metadata">

**Author:** ![jbardin](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/jbardin/32/3325_2.png) [@jbardin](https://discuss.hashicorp.com/u/jbardin)\
**Post date:** [April 22, 2021, 1:05pm UTC](https://discuss.hashicorp.com/t/terraform-null-resources-does-not-detect-changes-i-have-to-manually-do-taint-to-recreate-it/23443/4 "2021-04-22T13:05:58Z")

</div>

Thanks @Snehil03, but unfortunately that is still not sufficient to determine what is going on, as we need to be able to see how all the input to the triggers block are evaluated, and exactly what commands are being executed.

When applying a change, the null resource will be replaced if any of the values in `triggers` have changes. If the resource is not being replaced when you expect it, it means that the values for `manifest_sha1` and `provisioner_script` are identical to those that are named in the state. If `var.trigger`, `local.template_input` and `kubectl_apply.tpl.sh` have no changes, then the resource will not be replaced, so I would start buy inspecting how those values are derived.

---

<div class="post-metadata">

**Author:** ![Snehil03](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/snehil03/32/15574_2.png) [@Snehil03](https://discuss.hashicorp.com/u/Snehil03)\
**Post date:** [April 26, 2021, 9:38pm UTC](https://discuss.hashicorp.com/t/terraform-null-resources-does-not-detect-changes-i-have-to-manually-do-taint-to-recreate-it/23443/5 "2021-04-26T21:38:22Z")

</div>

Thanks @jbardin : After your detailed description , I had revalidated my entire code with respect to trigger, made few changes to make it work , It seems to be working now.
