mirror of
https://gitea.fenix-dev.com/fenix-gitea-admin/iac-opentofu-private.git
synced 2025-10-27 07:43:07 +00:00
Merge pull request 'Update proxmox.tf' (#133) from fenix-admin into main
Reviewed-on: fenix-gitea-admin/iac-teste#133
This commit is contained in:
84
proxmox.tf
84
proxmox.tf
@ -51,6 +51,56 @@ 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 = { for vm in var.k8s_vms : vm.name => vm }
|
||||
|
||||
node_name = "fenix"
|
||||
datastore_id = "local-snippets"
|
||||
content_type = "snippets"
|
||||
|
||||
source_raw {
|
||||
file_name = "cloud-init-iac-k8s-${each.value.name}.yaml"
|
||||
source_raw {
|
||||
<<EOF
|
||||
#cloud-config
|
||||
package_update: true
|
||||
packages:
|
||||
%{ for pkg in each.value.packages ~}
|
||||
- ${pkg}
|
||||
%{ endfor ~}
|
||||
|
||||
users:
|
||||
%{ if length(each.value.extra_users) > 0 ~}
|
||||
|
||||
%{ for u in each.value.extra_users ~}
|
||||
- name: ${u.name}
|
||||
groups: [${join(", ", u.groups)}]
|
||||
shell: /bin/bash
|
||||
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||
%{ endfor ~}
|
||||
|
||||
chpasswd:
|
||||
list: |
|
||||
%{ for u in each.value.extra_users ~}
|
||||
${u.name}:${u.password}
|
||||
%{ endfor ~}
|
||||
expire: false
|
||||
|
||||
%{ endif ~}
|
||||
runcmd:
|
||||
%{ if length(each.value.extra_runcmd) > 0 ~}
|
||||
%{ for cmd in each.value.extra_runcmd ~}
|
||||
- ${cmd}
|
||||
%{ endfor ~}
|
||||
%{ endif ~}
|
||||
EOF
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
resource "proxmox_virtual_environment_vm" "proxmox-kubernetes-VM-template" {
|
||||
|
||||
depends_on = [proxmox_virtual_environment_download_file.latest_ubunto_cloud_img, proxmox_virtual_environment_file.cloud_init_yaml]
|
||||
@ -141,39 +191,7 @@ resource "proxmox_virtual_environment_vm" "k8s_vms" {
|
||||
}
|
||||
}
|
||||
|
||||
user_data = <<EOF
|
||||
#cloud-config
|
||||
package_update: true
|
||||
packages:
|
||||
%{ for pkg in each.value.packages ~}
|
||||
- ${pkg}
|
||||
%{ endfor ~}
|
||||
|
||||
users:
|
||||
%{ if length(each.value.extra_users) > 0 ~}
|
||||
|
||||
%{ for u in each.value.extra_users ~}
|
||||
- name: ${u.name}
|
||||
groups: [${join(", ", u.groups)}]
|
||||
shell: /bin/bash
|
||||
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||
%{ endfor ~}
|
||||
|
||||
chpasswd:
|
||||
list: |
|
||||
%{ for u in each.value.extra_users ~}
|
||||
${u.name}:${u.password}
|
||||
%{ endfor ~}
|
||||
expire: false
|
||||
|
||||
%{ endif ~}
|
||||
runcmd:
|
||||
%{ if length(each.value.extra_runcmd) > 0 ~}
|
||||
%{ for cmd in each.value.extra_runcmd ~}
|
||||
- ${cmd}
|
||||
%{ endfor ~}
|
||||
%{ endif ~}
|
||||
EOF
|
||||
user_data_file_id = proxmox_virtual_environment_file.vm_user_data[each.key].id
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user