AWS default_tags in sub-modules with dynamic values

I don’t know if this is even possible, as I’ve been researching this for the last 2 days.

my current setup is using a root module and a ‘modules/vpc’ for sub-modules. I use this to create a customer-specific environment.

I’m trying to create ‘default_tags’ for the sub-module, but I’m hitting road blocks.

If I add ‘static’ content in the root module default_tags, it pushes just fine into the sub-module. However, I want to have a default_tag within the sub-module that looks like:

default_tags = { 
  tags {
    customer = "${var.cust_name}"
  }
}

now, here is the problem… if I create a ‘provider’ block within the sub-module, my root module fails because the root module uses a ‘for_each’ in the main, like so:

variable "customers" {
  type = list(string)
  description = "List of customer names to deploy"
  default = [] # Add a default value to avoid the "no value for required variable" error
}



locals {
  cust_vars = {
    for cust in var.customers :
      cust => merge(
        yamldecode(file("customers/${cust}.tfvars")).cust_config // Access the map
      )
  }

}

module "vpc" {
  for_each = local.cust_vars

  source = "./modules/vpc"

  # Access variables now available after merging with tfvars content
  cust_name           = each.value.cust_name
  ...
}

long story short, no matter what I do in terms of trying to set a ‘default_tag’ to dynamic content, Terraform doesn’t like it. I’m really trying to avoid having to specify the ‘tags’ block under every single resource. however, if that’s the only way to do this (ie. specifying a list of tags as a local variable and looping in the tag block of each and every resource, then so be it, but it seems like this should be very simple.

Appreciate any tips, pointers, etc…