add networks many
This commit is contained in:
@@ -6,13 +6,7 @@ locals {
|
||||
name => node
|
||||
}
|
||||
|
||||
ip_map = {
|
||||
for name, node in local.nodes :
|
||||
name => coalesce(
|
||||
lookup(node, "ip", null),
|
||||
"${var.network_base}.${var.cluster_ip_start + node.ip_offset + node.index}"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
vmid_map = {
|
||||
for name, node in local.nodes :
|
||||
|
||||
@@ -54,11 +54,13 @@ resource "proxmox_virtual_environment_vm" "nodes" {
|
||||
dedicated = each.value.memory
|
||||
}
|
||||
|
||||
network_device {
|
||||
bridge = var.node_bridge
|
||||
# vlan_id = try(each.value.vlan_id, null)
|
||||
vlan_id = each.value.vlan_id
|
||||
dynamic "network_device" {
|
||||
for_each = each.value.network_devices
|
||||
|
||||
content {
|
||||
bridge = network_device.value.bridge
|
||||
vlan_id = try(network_device.value.vlan_id, null)
|
||||
}
|
||||
}
|
||||
|
||||
disk {
|
||||
@@ -77,16 +79,19 @@ resource "proxmox_virtual_environment_vm" "nodes" {
|
||||
size = disk.value
|
||||
}
|
||||
}
|
||||
initialization {
|
||||
datastore_id = each.value.datastore
|
||||
user_data_file_id = proxmox_virtual_environment_file.cloudinit[each.key].id
|
||||
|
||||
initialization {
|
||||
datastore_id = each.value.datastore
|
||||
user_data_file_id = proxmox_virtual_environment_file.cloudinit[each.key].id
|
||||
dynamic "ip_config" {
|
||||
for_each = each.value.network_devices
|
||||
|
||||
ip_config {
|
||||
ipv4 {
|
||||
address = "${local.ip_map[each.key]}/${var.network_cidr}"
|
||||
gateway = var.cluster_gateway
|
||||
content {
|
||||
ipv4 {
|
||||
address = try(ip_config.value.ip, "dhcp") == null ? "dhcp" : "${ip_config.value.ip}/${ip_config.value.cidr}"
|
||||
gateway = try(ip_config.value.gateway, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,24 +4,26 @@ variable "ssh_key" {
|
||||
|
||||
variable "nodes" {
|
||||
type = map(object({
|
||||
# role = string
|
||||
index = number
|
||||
cpu = number
|
||||
memory = number
|
||||
disk = number
|
||||
datastore = string
|
||||
ip_offset = optional(number)
|
||||
ip = optional(string)
|
||||
vmid = optional(number)
|
||||
vlan_id = optional(number)
|
||||
data_disk = optional(number)
|
||||
cloudinit = optional(string)
|
||||
|
||||
network_devices = list(object({
|
||||
bridge = string
|
||||
vlan_id = optional(number)
|
||||
|
||||
ip = optional(string)
|
||||
cidr = optional(number)
|
||||
gateway = optional(string)
|
||||
}))
|
||||
}))
|
||||
}
|
||||
|
||||
variable "cluster_ip_start" {
|
||||
type = number
|
||||
}
|
||||
|
||||
variable "worker_vmid_start" {
|
||||
type = number
|
||||
@@ -51,20 +53,6 @@ variable "disk_interface" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "network_base" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "network_cidr" {
|
||||
type = number
|
||||
}
|
||||
|
||||
variable "cluster_gateway" {
|
||||
type = string
|
||||
}
|
||||
|
||||
|
||||
|
||||
variable "data_datastore" {
|
||||
type = string
|
||||
description = "Datastore for data disk"
|
||||
|
||||
Reference in New Issue
Block a user