В Terraform 0.12 вы можете использовать for_each с такими модулями, как:
modules / google_compute_instance / variables.tf
variable "hosts" {
type = map(object({
hostname = string
cpu = number
ram = number
hdd = number
log_drive = number
template = string
service_types = list(string)
}))
}
modules / google_compute_instance / main.tf
resource "google_compute_instance" "gcp_instance" {
for_each = var.hosts
hostname = each.value.repository_name
cpu = each.value.cpu
ram = each.value.ram
hdd = each.value.hdd
log_drive = each.value.log_drive
template = each.value.template
service_types = each.value.service_types
}
servers.tf
module "gcp_instances" {
source = ./modules/google_compute_instance"
hosts = {
"test1-srfe" = {
hostname = "test1-srfe",
cpu = 1,
ram = 4,
hdd = 15,
log_drive = 300,
template = "Template-New",
service_types = ["sql", "db01", "db02"]
},
"test1-second" = {
hostname = "test1-second",
cpu = 1,
ram = 4,
hdd = 15,
log_drive = 300,
template = "APPs-Template",
service_types = ["configs"]
},
}
}
Конечно, вы можете добавить столько переменных, сколько необходимо, и использовать их в модуле.