mirror of
https://gitea.fenix-dev.com/fenix-gitea-admin/iac-opentofu-private.git
synced 2025-10-27 15:53:06 +00:00
Merge pull request 'Update proxmox.tf' (#164) from fenix-admin into main
Reviewed-on: fenix-gitea-admin/iac-teste#164
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
|
||||
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"
|
||||
datastore_id = "local-snippets"
|
||||
@ -46,26 +46,20 @@ resource "proxmox_virtual_environment_file" "vm_user_data" {
|
||||
|
||||
source_raw {
|
||||
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 {
|
||||
# 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
|
||||
base, override = args
|
||||
result = {}
|
||||
@ -87,11 +81,6 @@ locals {
|
||||
return result
|
||||
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" {
|
||||
|
||||
Reference in New Issue
Block a user