在Terraform销毁上找不到数据外部源结果

时间:2019-10-14 23:47:10

标签: terraform

您如何将Data External Source用于输出?

根据这两个问题,由于depends_on是不可能的,在这种情况下我需要。我没办法解决。

https://github.com/hashicorp/terraform/issues/16728 https://github.com/hashicorp/terraform/issues/11806

之所以需要depends_on是因为data集团是在resource之前运行的,在这种情况下,我们首先需要resource

# Script allocating resources via internal API call
resource "null_resource" "allocate-resource" {
  provisioner "local-exec" {
    command = "python ${path.module}/scripts/api_allocation.py"
  }
}

# API call to list the resources created in previous bloc
data "external" "params" {
  program = ["python", "${path.module}/scripts/api_params.py"]
  depends_on = ["null_resource.allocate-resource"]
}

# Output used by next layer to deploy a VPC
output "vpc_net_id" {
  value = "${data.external.params.result["vpc_net_id"]}"
}

terraform planterraform apply可以工作,但是我不能将其用于terraform destroy

错误是:

1 error occurred:
    module.auto_subnetting.output.vpc_net_id: Resource 'data.external.params'
    does not have attribute 'result' for variable 'data.external.params.result'

我目前发现的唯一解决方法是在销毁之前用空字符串替换

output "vpc_net_id" {
  value = ""
}

NB:客户暂时停留在terraform 0.11上。但是也欢迎使用0.12解决方案。

0 个答案:

没有答案