Terraform 14.2: 'Error: Invalid index: This value does not have any indices' on destroy-time provisioner on a destroy-time resource

Terraform 14.2: 'Error: Invalid index: This value does not have any indices' on destroy-time provisioner on a destroy-time resource

我有一个创建配置器和一个销毁配置器。我读到显然,触发器可能会解决这个问题,所以它们被集成在这里,但是虽然这成功地构建了资源,但它不会让它们破坏这个 module.thingx.null_resource.script-stuff 资源。 我不确定我在这里是否正确使用了触发器,更令人困惑的是创建时间应用工作正常,但销毁时间应用失败并出现上述错误。

这是显然错误所指的模块空资源;包括创建和销毁时间供应器:

resource "null_resource" "script-stuff" {

### -- testing triggers
  triggers = {
     dns_zones = var.dns_zones[each.key]
     dnat_ip = google_compute_instance.server[each.key].network_interface.0.access_config.0.nat_ip
     pem = tls_private_key.node_ssh[each.key].private_key_pem
  } ### -- end testing
  
  depends_on = [google_compute_instance.server, google_project_iam_member.list-sa]
  for_each   = var.list_map

  provisioner "remote-exec" {
    when = create
    inline = [
      "cat ${var.dns_zones[each.key]} > /dev/null",
      "sensitive-script.sh --create"
    ]
    connection {
      type        = "ssh"
      host        = google_compute_instance.server[each.key].network_interface[0].access_config[0].nat_ip
      user        = "common-user"
      private_key = tls_private_key.node_ssh[each.key].private_key_pem
    }
  }

   provisioner "remote-exec" {
     when = destroy
     inline = [
      # "echo ${var.dns_zones[each.key]} > /dev/null", #<-- this doesn't work when terraform is destroying
      "echo ${self.triggers.dns_zones[each.key]} > /dev/null",
       "sensitive-script.sh --destroy"
     ]
     connection {
       type        = "ssh"
       #host        = google_compute_instance.server[each.key].network_interface[0].access_config[0].nat_ip #<-- this doesn't work when terraform is destroying
       host        = self.triggers.dnat_ip
       user        = "common-user"
       #private_key = tls_private_key.node_ssh[each.key].private_key_pem #<-- this doesn't work when terraform is destroying
       private_key = self.triggers.pem
     }
   }

 }

destroy 触发供应器 不支持变量 如本 GitHub 问题所述:

所以你不能在 "echo ${var.dns_zones[each.key]} > /dev/null" 中有任何变量。