amazon-web-services - 如何在 Terraform 的动态块中使用 for_each 和迭代器?
问题描述
我基本上正在尝试这样做:
module "california" {
source = "./themodule"
# ...
}
module "oregon" {
source = "./themodule"
# ...
}
resource "aws_globalaccelerator_endpoint_group" "world" {
# ...
dynamic "endpoint_configuration" {
for_each = [
module.california.lb,
module.oregon.lb
]
iterator = lb
content {
endpoint_id = lb.arn
weight = 100
}
}
}
# themodule/main.tf
resource "aws_lb" "lb" {
# ...
}
output "lb" {
value = aws_lb.lb
}
我正在lb
从 Terraform 中的子模块输出,并尝试在for_each
数组中的父模块中使用它,并使用自定义iterator
名称。它给了我这个错误:
This object does not have an attribute named "arn".
但它确实具有该属性,它是一个aws_lb
. 我在使用这个和模块设置时做错了什么,我该for_each
如何解决?非常感谢你!
如果我将其更改为此它似乎可以工作:
resource "aws_globalaccelerator_endpoint_group" "world" {
listener_arn = aws_globalaccelerator_listener.world.id
endpoint_configuration {
endpoint_id = module.california.lb.arn
weight = 100
}
}
解决方案
推荐阅读
- python - Python中的ATM脚本
- oauth-2.0 - Azure AD ADAL 隐式流说明
- c# - 仅针对有保证的作业过滤“查找所有参考”的快捷方式?
- android - 如何获取 Buildozer 的最新 SDK 版本
- java - Java Long Running Thread 导致内存泄漏?
- assembly - xmm8 寄存器值是否在调用中保留?
- node.js - 如何创建服务于 Vue.js SPA 的 Node.js Express 应用程序?
- kentico - 重新安排在下一个非高峰期删除更多联系人
- java - 在 Java 中重用按钮不会显示任何内容
- python - python 时间结果不符合预期:time.time() - time.time()