# Terraform destroy time provisioner not working after upgrade to v0.13.2

**URL:** <https://discuss.hashicorp.com/t/terraform-destroy-time-provisioner-not-working-after-upgrade-to-v0-13-2/21397>\
**Category:** Terraform\
**Tags:** k8s\
**Created:** [February 25, 2021, 1:45pm UTC](https://discuss.hashicorp.com/t/terraform-destroy-time-provisioner-not-working-after-upgrade-to-v0-13-2/21397 "2021-02-25T13:45:29Z")\
**Posts on this page:** 1\
**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:** [February 25, 2021, 1:45pm UTC](https://discuss.hashicorp.com/t/terraform-destroy-time-provisioner-not-working-after-upgrade-to-v0-13-2/21397/1 "2021-02-25T13:45:29Z")

</div>

Hello,

Destroy time provisioner does not work after migration from v0.12.29 to v0.13.2.

I am quite new to template\_input , templatefile hence were not able to resolve the issue ,  
can anyone please provide guidance to migrate these code to make it compatible 0.13.2 would be of real help,

I tried to pass the values directly instead of template\_input it gave error related to invalid var pass it should be map instead of variable … Whatever combinations I have tried these is not going through with success… I thought of keep in community to discuss so that I would be able to fix these issue seamlessly.

> Error: Invalid reference from destroy provisioner
> 
> on …/…/modules/k8s\_manifest/main.tf line 29, in resource “null\_resource” “kubernetes\_manifest”:  
> 29: command = templatefile(“${path.module}/kubectl\_apply.tpl.sh”, local.template\_input )
> 
> Destroy-time provisioners and their connection configurations may only  
> reference attributes of the related resource, via ‘self’, ‘count.index’, or  
> ‘each.key’.
> 
> References to other resources during the destroy phase can cause dependency  
> cycles and interact poorly with create\_before\_destroy.

kubectl\_apply.tpl.sh file

```
#!/usr/bin/env sh

if [-z "$DESTROY"]

then

OPERATOR="apply --validate=${validate}"

else

OPERATOR="delete"

fi

cat <<EOF > $KUBECONFIG

${kubeconfig}

EOF

%{if url == null}

cat <<EOF |

${manifest}

EOF

%{else}

curl ${url} |

%{~ endif ~}

kubectl $OPERATOR\

%{if namespace != null}--namespace ${namespace} %{endif}\

-f -

ret_code=$?

rm $KUBECONFIG

exit $ret_code

```

main.tf below :

```
  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 "local-exec" {
environment = {
  KUBECONFIG = "/tmp/kubeconfig_${uuid()}"
}
command = templatefile("${path.module}/kubectl_apply.tpl.sh", local.template_input)
  }

  provisioner "local-exec" {
when = destroy
environment = {
  KUBECONFIG = "/tmp/kubeconfig_${uuid()}"
  DESTROY = true
}
command = templatefile("${path.module}/kubectl_apply.tpl.sh", local.template_input )
  }
}

```
