title: Error: Invalid reference from destroy provisioner
body: <p>While upgrading terraform version, Facing such an error</p>
  <pre><code>    on athena.tf line 29, in resource &quot;null_resource&quot; &quot;athena_views_base_views_1&quot;:
    29:     command = &lt;&lt;EOF
    30:       AWS_DEFAULT_REGION=${local.region} AWS_ACCESS_KEY_ID=${local.aws_access_key_id} AWS_SECRET_ACCESS_KEY=${local.aws_secret_key} \
    31:       aws athena start-query-execution \
    32:         --output json \
    33:         --query-string 'DROP VIEW IF EXISTS ${each.key}' \
    34:         --query-execution-context &quot;Database=${self.triggers.database_name}&quot; \
    35:         --result-configuration &quot;OutputLocation=s3://${self.triggers.s3_bucket_query_output}&quot;
    36: EOF
  </code></pre>
  <p>Destroy-time provisioners and their connection configurations may only
  reference attributes of the related resource, via 'self', 'count.index', or
  'each.key'.</p>
  <p>References to other resources during the destroy phase can cause dependency
  cycles and interact poorly with create_before_destroy.</p>
  <p>Provider block is</p>
  <pre><code>resource &quot;null_resource&quot; &quot;athena_views_base_views_1&quot; {
    for_each = {
    for filename in fileset(&quot;${path.module}/sql-views/base/1_views/&quot;, &quot;**&quot;) :
    replace(filename, &quot;/&quot;, &quot;_&quot;) =&gt; replace(file(&quot;${path.module}/sql-views/base/1_views/${filename}&quot;),&quot;&lt;environment&gt;&quot;, &quot;${local.environment}&quot;)
    }
  
  
    triggers = {
      md5 = md5(each.value)
  
      database_name = data.terraform_remote_state.datalake.outputs.data_glue_catalog_base_name
      s3_bucket_query_output = data.terraform_remote_state.datalake.outputs.data_athena_results_bucket
    }
  
    provisioner &quot;local-exec&quot; {
      command = &lt;&lt;EOF
        AWS_DEFAULT_REGION=${local.region} AWS_ACCESS_KEY_ID=${local.aws_access_key_id} AWS_SECRET_ACCESS_KEY=${local.aws_secret_key} \
        aws athena start-query-execution \
          --output json \
          --query-string '${each.value}' \
          --query-execution-context &quot;Database=${self.triggers.database_name}&quot; \
          --result-configuration &quot;OutputLocation=s3://${self.triggers.s3_bucket_query_output}&quot;
  EOF
    }
  
    provisioner &quot;local-exec&quot; {
      when = destroy
      command = &lt;&lt;EOF
        AWS_DEFAULT_REGION=${local.region} AWS_ACCESS_KEY_ID=${local.aws_access_key_id} AWS_SECRET_ACCESS_KEY=${local.aws_secret_key} \
        aws athena start-query-execution \
          --output json \
          --query-string 'DROP VIEW IF EXISTS ${each.key}' \
          --query-execution-context &quot;Database=${self.triggers.database_name}&quot; \
          --result-configuration &quot;OutputLocation=s3://${self.triggers.s3_bucket_query_output}&quot;
  EOF
    }
  }
  </code></pre>
  <p>Can someone help???</p>