diff --git a/main.tf b/main.tf index 646e608..86dea30 100644 --- a/main.tf +++ b/main.tf @@ -18,13 +18,7 @@ module "network" { source = "./modules/network" name = var.network_name - subnets = [ - { - name = var.subnet_name - region = var.region - cidr = var.subnet_cidr - } - ] + subnets = var.subnets } module "vm" { @@ -32,7 +26,7 @@ module "vm" { name = "vm-test" network_name = var.network_name - subnet_name = var.subnet_name + subnet_name = var.subnets[0].name ssh = var.ssh depends_on = [module.network] diff --git a/variables.tf b/variables.tf index 963e0fa..408eeeb 100644 --- a/variables.tf +++ b/variables.tf @@ -6,13 +6,13 @@ variable "project_id" { variable "region" { description = "The region for the resources." type = string - default = "europe-central2" + default = "us-west1" } variable "zone" { description = "The zone for the resources." type = string - default = "europe-central2-b" + default = "us-west1-a" } variable "network_name" { @@ -21,16 +21,25 @@ variable "network_name" { default = "dom-lab-network" } -variable "subnet_name" { - description = "The name of the subnet." - type = string - default = "waw-default" -} +variable "subnets" { + description = "A list of subnets to create." -variable "subnet_cidr" { - description = "The CIDR range for the subnet." - type = string - default = "192.168.16.0/24" + type = list(object({ + name = string + cidr = string + region = string + })) + + default = [{ + name = "waw-default" + cidr = "192.168.16.0/24" + region = "us-west1" + }] + + validation { + condition = var.subnets[0].region != null + error_message = "The region for the first subnet must be specified." + } } variable "ssh" {