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


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

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" ]


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







%{if url == null}

cat <<EOF |




curl ${url} |

%{~ endif ~}

kubectl $OPERATOR\

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

-f -



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 )