You can change the module to take all or most of its parameters as a single variable of object type, e.g. just called parameters, and then you can pass in a common object, probably defined in terms of a local variable, to each module instance.
Can you give a quick example of how you would do that? I’m not sure if there’s a way to do it for a root module. This doesn’t work and complains that name is not a valid attribute
module "imaged" {
for_each = {
app = {
node_group = "app"
machine_type = var.app_machine_type
}
pgbouncer-app = {
node_group = "pgbouncer"
machine_type = var.pgbouncer_machine_type
}
}
# This will be the name of the module
name = each.key
source = "./imaged"
node_group = each.value.node_group
name_prefix = each.key
name_suffix = var.name_suffix
project = var.project
zone = var.zone
source_disk_name = var.source_disk_name
source_image_name = var.source_image_name
nomad_running_healthcheck_name = var.nomad_running_healthcheck_name
machine_type = each.value.machine_type
}
No. If you use for_each or count within a module or resource you have the single name with a [] suffix (string values for for_each and numbers for count).
Choosing your own resource/module name individually is only possible by having multiple blocks.