在动态块内声明必需参数时缺少必需参数

问题描述 投票:0回答:1

当在动态块中声明必需参数时,我正在寻找错误缺少必需参数的解决方案。

在下面的示例中,

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
1个回答
0
投票

根据您使用的 Terraform 版本,您可以将版本属性设置为可选,请参阅:https://developer.hashicorp.com/terraform/language/expressions/type-constraints#optional-object-type-attributes .

© www.soinside.com 2019 - 2024. All rights reserved.