【发布时间】:2021-06-12 09:17:56
【问题描述】:
假设我们有这个本地人:
locals = {
schemas = [
{
name = "is_cool"
attribute_data_type = "Boolean"
mutable = true
required = false
},
{
name = "firstname"
attribute_data_type = "String"
mutable = true
required = false
min_length = 1
max_length = 256
}
]
}
我想要实现的是使用dynamic 来构建架构,当架构是字符串时,我想添加string_attribute_constraints 块。
这是我到目前为止所做的,但是当架构为布尔时,它会添加一个空的 string_attribute_constraints 块
dynamic "schema" {
for_each = var.schemas
content {
name = schema.value.name
attribute_data_type = schema.value.attribute_data_type
mutable = schema.value.mutable
required = schema.value.required
string_attribute_constraints {
min_length = lookup(schema.value, "min_length", null)
max_length = lookup(schema.value, "max_length", null)
}
}
}
地形规划:
+ schema {
+ attribute_data_type = "Boolean"
+ mutable = true
+ name = "is_cool"
+ required = false
+ string_attribute_constraints {}
}
【问题讨论】: