mirror of
https://gitea.fenix-dev.com/fenix-gitea-admin/iac-opentofu-private.git
synced 2025-10-27 15:53:06 +00:00
Update proxmox.tf
This commit is contained in:
33
proxmox.tf
33
proxmox.tf
@ -38,7 +38,7 @@ resource "proxmox_virtual_environment_file" "cloud_init_yaml" {
|
|||||||
|
|
||||||
# Gerar um snippet cloud-init por VM
|
# Gerar um snippet cloud-init por VM
|
||||||
resource "proxmox_virtual_environment_file" "vm_user_data" {
|
resource "proxmox_virtual_environment_file" "vm_user_data" {
|
||||||
for_each = local.merged_cloudinit
|
for_each = { for vm in var.proxmox_k8s_vms : vm.name => vm }
|
||||||
|
|
||||||
node_name = "fenix"
|
node_name = "fenix"
|
||||||
datastore_id = "local-snippets"
|
datastore_id = "local-snippets"
|
||||||
@ -46,26 +46,20 @@ resource "proxmox_virtual_environment_file" "vm_user_data" {
|
|||||||
|
|
||||||
source_raw {
|
source_raw {
|
||||||
file_name = "cloud-init-iac-k8s-${each.key}.yaml"
|
file_name = "cloud-init-iac-k8s-${each.key}.yaml"
|
||||||
data = yamlencode(each.value)
|
data = yamlencode(
|
||||||
|
local.deep_merge(
|
||||||
|
yamldecode(file("${path.module}/cloud-init-base.yaml")),
|
||||||
|
yamldecode(templatefile("${path.module}/cloud-init-vm.yaml.tftpl", {
|
||||||
|
extra_packages = try(each.value.extra_packages, [])
|
||||||
|
extra_users = try(each.value.extra_users, [])
|
||||||
|
extra_runcmd = try(each.value.extra_runcmd, [])
|
||||||
|
}))
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
locals {
|
locals {
|
||||||
# Lê o ficheiro base (que está no mesmo módulo)
|
|
||||||
base_cloudinit = yamldecode(file("${path.module}/cloud-init-base.yaml"))
|
|
||||||
|
|
||||||
# Renderiza cada ficheiro por VM
|
|
||||||
vm_cloudinits = {
|
|
||||||
for vm in var.proxmox_k8s_vms : vm.name => yamldecode(
|
|
||||||
templatefile("${path.module}/cloud-init-vm.yaml.tftpl", {
|
|
||||||
extra_packages = try(vm.extra_packages, [])
|
|
||||||
extra_users = try(vm.extra_users, [])
|
|
||||||
extra_runcmd = try(vm.extra_runcmd, [])
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
deep_merge = function("deep_merge", [any, any], any, <<-EOT
|
deep_merge = function("deep_merge", [any, any], any, <<-EOT
|
||||||
base, override = args
|
base, override = args
|
||||||
result = {}
|
result = {}
|
||||||
@ -87,11 +81,6 @@ locals {
|
|||||||
return result
|
return result
|
||||||
EOT
|
EOT
|
||||||
)
|
)
|
||||||
|
|
||||||
merged_cloudinit = tomap({
|
|
||||||
for vm_name, vm_cfg in local.vm_cloudinits :
|
|
||||||
vm_name => local.deep_merge([local.base_cloudinit, vm_cfg])
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "proxmox_virtual_environment_vm" "proxmox-kubernetes-VM-template" {
|
resource "proxmox_virtual_environment_vm" "proxmox-kubernetes-VM-template" {
|
||||||
|
|||||||
Reference in New Issue
Block a user