【问题标题】:Terraform module output to use as input in other module specifically with for_eachTerraform 模块输出用作其他模块中的输入,特别是 for_each
【发布时间】:2021-08-16 23:30:56
【问题描述】:

我需要一些关于以下用例的指导。我有一个堆栈,其中有 30 个要创建的 aws 目标组。所以我使用了一个带有 diff 参数的 for_each 模块并创建了 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 = 每个.值

给定的值不适用于定义在的子模块变量“tg_arn” .terraform\modules\listener_rule_Models\variables.tf:6,1-18:需要字符串。

错误:模块参数的值无效

在 main.tf 第 181 行,在模块“listener_rule_Models”中: 181: tg_arn = 每个.值

给定的值不适用于定义在的子模块变量“tg_arn” .terraform\modules\listener_rule_Models\variables.tf:6,1-18:需要字符串。

错误:模块参数的值无效

在 main.tf 第 182 行,在模块“listener_rule_Models”中: 182: forwarding_path = [每个值]

给定的值不适用于子模块变量“forwarding_path” 在 .terraform\modules\listener_rule_Models\variables.tf:17,1-27 中定义: 元素 0:需要字符串。

错误:模块参数的值无效

在 main.tf 第 182 行,在模块“listener_rule_Models”中: 182: forwarding_path = [每个值]

【问题讨论】:

    标签: for-loop terraform each terraform-provider-aws


    【解决方案1】:

    您错过了在映射中引用单个键,而是为 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]
    }
    

    【讨论】:

      猜你喜欢
      • 2021-03-07
      • 2021-03-31
      • 2021-07-08
      • 2021-09-24
      • 2021-03-21
      • 2021-01-11
      • 2021-02-12
      • 2021-07-09
      • 1970-01-01
      相关资源
      最近更新 更多