我正在编写用于在 Oracle 云中创建 Kubernetes 集群的脚本。 当我运行 terraform plan 时,它没有返回任何错误。但是当我运行 terraform apply 时,它返回错误:
Error: Invalid template interpolation value: Cannot include the given value in a string template: string required.
我启用跟踪和日志文件生成以尝试确定问题出在哪里,在跟踪中它返回:
2019/11/21 20:31:15 [TRACE] EvalMaybeTainted: null_resource.k8sworker-ad1 [0] encountered an error during creation, so it is now marked as tainted
2019/11/21 20:31:15 [ERROR] : eval: * terraform.EvalApplyPost, err: 1 error occurred:
Invalid template interpolation value: Cannot include the given value in a template: string required string.
2019/11/21 20:31:15 [TRACE] EvalMaybeTainted: null_resource.k8sworker-ad1 [1] encountered an error during creation, so it is now marked as tainted
2019/11/21 20:31:15 [ERROR] : eval: * terraform.EvalSequence, err: Invalid template interpolation value: Cannot include the given value in a string template: string required.
我认为问题出在这部分代码中:
resource "null_resource" "k8sworker-ad1" {
count = var.k8sWorkerAd1Count
depends_on = [module.instances-k8sworker-ad1]
triggers = {
worker_id = module.instances-k8sworker-ad1.ids[0][count.index]
build_source_id = null_resource.build_source.id
}
provisioner "local-exec" {
command = "echo 'alias ${var.label_prefix}workerad1-${count.index}=\"ssh -i ${path.root}/generated/instances_id_rsa opc@${element(module.instances-k8sworker-ad1.public_ips, count.index)}\"' >> source.sh"
}
}
Terraform 版本是:
Terraform v0.12.16
+ provider.null v2.1.2
+ provider.oci v3.52.0
+ provider.random v2.2.1
+ provider.template v2.1.2
+ provider.tls v2.1.1
跟踪输出是:
https://gist.github.com/RuyCury/bc0dbccc65bbbadf2eb90569fd438286
请帮我解决这个问题。
最佳答案
我刚刚遇到了类似的问题并找到了解决方法,所以我将在此处分享。
基本上,我尝试获取的 element(module.instances-k8sworker-ad1.public_ips, count.index)
在插值时不可用。我所做的修复是删除我在 VM 的资源声明中放入的 wait_for_guest_net_timeout = 0
参数。
如果我使用此参数,当我使用 terraform console
并尝试在创建后评估我的 VM 资源时,输出中没有名为 default_ip_address
的 key (这是我试图在 element
中获取的资源键),这一定是 terraform 返回 OP 错误(值为 null)的原因。当我删除参数时,键和值已正确填充。我的 VM 资源类型为 vsphere_virtual_machine
。我猜 OP 使用的是不同类型的资源,但问题可能是一样的。
关于terraform - 错误 : Invalid template interpolation value: Cannot include the given value in a string template: string required,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58995366/
相关文章:
python - 使用 TorchScript 类作为 pytorch 模块中的成员
python - macOS : Access denied (insufficient permi
react-native - 在 bazel 构建中运行 react-native cli
arrays - 当我在 PowerShell 中更改数组的值时,我不断收到 "Unable to
mongoose - 是否有用于数据访问的 Mongoose 事件?
git - Devops Azure 没有足够的钩子(Hook)权限(对于协作者)
graphql - gatsby-source-contentful 不适用于 gatsby-tra