gpt4 book ai didi

Terraform 外部提供者资源在计划阶段没有变量属性

转载 作者:行者123 更新时间:2023-12-05 06:33:41 24 4
gpt4 key购买 nike

当使用以下脚本运行 terraform plan 时,我收到以下错误消息:

Error: Error running plan: 1 error(s) occurred:

* output.foobaz: Resource 'data.external.example' does not have attribute 'result.foobaz' for variable 'data.external.example.result.foobaz'

从测试来看,外部脚本似乎并没有在计划阶段实际执行,但是,计划阶段确实试图插入预期的响应,这对我来说似乎是不正确的。有什么我想念的吗?

provider "scaleway" {
region = "ams1"
}

resource "scaleway_ip" "swarm_manager_ip" {
count = 1
}

data "external" "example" {
program = ["./scripts/test.sh"]

query = {
# arbitrary map from strings to strings, passed
# to the external program as the data query.
foo = "${scaleway_ip.swarm_manager_ip.0.ip}"
baz = "i-am-baz"
}
}

output "foobaz" {
value = "${data.external.example.result.foobaz}"
}

output "scaleway_ip_address" {
value = "${scaleway_ip.swarm_manager_ip.0.ip}"
}

这是外部脚本:

#!/bin/bash

# Exit if any of the intermediate steps fail
set -e

# Extract "foo" and "baz" arguments from the input into
# FOO and BAZ shell variables.
# jq will ensure that the values are properly quoted
# and escaped for consumption by the shell.
eval "$(jq -r '@sh "FOO=\(.foo) BAZ=\(.baz)"')"

# Placeholder for whatever data-fetching logic your script implements
FOOBAZ="$FOO BAZ"

# Safely produce a JSON object containing the result value.
# jq will ensure that the value is properly quoted
# and escaped to produce a valid JSON string.
jq -n --arg foobaz "$FOOBAZ" '{"foobaz":$foobaz}'

最佳答案

您的 Terraform 语法不正确。 data.external.example.result 是一张 map 。要访问其条目 foobaz,您需要编写代码

"${data.external.example.result["foobaz"]}"

参见 https://www.terraform.io/docs/configuration/interpolation.html

关于Terraform 外部提供者资源在计划阶段没有变量属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50620601/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com