diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..18f6eb0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +*.tfvars +!*.tfvars.example +*.tfstate +*.tfstate.backup +*.out +.terraform/ +.terraform.lock.hcl diff --git a/locals.tf b/locals.tf deleted file mode 100644 index aae7eae..0000000 --- a/locals.tf +++ /dev/null @@ -1,19 +0,0 @@ -locals { - # Alphabet pour la conversion base 26 des suffixes de noms de VMs. - letters = [ - "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", - "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", - "u", "v", "w", "x", "y", "z" - ] - - # Dict des VMs a deployer, genere dynamiquement a partir de var.vm_count. - # cle = nom unique de la VM ex. "9999aaaa" - # value = parametres specifiques { vmid, ip } - vms = { - for i in range(var.vm_count) : - "9999aa${local.letters[floor(i / 26)]}${local.letters[i % 26]}" => { - vmid = 9010 + i - ip = cidrhost("10.1.90.0/24", 100 + i) - } - } -} diff --git a/main.tf b/main.tf deleted file mode 100644 index 8eece42..0000000 --- a/main.tf +++ /dev/null @@ -1,50 +0,0 @@ -resource "proxmox_virtual_environment_vm" "lab" { - for_each = local.vms - - name = each.key - node_name = var.node_name - vm_id = each.value.vmid - - clone { - vm_id = var.template_id - full = true - } - - agent { - enabled = true - } - - cpu { - sockets = var.vm_cpu_sockets - cores = var.vm_cpu_cores - hotplugged = var.vm_cpu_hotplugged - } - - memory { - dedicated = var.vm_memory - } - - disk { - interface = "scsi0" - size = var.vm_disk_size - datastore_id = "local-lvm" - } - - network_device { - bridge = var.bridge - vlan_id = var.vlan_id - } - - initialization { - user_account { - username = var.ci_user - keys = [var.ssh_public_key] - } - ip_config { - ipv4 { - address = "${each.value.ip}/24" - gateway = var.gateway - } - } - } -} diff --git a/outputs.tf b/outputs.tf deleted file mode 100644 index 3bfef95..0000000 --- a/outputs.tf +++ /dev/null @@ -1,17 +0,0 @@ -output "vm_names" { - description = "Liste des noms de VMs creees" - value = [for k, v in proxmox_virtual_environment_vm.lab : v.name] -} - -output "vm_ips" { - description = "Mapping nom de VM -> IP" - value = { for name, vm in local.vms : name => vm.ip } -} - -output "ssh_commands" { - description = "Commandes SSH pretes a copier pour chaque VM" - value = [ - for name, vm in local.vms : - "ssh ${var.ci_user}@${vm.ip} # ${name}" - ] -} diff --git a/providers.tf b/providers.tf deleted file mode 100644 index c5772d7..0000000 --- a/providers.tf +++ /dev/null @@ -1,5 +0,0 @@ -provider "proxmox" { - endpoint = var.proxmox_endpoint - api_token = var.proxmox_api_token - insecure = var.proxmox_insecure -} diff --git a/terraform.tfstate b/terraform.tfstate deleted file mode 100644 index 68819c9..0000000 --- a/terraform.tfstate +++ /dev/null @@ -1 +0,0 @@ -{"version":4,"terraform_version":"1.11.5","serial":7,"lineage":"500c6307-1c37-d0cc-1c25-be2a978fbbbf","outputs":{},"resources":[],"check_results":[{"object_kind":"var","config_addr":"var.vm_count","status":"unknown","objects":null}]} diff --git a/terraform.tfstate.backup b/terraform.tfstate.backup deleted file mode 100644 index bea21e1..0000000 --- a/terraform.tfstate.backup +++ /dev/null @@ -1 +0,0 @@ -{"version":4,"terraform_version":"1.11.5","serial":6,"lineage":"500c6307-1c37-d0cc-1c25-be2a978fbbbf","outputs":{"ssh_commands":{"value":["ssh nidoradmin@10.1.90.100 # 9999aaaa","ssh nidoradmin@10.1.90.101 # 9999aaab","ssh nidoradmin@10.1.90.102 # 9999aaac"],"type":["tuple",["string","string","string"]]},"vm_ips":{"value":{"9999aaaa":"10.1.90.100","9999aaab":"10.1.90.101","9999aaac":"10.1.90.102"},"type":["object",{"9999aaaa":"string","9999aaab":"string","9999aaac":"string"}]},"vm_names":{"value":["9999aaaa","9999aaab","9999aaac"],"type":["tuple",["string","string","string"]]}},"resources":[{"mode":"managed","type":"proxmox_virtual_environment_vm","name":"lab","provider":"provider[\"registry.opentofu.org/bpg/proxmox\"]","instances":[{"index_key":"9999aaaa","schema_version":0,"attributes":{"acpi":true,"agent":[{"enabled":true,"timeout":"15m","trim":false,"type":"virtio","wait_for_ip":[]}],"amd_sev":[],"audio_device":[],"bios":"seabios","boot_order":[],"cdrom":[],"clone":[{"datastore_id":"","full":true,"node_name":"","retries":1,"vm_id":100}],"cpu":[{"affinity":"","architecture":"","cores":12,"flags":null,"hotplugged":2,"limit":0,"numa":false,"sockets":1,"type":"qemu64","units":0}],"delete_unreferenced_disks_on_destroy":true,"description":null,"disk":[{"aio":"io_uring","backup":true,"cache":"none","datastore_id":"local-lvm","discard":"ignore","file_format":"raw","file_id":"","import_from":"","interface":"scsi0","iothread":false,"path_in_datastore":"vm-9010-disk-0","replicate":true,"serial":"","size":10,"speed":[],"ssd":false}],"efi_disk":[],"hook_script_file_id":null,"hostpci":[],"hotplug":null,"id":"9010","initialization":[{"datastore_id":"local-lvm","dns":[],"file_format":"","interface":"ide2","ip_config":[{"ipv4":[{"address":"10.1.90.100/24","gateway":"10.1.90.1"}],"ipv6":[]}],"meta_data_file_id":"","network_data_file_id":"","type":"","upgrade":true,"user_account":[{"keys":["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDV8PkUNKeIftHKf+nrS9CH9pUlOSJ8s27ejEgqH3kAs dorygann@fedora"],"password":"","username":"nidoradmin"}],"user_data_file_id":"","vendor_data_file_id":""}],"ipv4_addresses":[["127.0.0.1"],["10.1.90.100"]],"ipv6_addresses":[["::1"],["fe80::be24:11ff:fe35:3569"]],"keyboard_layout":"en-us","kvm_arguments":null,"mac_addresses":["00:00:00:00:00:00","BC:24:11:35:35:69"],"machine":null,"memory":[{"dedicated":1024,"floating":0,"hugepages":"","keep_hugepages":false,"shared":0}],"migrate":false,"name":"9999aaaa","network_device":[{"bridge":"vmbr0","disconnected":false,"enabled":true,"firewall":false,"mac_address":"BC:24:11:35:35:69","model":"virtio","mtu":0,"queues":0,"rate_limit":0,"trunks":"","vlan_id":90}],"network_interface_names":["lo","eth0"],"node_name":"npx-666942cd","numa":[],"on_boot":true,"operating_system":[],"pool_id":"","protection":false,"purge_on_destroy":true,"reboot":false,"reboot_after_update":true,"rng":[],"scsi_hardware":"virtio-scsi-pci","serial_device":[],"smbios":[],"started":true,"startup":[],"stop_on_destroy":false,"tablet_device":true,"tags":null,"template":false,"timeout_clone":1800,"timeout_create":1800,"timeout_migrate":1800,"timeout_move_disk":1800,"timeout_reboot":1800,"timeout_shutdown_vm":1800,"timeout_start_vm":1800,"timeout_stop_vm":300,"tpm_state":[],"usb":[],"vga":[],"virtiofs":[],"vm_id":9010,"watchdog":[]},"sensitive_attributes":[[{"type":"get_attr","value":"initialization"},{"type":"index","value":{"value":0,"type":"number"}},{"type":"get_attr","value":"user_account"},{"type":"index","value":{"value":0,"type":"number"}},{"type":"get_attr","value":"password"}]],"private":"bnVsbA=="},{"index_key":"9999aaab","schema_version":0,"attributes":{"acpi":true,"agent":[{"enabled":true,"timeout":"15m","trim":false,"type":"virtio","wait_for_ip":[]}],"amd_sev":[],"audio_device":[],"bios":"seabios","boot_order":[],"cdrom":[],"clone":[{"datastore_id":"","full":true,"node_name":"","retries":1,"vm_id":100}],"cpu":[{"affinity":"","architecture":"","cores":12,"flags":null,"hotplugged":2,"limit":0,"numa":false,"sockets":1,"type":"qemu64","units":0}],"delete_unreferenced_disks_on_destroy":true,"description":null,"disk":[{"aio":"io_uring","backup":true,"cache":"none","datastore_id":"local-lvm","discard":"ignore","file_format":"raw","file_id":"","import_from":"","interface":"scsi0","iothread":false,"path_in_datastore":"vm-9011-disk-0","replicate":true,"serial":"","size":10,"speed":[],"ssd":false}],"efi_disk":[],"hook_script_file_id":null,"hostpci":[],"hotplug":null,"id":"9011","initialization":[{"datastore_id":"local-lvm","dns":[],"file_format":"","interface":"ide2","ip_config":[{"ipv4":[{"address":"10.1.90.101/24","gateway":"10.1.90.1"}],"ipv6":[]}],"meta_data_file_id":"","network_data_file_id":"","type":"","upgrade":true,"user_account":[{"keys":["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDV8PkUNKeIftHKf+nrS9CH9pUlOSJ8s27ejEgqH3kAs dorygann@fedora"],"password":"","username":"nidoradmin"}],"user_data_file_id":"","vendor_data_file_id":""}],"ipv4_addresses":[["127.0.0.1"],["10.1.90.101"]],"ipv6_addresses":[["::1"],["fe80::be24:11ff:fe7c:d4ab"]],"keyboard_layout":"en-us","kvm_arguments":null,"mac_addresses":["00:00:00:00:00:00","BC:24:11:7C:D4:AB"],"machine":null,"memory":[{"dedicated":1024,"floating":0,"hugepages":"","keep_hugepages":false,"shared":0}],"migrate":false,"name":"9999aaab","network_device":[{"bridge":"vmbr0","disconnected":false,"enabled":true,"firewall":false,"mac_address":"BC:24:11:7C:D4:AB","model":"virtio","mtu":0,"queues":0,"rate_limit":0,"trunks":"","vlan_id":90}],"network_interface_names":["lo","eth0"],"node_name":"npx-666942cd","numa":[],"on_boot":true,"operating_system":[],"pool_id":"","protection":false,"purge_on_destroy":true,"reboot":false,"reboot_after_update":true,"rng":[],"scsi_hardware":"virtio-scsi-pci","serial_device":[],"smbios":[],"started":true,"startup":[],"stop_on_destroy":false,"tablet_device":true,"tags":null,"template":false,"timeout_clone":1800,"timeout_create":1800,"timeout_migrate":1800,"timeout_move_disk":1800,"timeout_reboot":1800,"timeout_shutdown_vm":1800,"timeout_start_vm":1800,"timeout_stop_vm":300,"tpm_state":[],"usb":[],"vga":[],"virtiofs":[],"vm_id":9011,"watchdog":[]},"sensitive_attributes":[[{"type":"get_attr","value":"initialization"},{"type":"index","value":{"value":0,"type":"number"}},{"type":"get_attr","value":"user_account"},{"type":"index","value":{"value":0,"type":"number"}},{"type":"get_attr","value":"password"}]],"private":"bnVsbA=="},{"index_key":"9999aaac","schema_version":0,"attributes":{"acpi":true,"agent":[{"enabled":true,"timeout":"15m","trim":false,"type":"virtio","wait_for_ip":[]}],"amd_sev":[],"audio_device":[],"bios":"seabios","boot_order":[],"cdrom":[],"clone":[{"datastore_id":"","full":true,"node_name":"","retries":1,"vm_id":100}],"cpu":[{"affinity":"","architecture":"","cores":12,"flags":null,"hotplugged":2,"limit":0,"numa":false,"sockets":1,"type":"qemu64","units":0}],"delete_unreferenced_disks_on_destroy":true,"description":null,"disk":[{"aio":"io_uring","backup":true,"cache":"none","datastore_id":"local-lvm","discard":"ignore","file_format":"raw","file_id":"","import_from":"","interface":"scsi0","iothread":false,"path_in_datastore":"vm-9012-disk-0","replicate":true,"serial":"","size":10,"speed":[],"ssd":false}],"efi_disk":[],"hook_script_file_id":null,"hostpci":[],"hotplug":null,"id":"9012","initialization":[{"datastore_id":"local-lvm","dns":[],"file_format":"","interface":"ide2","ip_config":[{"ipv4":[{"address":"10.1.90.102/24","gateway":"10.1.90.1"}],"ipv6":[]}],"meta_data_file_id":"","network_data_file_id":"","type":"","upgrade":true,"user_account":[{"keys":["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDV8PkUNKeIftHKf+nrS9CH9pUlOSJ8s27ejEgqH3kAs dorygann@fedora"],"password":"","username":"nidoradmin"}],"user_data_file_id":"","vendor_data_file_id":""}],"ipv4_addresses":[["127.0.0.1"],["10.1.90.102"]],"ipv6_addresses":[["::1"],["fe80::be24:11ff:fe45:9627"]],"keyboard_layout":"en-us","kvm_arguments":null,"mac_addresses":["00:00:00:00:00:00","BC:24:11:45:96:27"],"machine":null,"memory":[{"dedicated":1024,"floating":0,"hugepages":"","keep_hugepages":false,"shared":0}],"migrate":false,"name":"9999aaac","network_device":[{"bridge":"vmbr0","disconnected":false,"enabled":true,"firewall":false,"mac_address":"BC:24:11:45:96:27","model":"virtio","mtu":0,"queues":0,"rate_limit":0,"trunks":"","vlan_id":90}],"network_interface_names":["lo","eth0"],"node_name":"npx-666942cd","numa":[],"on_boot":true,"operating_system":[],"pool_id":"","protection":false,"purge_on_destroy":true,"reboot":false,"reboot_after_update":true,"rng":[],"scsi_hardware":"virtio-scsi-pci","serial_device":[],"smbios":[],"started":true,"startup":[],"stop_on_destroy":false,"tablet_device":true,"tags":null,"template":false,"timeout_clone":1800,"timeout_create":1800,"timeout_migrate":1800,"timeout_move_disk":1800,"timeout_reboot":1800,"timeout_shutdown_vm":1800,"timeout_start_vm":1800,"timeout_stop_vm":300,"tpm_state":[],"usb":[],"vga":[],"virtiofs":[],"vm_id":9012,"watchdog":[]},"sensitive_attributes":[[{"type":"get_attr","value":"initialization"},{"type":"index","value":{"value":0,"type":"number"}},{"type":"get_attr","value":"user_account"},{"type":"index","value":{"value":0,"type":"number"}},{"type":"get_attr","value":"password"}]],"private":"bnVsbA=="}]}],"check_results":[{"object_kind":"var","config_addr":"var.vm_count","status":"pass","objects":[{"object_addr":"var.vm_count","status":"pass"}]}]} diff --git a/terraform.tfvars b/terraform.tfvars deleted file mode 100644 index 5b8801a..0000000 --- a/terraform.tfvars +++ /dev/null @@ -1,10 +0,0 @@ -# Copier en `terraform.tfvars` puis remplacer les placeholders -# par les vraies valeurs. Toutes les variables listees ici sont obligatoires - -proxmox_endpoint = "https://npx-666942cd.nia.nidora.lan:8006" -proxmox_api_token = "tofu@pam!opentofu=f59770a7-df52-4744-a7f2-9b44113924f9" -proxmox_insecure = true - -node_name = "npx-666942cd" - -ssh_public_key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDV8PkUNKeIftHKf+nrS9CH9pUlOSJ8s27ejEgqH3kAs dorygann@fedora" diff --git a/terraform.tfvars.example b/terraform.tfvars.example deleted file mode 100644 index 937d399..0000000 --- a/terraform.tfvars.example +++ /dev/null @@ -1,16 +0,0 @@ -# Copier en `terraform.tfvars` puis remplacer les placeholders par les vraies valeurs. -# Toutes les variables listees ici sont obligatoires (sans default cote variables.tf). -# -# Note : `vm_count` est aussi obligatoire mais volontairement absente ici pour -# etre promptee a chaque `tofu plan` / `tofu apply`. Decommenter la ligne en bas -# si tu veux la figer. - -proxmox_endpoint = "https://:8006" -proxmox_api_token = "root@pam!sio-routage=00000000-0000-0000-0000-000000000000" -proxmox_insecure = true - -node_name = "" - -ssh_public_key = "ssh-ed25519 AAAA... user@host" - -# vm_count = 3 diff --git a/variables.tf b/variables.tf deleted file mode 100644 index ba3d92d..0000000 --- a/variables.tf +++ /dev/null @@ -1,99 +0,0 @@ -# =================== OBLIGATOIRES (sans default) =================== - -variable "proxmox_endpoint" { - description = "URL HTTPS Proxmox" - type = string -} - -variable "proxmox_api_token" { - description = "USER@REALM!TOKENID=SECRET" - type = string - sensitive = true -} - -variable "proxmox_insecure" { - description = "Skip TLS" - type = bool -} - -variable "node_name" { - description = "Nom du node PVE" - type = string -} - -variable "ssh_public_key" { - description = "Cle SSH publique cloudinit" - type = string -} - -variable "vm_count" { - description = "Nombre de VMs a deployer (1 a 90)" - type = number - - validation { - condition = var.vm_count >= 1 && var.vm_count <= 90 - error_message = "vm_count doit etre entre 1 et 90 (limite vm_id 9010-9099)." - } -} - -# =================== OPTIONNELLES (avec default) =================== - -variable "template_id" { - description = "ID Proxmox du template a cloner" - type = number - default = 100 -} - -variable "vm_cpu_sockets" { - description = "Nombre de sockets alloues a la VM" - type = number - default = 1 -} - -variable "vm_cpu_cores" { - description = "Nombre de vCPU alloues a la VM" - type = number - default = 12 -} - -variable "vm_cpu_hotplugged" { - description = "Nombre de vCPUs actifs au boot" - type = number - default = 2 -} - -variable "vm_memory" { - description = "RAM dediee a la VM en MiB" - type = number - default = 1024 -} - -variable "vm_disk_size" { - description = "Taille du disque en GiB" - type = number - default = 10 -} - -variable "bridge" { - description = "Bridge Proxmox" - type = string - default = "vmbr0" -} - -variable "vlan_id" { - description = "VLAN tag applique" - type = number - default = 90 -} - -variable "ci_user" { - description = "Compte unix cree par cloud-init" - type = string - default = "nidoradmin" -} - -variable "gateway" { - description = "Gateway IPv4 du subnet" - type = string - default = "10.1.90.1" -} diff --git a/versions.tf b/versions.tf deleted file mode 100644 index b234dd2..0000000 --- a/versions.tf +++ /dev/null @@ -1,10 +0,0 @@ -terraform { - required_version = ">= 1.8" - - required_providers { - proxmox = { - source = "bpg/proxmox" - version = "~> 0.78" - } - } -}