您如何将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 plan
和terraform 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解决方案。