【发布时间】:2021-09-08 22:27:10
【问题描述】:
我正在尝试遍历地图并在 aws_codebuild_project 中创建一些附加设置。这是我第一次在 Terraform 中使用循环。我的主要困惑是我不知道资源是否必须“支持”循环,或者是否可以在资源内的几乎所有地方进行迭代?
variable "custom_environment_variables" {
type = map(any)
default = {}
}
resource "aws_codebuild_project" "my_project" {
# other props...
environment {
type = "LINUX_CONTAINER"
# more props
# some hardcoded environment_variable
environment_variable {
name = "APP_STAGE"
value = var.app_stage
}
# some dynamic environment_variable
dynamic "custom_environment_variable" {
for_each = var.custom_environment_variables
environment_variable {
name = custom_environment_variable.key
value = custom_environment_variable.value
}
}
}
}
此代码导致此错误:
│ Error: Unsupported block type
│
│ on ../modules/static_web_pipeline/main.tf line 155, in resource "aws_codebuild_project" "my_project":
│ 155: dynamic "custom_environment_variable" {
│
│ Blocks of type "custom_environment_variable" are not expected here.
【问题讨论】:
标签: amazon-web-services terraform infrastructure-as-code