Changed the method of defining subnets in the main module.

This commit is contained in:
2025-03-30 13:42:13 +02:00
parent f97a27012b
commit 6924f75c86
2 changed files with 22 additions and 19 deletions
+2 -8
View File
@@ -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]
+20 -11
View File
@@ -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" {