Use admin_ssh_public_key content when provided, otherwise fall back to reading from admin_ssh_public_key_path file.
32 lines
1.0 KiB
HCL
32 lines
1.0 KiB
HCL
# Fichier: terraform/prod/02-cloud-init.tf
|
|
|
|
locals {
|
|
# Utilise le contenu direct si fourni (CI), sinon lit depuis le fichier (local)
|
|
ssh_public_key = var.admin_ssh_public_key != "" ? var.admin_ssh_public_key : file(var.admin_ssh_public_key_path)
|
|
}
|
|
|
|
resource "proxmox_virtual_environment_file" "cloud_config" {
|
|
for_each = var.virtual_machines
|
|
|
|
node_name = var.target_node
|
|
datastore_id = "local"
|
|
content_type = "snippets"
|
|
|
|
source_raw {
|
|
data = templatefile("${path.module}/../../cloud-init/user-data.yml.tftpl", {
|
|
# Variables pour définir les informations de l'utilisateur
|
|
username = lookup(each.value, "username", var.default_vm_user)
|
|
ssh_key = local.ssh_public_key
|
|
|
|
# Variables pour définir les informations de la VM
|
|
hostname = "${each.key}.${var.domain_suffix}"
|
|
|
|
# Nouvelles variables pour Tailscale
|
|
vm_name = each.key # Le nom de la VM (ex: "web-01")
|
|
tailscale_auth_key = var.tailscale_auth_key
|
|
})
|
|
|
|
file_name = "${each.key}-cloud-init.yml"
|
|
}
|
|
}
|