我该如何处理以下variables
var 可以为空的情况
locals {
tf_variables = (var.variables == null) ? null : jsondecode(var.variables)["variables"]
}
resource "tfe_variable" "this" {
for_each = local.tf_variables
...
}
Run Code Online (Sandbox Code Playgroud)
我正在打
Error: Invalid for_each argument
on ..\..\main.tf line 63, in resource "tfe_variable" "this":
63: for_each = local.tf_variables
The given "for_each" argument value is unsuitable: the given "for_each"
argument value is null. A map, or set of strings is allowed.
Run Code Online (Sandbox Code Playgroud)
您可以将 替换null
为空集、列表或地图。
将您的本地更改为此应该有效:
locals {
tf_variables = (var.variables == null) ? [] : jsondecode(var.variables)["variables"]
}
Run Code Online (Sandbox Code Playgroud)
顺便说一句,您不需要jsondecode
在那里使用,因为var.variables
它必须已经是序列化的 HCL 对象。
归档时间: |
|
查看次数: |
16008 次 |
最近记录: |