【发布时间】:2020-11-06 02:41:20
【问题描述】:
这个想法是生成这样的东西:
environment {
...
environment_variable {
...
}
environment_variable {
...
}
}
其中有一个具有某些属性的环境块和具有某些属性的 0...n environment_variables。
我有以下模块,它在动态中使用动态。这可能吗?或者我将如何实现这一目标?
到目前为止,我所拥有的是以下模块,它在动态内部使用动态:
模块:
dynamic "environment" {
for_each = var.environment_definition
content {
field1 = environment.value.field1
field2 = environment.value.field2
dynamic "environment_variable" {
for_each = length(var.environment_variables) == 0 ? [] : [var.environment_variables]
content {
name = environment_variable.value.env_name
value = environment_variable.value.env_value
}
}
}
}
变量.tf:
variable "environment_definition" {
description = ""
type = any
default = {}
}
variable "environment_variables" {
description = ""
type = map(object({
env_name = string
env_value = string
}))
default = {}
}
上面的模块及其变量在我的 main.tf 中被调用:
environment_definition = {
field1 = "value"
field2 = "value"
}
environment_variables = {
tf_version = {
env_name = "TERRAFORM_VERSION"
env_value = "0.12.28"
},
aws_account = {
env_name = "AWS_ACCOUNT"
env_value = "Account123456"
},
environment = {
env_name = "ENVIRONMENT"
env_value = "dev"
}
}
但是我收到了这个错误:
Error: Missing map element
on ../../../modules/codebuild/main.tf line 123, in resource "aws_codebuild_project" "this":
152: value = environment_variable.value.env_value
|----------------
| environment_variable.value is map of object with 3 elements
This map does not have an element with the key "env_value".
我怎样才能成功地实现这个?
【问题讨论】:
标签: terraform terraform-provider-aws