【发布时间】:2021-11-28 19:41:44
【问题描述】:
我正在尝试使用对象的变量列表来定义值的类型和默认值,并在动态块中使用它。我知道有一个实验性功能,但只是想知道如果没有实验性功能我将如何做到这一点?
variables.rf
variable "identity" {
type = list(object({
type = string
identity_ids = list(string)
}))
default = [
{
type = null
identity_ids = null
}
]
}
main.tf
resource "azurerm_cognitive_account" "azure" {
# Required
name = var.name
location = var.location
resource_group_name = var.resource_group_name
kind = var.kind
sku_name = var.sku_name
dynamic "identity" {
for_each = var.identity
content {
type = identity.value.type
identity_ids = identity.value.identity_ids
}
}
}
作为模块使用
module "cognitive_account" {
source = "../modules/cognitive-account"
name = "name"
location = "Australia East"
resource_group_name = module.rg.name
kind = "TextAnalytics"
sku_name = "S"
custom_subdomain_name = "unique-name"
identity = [{
type = "SystemAssigned"
}]
}
使用该代码会给我一个错误:
│ Error: Invalid value for module argument
│
│ on main.tf line 66, in module "cognitive_account":
│ 66: identity = [{
│ 67: type = "SystemAssigned"
│ 68: }]
│
│ The given value is not suitable for child module variable "identity" defined at .terraform\modules\cognitive_account\variables.tf:123,1-20: element 0:
│ attribute "identity_ids" is required.
我不知道如何处理从对象块中省略identity_ids,我认为默认为null 会处理它。
【问题讨论】:
-
动态块不是实验性的。所以不知道你是什么意思?
标签: terraform