195 lines
4.1 KiB
HCL
195 lines
4.1 KiB
HCL
locals {
|
|
managers = [
|
|
for i in range(var.manager_count) : {
|
|
name = "${var.swarm_name}-manager-${format("%02s", i + 1)}"
|
|
}
|
|
]
|
|
workers = [
|
|
for i in range(var.worker_count) : {
|
|
name = "${var.swarm_name}-worker-${format("%02s", i + 1)}"
|
|
}
|
|
]
|
|
}
|
|
|
|
resource "proxmox_virtual_environment_pool" "swarm_pool" {
|
|
comment = "Managed by Terraform"
|
|
pool_id = var.swarm_name
|
|
}
|
|
|
|
resource "proxmox_virtual_environment_vm" "swarm_manager" {
|
|
count = var.manager_count
|
|
name = local.managers[count.index].name
|
|
description = "Managed by Terraform"
|
|
tags = ["terraform", "ubuntu", "swarm-manager", var.swarm_name]
|
|
|
|
node_name = "pve"
|
|
vm_id = "${var.vm_id_prefix}${count.index + 101}"
|
|
pool_id = proxmox_virtual_environment_pool.swarm_pool.id
|
|
|
|
cpu {
|
|
cores = 2
|
|
type = "host"
|
|
}
|
|
|
|
memory {
|
|
dedicated = 2048
|
|
floating = 2048
|
|
}
|
|
|
|
agent {
|
|
# read 'Qemu guest agent' section, change to true only when ready
|
|
enabled = true
|
|
}
|
|
|
|
startup {
|
|
order = "1"
|
|
up_delay = "60"
|
|
down_delay = "60"
|
|
}
|
|
|
|
disk {
|
|
datastore_id = var.proxmox_vm_storage
|
|
file_id = var.cloud_image_id
|
|
interface = "virtio0"
|
|
iothread = true
|
|
discard = "on"
|
|
size = 32
|
|
file_format = "qcow2"
|
|
}
|
|
|
|
initialization {
|
|
ip_config {
|
|
ipv4 {
|
|
# x.x.x.32 - x.x.x.39
|
|
address = "${cidrhost(var.subnet_cidr, count.index + 32)}/24"
|
|
gateway = var.gateway
|
|
}
|
|
}
|
|
datastore_id = var.proxmox_image_storage
|
|
|
|
user_data_file_id = proxmox_virtual_environment_file.swarm_manager[count.index].id
|
|
}
|
|
|
|
network_device {
|
|
bridge = "vmbr0"
|
|
}
|
|
|
|
operating_system {
|
|
type = "l26"
|
|
}
|
|
|
|
lifecycle {
|
|
}
|
|
}
|
|
|
|
|
|
resource "proxmox_virtual_environment_file" "swarm_manager" {
|
|
count = var.manager_count
|
|
content_type = "snippets"
|
|
datastore_id = var.proxmox_image_storage
|
|
node_name = "pve"
|
|
|
|
source_raw {
|
|
data = <<EOF
|
|
${var.common_cloud_init}
|
|
|
|
hostname: ${local.managers[count.index].name}
|
|
EOF
|
|
file_name = "${local.managers[count.index].name}.cloud-config.yaml"
|
|
}
|
|
}
|
|
|
|
|
|
resource "proxmox_virtual_environment_file" "swarm_worker" {
|
|
count = var.worker_count
|
|
content_type = "snippets"
|
|
datastore_id = var.proxmox_image_storage
|
|
node_name = "pve"
|
|
|
|
source_raw {
|
|
data = <<EOF
|
|
${var.common_cloud_init}
|
|
|
|
hostname: ${local.workers[count.index].name}
|
|
EOF
|
|
file_name = "${local.workers[count.index].name}.cloud-config.yaml"
|
|
}
|
|
}
|
|
|
|
resource "proxmox_virtual_environment_vm" "swarm_worker" {
|
|
count = var.worker_count
|
|
name = local.workers[count.index].name
|
|
description = "Managed by Terraform"
|
|
tags = ["terraform", "ubuntu", "swarm-worker", var.swarm_name]
|
|
|
|
node_name = "pve"
|
|
vm_id = "${var.vm_id_prefix}${count.index + 301}"
|
|
pool_id = proxmox_virtual_environment_pool.swarm_pool.id
|
|
|
|
cpu {
|
|
cores = 4
|
|
type = "host"
|
|
}
|
|
|
|
memory {
|
|
dedicated = 8192
|
|
floating = 8192
|
|
}
|
|
|
|
agent {
|
|
# read 'Qemu guest agent' section, change to true only when ready
|
|
enabled = true
|
|
}
|
|
|
|
startup {
|
|
order = "2"
|
|
up_delay = "60"
|
|
down_delay = "60"
|
|
}
|
|
|
|
disk {
|
|
datastore_id = var.proxmox_vm_storage
|
|
file_id = var.cloud_image_id
|
|
interface = "virtio0"
|
|
discard = "on"
|
|
size = 32
|
|
file_format = "qcow2"
|
|
}
|
|
|
|
initialization {
|
|
ip_config {
|
|
ipv4 {
|
|
# x.x.x.40 - x.x.x.55
|
|
address = "${cidrhost(var.subnet_cidr, count.index + 40)}/24"
|
|
gateway = var.gateway
|
|
}
|
|
}
|
|
datastore_id = var.proxmox_image_storage
|
|
|
|
user_data_file_id = proxmox_virtual_environment_file.swarm_worker[count.index].id
|
|
}
|
|
|
|
network_device {
|
|
bridge = "vmbr0"
|
|
}
|
|
|
|
operating_system {
|
|
type = "l26"
|
|
}
|
|
|
|
lifecycle {
|
|
}
|
|
}
|
|
|
|
resource "ansible_host" "swarm_manager" {
|
|
count = var.manager_count
|
|
name = "${local.managers[count.index].name}.local"
|
|
groups = ["${var.swarm_name}_manager", var.swarm_name]
|
|
}
|
|
|
|
resource "ansible_host" "swarm_worker" {
|
|
count = var.worker_count
|
|
name = "${local.workers[count.index].name}.local"
|
|
groups = ["${var.swarm_name}_worker", var.swarm_name]
|
|
}
|