Terraform to define different module source based on a condition that is based on a nested json data

30 views Asked by At

I have a nested json data that I have flattened it and want to call different module basing on the variable value while looping through that flattened variable . How can I achieve it ?

below is the json and the module block that we are using

      “customMetric” = “true”,
      “env” = “prod”,
      “service_name” = “cat-v1",
      “app_name” = “cat-v1",
      “qma_app_name” = “cat-v1",
      “host_count_metric_name” = “uptime”,
      “request_trend_metric_name” = “requests.count”,
      “error_5xx_request_metric_name” = “requests.count”,
      “error_5xx_response_metric_name” = “response_code”,
      “error_4xx_request_metric_name” = “requests.count”,
      “error_4xx_response_metric_name” = “response_code”
},
{
      “customMetric” = “false”,
      “env” = “prod”,
      “service_name” = “cat-v2",
      “app_name” = “cat-v2",
      “qma_app_name” = “cat-v2",
      “host_count_metric_name” = “uptime”,
      “request_trend_metric_name” = “requests.count”,
      “error_5xx_request_metric_name” = “requests.count”,
      “error_5xx_response_metric_name” = “response_code”,
      “error_4xx_request_metric_name” = “requests.count”,
      “error_4xx_response_metric_name” = “response_code”
     }
{
      “customMetric” = “true”,
      “env” = “prod”,
      “service_name” = “cat-v2",
      “app_name” = “cat-v2",
      “qma_app_name” = “cat-v2",
      “host_count_metric_name” = “uptime”,
      “request_trend_metric_name” = “requests.count”,
      “error_5xx_request_metric_name” = “requests.count”,
      “error_5xx_response_metric_name” = “response_code”,
      “error_4xx_request_metric_name” = “requests.count”,
      “error_4xx_response_metric_name” = “response_code”
     }
]
module “example” {
  for_each                   = local.services
  source                      = “${each.value.hasCustomMetric}” == “true” ? “/path1" : "/path2"
  team_name                   = each.value.team_name
}
0

There are 0 answers