当在动态块中声明必需参数时,我正在寻找错误缺少必需参数的解决方案。
在下面的示例中,
resource_two
具有所需的参数 version
和 id
。使用此配置,我总是收到错误消息,指出 Missing required argument.
resource "resource_one" "sample" {
for_each = { for sl in var.sample_list : sl.name => sl }
name = each.value.name
}
resource "resource_two" "sample" {
for_each = { for sl in var.sample_list : sl.name => sl }
dynamic "v" {
for_each = each.value.versions
content {
version = v.value.version
id = resource_one[each.key].id
}
}
}
variable "sample_list" {
type = list(object({
name = string
versions = list(object({
id = string
version = number
}))
}))
}
我尝试在 terraform 中使用 try 函数,但没有成功。
是否可以在动态块中添加所需的变量?
根据您使用的 Terraform 版本,您可以将版本属性设置为可选,请参阅:https://developer.hashicorp.com/terraform/language/expressions/type-constraints#optional-object-type-attributes .