terraform - Terraform 外部提供者资源在计划阶段没有变量属性
问题描述
使用以下脚本运行 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
是一张地图。要访问其条目foobaz
,您需要编码
"${data.external.example.result["foobaz"]}"
见https://www.terraform.io/docs/configuration/interpolation.html
推荐阅读
- react-native - 底部选项卡中的 React Navigation 6.x 标题问题
- docusignapi - 我无法使用 Create Envelope 方法
- django - 如何在 django 中使用 bulk_create
- java - 如何在一个 Spring 数据存储库查询中从多个模式访问表
- typescript - 在生产所需的 devDependences 上构建 Nuxt.js
- c - STM32F446RE 没有得到来自 SIM800L 模块的 AT 命令的响应
- xslt - Need For -Each Logic 基于在 xslt 1.0 中没有节点/根的变量值
- ruby - 带有可选参数的 ArgumentError
- swiftui - 我希望在我正在关注的教程中添加一个带有标题的导航栏。任何帮助都感激不尽
- batch-file - 批量 ping 监视器未写入日志