[英]Terraform - cloud run multiple environment variables from list
I'm trying to set multiple environment variables on a cloud run module I've created.我正在尝试在我创建的云运行模块上设置多个环境变量。 The example I'm following from Terraform is static. Is it possible to dynamically create these?
我从 Terraform 开始的示例是 static。是否可以动态创建这些?
template {
spec {
containers {
image = "us-docker.pkg.dev/cloudrun/container/hello"
env {
name = "SOURCE"
value = "remote"
}
env {
name = "TARGET"
value = "home"
}
}
}
}
https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloud_run_service#example-usage---cloud-run-service-multiple-environment-variables https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloud_run_service#example-usage---cloud-run-service-multiple-environment-variables
I've tried:我试过了:
dynamic "env" {
for_each = var.envs
content {
name = each.key
value = each.value
}
}
But I get the following error:但我收到以下错误:
A reference to "each.value" has been used in a context in which it unavailable, such as when the configuration no longer contains the value in │ its "for_each" expression.
对“each.value”的引用已在其不可用的上下文中使用,例如当配置不再包含其“for_each”表达式中的值时。 Remove this reference to each.value in your configuration to work around this error.
在您的配置中删除对 each.value 的引用以解决此错误。
Edit: Full code example编辑:完整代码示例
resource "google_cloud_run_service" "default" {
name = "cloudrun-srv"
location = "us-central1"
template {
spec {
containers {
image = "us-docker.pkg.dev/cloudrun/container/hello"
env {
name = "SOURCE"
value = "remote"
}
env {
name = "TARGET"
value = "home"
}
}
}
}
traffic {
percent = 100
latest_revision = true
}
autogenerate_revision_name = true
}
When you use dynamic blocks, you can't use each
.使用动态块时,不能使用
each
。 It should be:它应该是:
dynamic "env" {
for_each = var.envs
content {
name = env.key
value = env.value
}
}
Can you please help me with reading secrets from secret manager using dynamic block?你能帮我使用动态块从秘密管理器中读取秘密吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.