0

I am deploying a number of AWS application load balancers by feeding a nested map from locals.tf to a module configuring the load-balancers.

locals {
   lb_vars = {
      alb1 = {
           load_balancer_type = application
           listener_port  = 443
           listener_protocol = https
           internal = false
           subnets  = var.subnet1
            backends = {
                 backend1 = {
                 port                  = "8080"
                 path                  = ["/endpoint1/backend1*"]
                 protocol              = "http"
                 protocol_version      = "http1"
                 health_check_enabled  = true
                 health_check_interval = 10
                 health_check_port     = 19808
                 health_check_path     = "/health"
                 health_check_protocol = "http"    
          },
                 backend2 = {
                 port                  = "8081"
                 path                  = ["/endpoint1/backend2*"]
                 protocol              = "http"
                 protocol_version      = "http1"
                 health_check_enabled  = true
                 health_check_interval = 10
                 health_check_port     = 19809
                 health_check_path     = "/health"
                 health_check_protocol = "http"    
          },
      alb2 = {
           load_balancer_type = application
           listener_port  = 443
           listener_protocol = https
           internal = false
           subnets = var.subnet1
            backends = {
                 backend1 = {
                 port                  = "8082"
                 path                  = ["/endpoint2/backend1*"]
                 protocol              = "http"
                 protocol_version      = "http1"
                 health_check_enabled  = true
                 health_check_interval = 10
                 health_check_port     = 19810
                 health_check_path     = "/health"
                 health_check_protocol = "http"    
          },             
                 backend2 = {
                 port                  = "8083"
                 path                  = ["/endpoint2/backend2*"]
                 protocol              = "http"
                 protocol_version      = "http1"
                 health_check_enabled  = true
                 health_check_interval = 10
                 health_check_port     = 19811
                 health_check_path     = "/health"
                 health_check_protocol = "http"    
          },
       }
    }
  }
}

Resource in load-balancer module:

resource "aws_lb" "lb" {                                   
  for_each = var.lb_vars                    
                                                       
  name               = "${each.key}-${var.env_name}"       
  internal           = try(each.value.internal, "false")            
  load_balancer_type = try(each.value.load_balancer_type, "application")   
  security_groups    = aws_security_group.lb_security_group[each.key] 
  subnets            = each.value.subnets     
                                                       
  enable_deletion_protection = false                                                                          
                                                      
  tags = "Name" = "${each.key}-${var.env_name}"                                                           
}

As one can see, there are a number of parameters which I would like to not define for each AWS lb because typically they are the defaults, but if I remove one of the parameters I get the following error;

Error: Invalid value for module argument
The given value is not suitable for child module variable "lb_vars" defined
at lb/variables.tf:41,1-21: all map elements must have the same type.

Load-balancer Module

module "lb" {
  source = "./lb"

  env_name         = var.env_name
  full_env_name    = local.full_env_name
  subnet_ids       = local.subnet_ids
  vpc_id           = data.aws_vpc.vpc.id
  external_zone_id = data.aws_route53_zone.external.zone_id
  common_tags      = local.common_tags
  env_cert_arn     = data.aws_acm_certificate.wildcard_cert.arn
  lb_params        = local.lb_params
}

Variables.tf in load-balancer modules (line 41 as per error)

variable "lb_params" {
  type        = map
  description = "LB parameters"
}
5
  • 1
    The error is about "module argument". Which argument, what module? Can you updated the question with full details? Commented Mar 28, 2022 at 9:00
  • I have added the module arguments Commented Mar 28, 2022 at 9:49
  • 1
    The error also says variables.tf line 41, yet you are not showing that file. Can you please provide all code, including the one that generates the error? Commented Mar 28, 2022 at 9:51
  • Added the variables.tf line 41. The only other pieces of code left are the other parts of the load-balancer configuration. Commented Mar 28, 2022 at 11:47
  • The error is about variable "lb_vars" yet you haven't shown how it is declared nor used. Commented Dec 18, 2022 at 9:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.