Terraform 模块输出用作其他模块的输入,特别是 for_each
Terraform module output to use as input in other module specifically with for_each
我需要一些关于以下用例的指导。我有一个堆栈,其中包含 30 个要创建的 aws 目标组。因此,我正在使用带有 for_each 和 diff 参数的模块并创建 30 个目标组。现在稍后我需要创建 30 个侦听器转发规则,我必须在其中传递上述目标组的 arn 的输出。我收到需要字符串的错误。我确定输出是一个字符串,当我多次调用模块时没有 for_each.
module "listener_rule_Models" {
source = "git::https://mycompany/_git/terraform-aws-alb-listener-rule"
for_each = {
"models" = {
tg_arn = module.tgLOGIN["MODELS"].tg_arn
forwarding_path = ["/my_service.application_path*"]
},
"indexEngine" = {
tg_arn = module.tgLOGIN["MODELS"].tg_arn
forwarding_path = ["/my_service2.application_path*"]
}
}
listener_arn = module.lis-Consolidated81.listener_arn
tg_arn = each.value
forwarding_path = [each.value]
}
错误:模块参数的值无效
在 main.tf 第 181 行,在模块“listener_rule_Models”中:
181:tg_arn=each.value
给定的值不适合定义在以下位置的子模块变量“tg_arn”
.terraform\modules\listener_rule_Models\variables.tf:6,1-18: 需要字符串。
错误:模块参数的值无效
在 main.tf 第 181 行,在模块“listener_rule_Models”中:
181:tg_arn=each.value
给定的值不适合定义在以下位置的子模块变量“tg_arn”
.terraform\modules\listener_rule_Models\variables.tf:6,1-18: 需要字符串。
错误:模块参数的值无效
在 main.tf 第 182 行,在模块“listener_rule_Models”中:
182:forwarding_path=[each.value]
给定值不适合子模块变量“forwarding_path”
定义在 .terraform\modules\listener_rule_Models\variables.tf:17,1-27:
元素 0:需要字符串。
错误:模块参数的值无效
在 main.tf 第 182 行,在模块“listener_rule_Models”中:
182:forwarding_path=[each.value]
您错过了引用地图中的各个键,而是同时引用了 tg_arn 和 forwarding_path 的地图。
module "listener_rule_Models" {
source = "git::https://mycompany/_git/terraform-aws-alb-listener-rule"
for_each = {
"models" = {
tg_arn = module.tgLOGIN["MODELS"].tg_arn
forwarding_path = ["/my_service.application_path*"]
},
"indexEngine" = {
tg_arn = module.tgLOGIN["MODELS"].tg_arn
forwarding_path = ["/my_service2.application_path*"]
}
}
listener_arn = module.lis-Consolidated81.listener_arn
tg_arn = each.value.tg_arn
forwarding_path = [each.value.forwarding_path]
}
我需要一些关于以下用例的指导。我有一个堆栈,其中包含 30 个要创建的 aws 目标组。因此,我正在使用带有 for_each 和 diff 参数的模块并创建 30 个目标组。现在稍后我需要创建 30 个侦听器转发规则,我必须在其中传递上述目标组的 arn 的输出。我收到需要字符串的错误。我确定输出是一个字符串,当我多次调用模块时没有 for_each.
module "listener_rule_Models" {
source = "git::https://mycompany/_git/terraform-aws-alb-listener-rule"
for_each = {
"models" = {
tg_arn = module.tgLOGIN["MODELS"].tg_arn
forwarding_path = ["/my_service.application_path*"]
},
"indexEngine" = {
tg_arn = module.tgLOGIN["MODELS"].tg_arn
forwarding_path = ["/my_service2.application_path*"]
}
}
listener_arn = module.lis-Consolidated81.listener_arn
tg_arn = each.value
forwarding_path = [each.value]
}
错误:模块参数的值无效
在 main.tf 第 181 行,在模块“listener_rule_Models”中: 181:tg_arn=each.value
给定的值不适合定义在以下位置的子模块变量“tg_arn” .terraform\modules\listener_rule_Models\variables.tf:6,1-18: 需要字符串。
错误:模块参数的值无效
在 main.tf 第 181 行,在模块“listener_rule_Models”中: 181:tg_arn=each.value
给定的值不适合定义在以下位置的子模块变量“tg_arn” .terraform\modules\listener_rule_Models\variables.tf:6,1-18: 需要字符串。
错误:模块参数的值无效
在 main.tf 第 182 行,在模块“listener_rule_Models”中: 182:forwarding_path=[each.value]
给定值不适合子模块变量“forwarding_path” 定义在 .terraform\modules\listener_rule_Models\variables.tf:17,1-27: 元素 0:需要字符串。
错误:模块参数的值无效
在 main.tf 第 182 行,在模块“listener_rule_Models”中: 182:forwarding_path=[each.value]
您错过了引用地图中的各个键,而是同时引用了 tg_arn 和 forwarding_path 的地图。
module "listener_rule_Models" {
source = "git::https://mycompany/_git/terraform-aws-alb-listener-rule"
for_each = {
"models" = {
tg_arn = module.tgLOGIN["MODELS"].tg_arn
forwarding_path = ["/my_service.application_path*"]
},
"indexEngine" = {
tg_arn = module.tgLOGIN["MODELS"].tg_arn
forwarding_path = ["/my_service2.application_path*"]
}
}
listener_arn = module.lis-Consolidated81.listener_arn
tg_arn = each.value.tg_arn
forwarding_path = [each.value.forwarding_path]
}