diff --git a/create-vm-ubuntu/main.tf b/create-vm-ubuntu/main.tf index 587afc7..5f97337 100644 --- a/create-vm-ubuntu/main.tf +++ b/create-vm-ubuntu/main.tf @@ -1,7 +1,27 @@ -resource "proxmox_virtual_environment_vm" "vm_ubuntu" { +data "proxmox_files" "ubuntu_image" { + content_type = "import" + node_name = var.target_node + datastore_id = "local" + file_name_regex = "jammy" +} + +resource "proxmox_virtual_environment_vm" "vm_ubuntu_iscsi" { + count = 3 + vm_id = 100 + count.index + 2 + name = "ubuntu-cloud-vm-${count.index + 1}" node_name = var.target_node - name = "vm-ubuntu" - vm_id = 1100 + + initialization { + ip_config { + ipv4 { + address = "dhcp" + } + } + user_account { + username = "root" + password = "rootroot" + } + } cpu { cores = 2 @@ -12,14 +32,13 @@ resource "proxmox_virtual_environment_vm" "vm_ubuntu" { } network_device { - bridge = "vmbr0" + bridge = "vmbr1" } disk { - import_from = "local:iso/jammy-server-cloudimg-amd64.img" + interface = "scsi0" + datastore_id = "truenas_lvm" + import_from = data.proxmox_files.ubuntu_image.files[0].id } - initialization { - - } } diff --git a/create-vm-ubuntu/outputs.tf b/create-vm-ubuntu/outputs.tf index 4213455..0a38255 100644 --- a/create-vm-ubuntu/outputs.tf +++ b/create-vm-ubuntu/outputs.tf @@ -1,4 +1,4 @@ output "vm_status" { - value = proxmox_virtual_environment_vm.vm_ubuntu.ipv4_addresses + value = proxmox_virtual_environment_vm.vm_ubuntu_iscsi[*].all description = "Les adresses IP de la VM créée" } diff --git a/create-vm-ubuntu/terraform.tfstate b/create-vm-ubuntu/terraform.tfstate index 58547f1..2180f18 100644 --- a/create-vm-ubuntu/terraform.tfstate +++ b/create-vm-ubuntu/terraform.tfstate @@ -1,28 +1,81 @@ { "version": 4, "terraform_version": "1.15.1", - "serial": 7, + "serial": 33, "lineage": "932f91fd-26ce-0c13-df63-09cd25a0eb0f", "outputs": { "vm_status": { - "value": [], + "value": [ + [], + [], + [] + ], "type": [ - "list", + "tuple", [ - "list", - "string" + [ + "list", + [ + "list", + "string" + ] + ], + [ + "list", + [ + "list", + "string" + ] + ], + [ + "list", + [ + "list", + "string" + ] + ] ] ] } }, "resources": [ { - "mode": "managed", - "type": "proxmox_virtual_environment_vm", - "name": "vm_ubuntu", + "mode": "data", + "type": "proxmox_files", + "name": "ubuntu_image", "provider": "provider[\"registry.terraform.io/bpg/proxmox\"]", "instances": [ { + "schema_version": 0, + "attributes": { + "content_type": "import", + "datastore_id": "local", + "file_name_regex": "jammy", + "files": [ + { + "content_type": "import", + "file_format": "qcow2", + "file_name": "jammy-server-cloudimg-amd64.qcow2", + "file_size": 692407808, + "id": "local:import/jammy-server-cloudimg-amd64.qcow2", + "vmid": null + } + ], + "node_name": "pve1" + }, + "sensitive_attributes": [], + "identity_schema_version": 0 + } + ] + }, + { + "mode": "managed", + "type": "proxmox_virtual_environment_vm", + "name": "vm_ubuntu_iscsi", + "provider": "provider[\"registry.terraform.io/bpg/proxmox\"]", + "instances": [ + { + "index_key": 0, "schema_version": 0, "attributes": { "acpi": true, @@ -31,16 +84,10 @@ "audio_device": [], "bios": "seabios", "boot_order": [ - "ide3", + "scsi0", "net0" ], - "cdrom": [ - { - "enabled": false, - "file_id": "local:iso/jammy-server-cloudimg-amd64.img", - "interface": "ide3" - } - ], + "cdrom": [], "clone": [], "cpu": [ { @@ -58,19 +105,69 @@ ], "delete_unreferenced_disks_on_destroy": true, "description": "", - "disk": [], + "disk": [ + { + "aio": "io_uring", + "backup": true, + "cache": "none", + "datastore_id": "truenas_lvm", + "discard": "ignore", + "file_format": "raw", + "file_id": "", + "import_from": "local:import/jammy-server-cloudimg-amd64.qcow2", + "interface": "scsi0", + "iothread": false, + "path_in_datastore": "vm-102-disk-0", + "replicate": true, + "serial": "", + "size": 8, + "speed": [], + "ssd": false + } + ], "efi_disk": [], "hook_script_file_id": null, "hostpci": [], "hotplug": null, - "id": "1100", - "initialization": [], + "id": "102", + "initialization": [ + { + "datastore_id": "local-lvm", + "dns": [], + "file_format": "", + "interface": "ide2", + "ip_config": [ + { + "ipv4": [ + { + "address": "dhcp", + "gateway": "" + } + ], + "ipv6": [] + } + ], + "meta_data_file_id": "", + "network_data_file_id": "", + "type": "", + "upgrade": true, + "user_account": [ + { + "keys": null, + "password": "**********", + "username": "root" + } + ], + "user_data_file_id": "", + "vendor_data_file_id": "" + } + ], "ipv4_addresses": [], "ipv6_addresses": [], "keyboard_layout": "en-us", "kvm_arguments": "", "mac_addresses": [ - "BC:24:11:AE:FB:4F" + "BC:24:11:F0:0B:68" ], "machine": "", "memory": [ @@ -83,14 +180,14 @@ } ], "migrate": false, - "name": "vm-ubuntu", + "name": "ubuntu-cloud-vm-1", "network_device": [ { - "bridge": "vmbr0", + "bridge": "vmbr1", "disconnected": false, "enabled": true, "firewall": false, - "mac_address": "BC:24:11:AE:FB:4F", + "mac_address": "BC:24:11:F0:0B:68", "model": "virtio", "mtu": 0, "queues": 0, @@ -131,12 +228,430 @@ "usb": [], "vga": [], "virtiofs": [], - "vm_id": 1100, + "vm_id": 102, "watchdog": [] }, - "sensitive_attributes": [], + "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" + } + ] + ], "identity_schema_version": 0, - "private": "bnVsbA==" + "private": "bnVsbA==", + "dependencies": [ + "data.proxmox_files.ubuntu_image" + ] + }, + { + "index_key": 1, + "schema_version": 0, + "attributes": { + "acpi": true, + "agent": [], + "amd_sev": [], + "audio_device": [], + "bios": "seabios", + "boot_order": [ + "scsi0", + "net0" + ], + "cdrom": [], + "clone": [], + "cpu": [ + { + "affinity": "", + "architecture": "", + "cores": 2, + "flags": null, + "hotplugged": 0, + "limit": 0, + "numa": false, + "sockets": 1, + "type": "qemu64", + "units": 0 + } + ], + "delete_unreferenced_disks_on_destroy": true, + "description": "", + "disk": [ + { + "aio": "io_uring", + "backup": true, + "cache": "none", + "datastore_id": "truenas_lvm", + "discard": "ignore", + "file_format": "raw", + "file_id": "", + "import_from": "local:import/jammy-server-cloudimg-amd64.qcow2", + "interface": "scsi0", + "iothread": false, + "path_in_datastore": "vm-103-disk-0", + "replicate": true, + "serial": "", + "size": 8, + "speed": [], + "ssd": false + } + ], + "efi_disk": [], + "hook_script_file_id": null, + "hostpci": [], + "hotplug": null, + "id": "103", + "initialization": [ + { + "datastore_id": "local-lvm", + "dns": [], + "file_format": "", + "interface": "ide2", + "ip_config": [ + { + "ipv4": [ + { + "address": "dhcp", + "gateway": "" + } + ], + "ipv6": [] + } + ], + "meta_data_file_id": "", + "network_data_file_id": "", + "type": "", + "upgrade": true, + "user_account": [ + { + "keys": null, + "password": "**********", + "username": "root" + } + ], + "user_data_file_id": "", + "vendor_data_file_id": "" + } + ], + "ipv4_addresses": [], + "ipv6_addresses": [], + "keyboard_layout": "en-us", + "kvm_arguments": "", + "mac_addresses": [ + "BC:24:11:BC:8C:9C" + ], + "machine": "", + "memory": [ + { + "dedicated": 2048, + "floating": 0, + "hugepages": "", + "keep_hugepages": false, + "shared": 0 + } + ], + "migrate": false, + "name": "ubuntu-cloud-vm-2", + "network_device": [ + { + "bridge": "vmbr1", + "disconnected": false, + "enabled": true, + "firewall": false, + "mac_address": "BC:24:11:BC:8C:9C", + "model": "virtio", + "mtu": 0, + "queues": 0, + "rate_limit": 0, + "trunks": "", + "vlan_id": 0 + } + ], + "network_interface_names": [], + "node_name": "pve1", + "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": 103, + "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" + } + ] + ], + "identity_schema_version": 0, + "private": "bnVsbA==", + "dependencies": [ + "data.proxmox_files.ubuntu_image" + ] + }, + { + "index_key": 2, + "schema_version": 0, + "attributes": { + "acpi": true, + "agent": [], + "amd_sev": [], + "audio_device": [], + "bios": "seabios", + "boot_order": [ + "scsi0", + "net0" + ], + "cdrom": [], + "clone": [], + "cpu": [ + { + "affinity": "", + "architecture": "", + "cores": 2, + "flags": null, + "hotplugged": 0, + "limit": 0, + "numa": false, + "sockets": 1, + "type": "qemu64", + "units": 0 + } + ], + "delete_unreferenced_disks_on_destroy": true, + "description": "", + "disk": [ + { + "aio": "io_uring", + "backup": true, + "cache": "none", + "datastore_id": "truenas_lvm", + "discard": "ignore", + "file_format": "raw", + "file_id": "", + "import_from": "local:import/jammy-server-cloudimg-amd64.qcow2", + "interface": "scsi0", + "iothread": false, + "path_in_datastore": "vm-104-disk-0", + "replicate": true, + "serial": "", + "size": 8, + "speed": [], + "ssd": false + } + ], + "efi_disk": [], + "hook_script_file_id": null, + "hostpci": [], + "hotplug": null, + "id": "104", + "initialization": [ + { + "datastore_id": "local-lvm", + "dns": [], + "file_format": "", + "interface": "ide2", + "ip_config": [ + { + "ipv4": [ + { + "address": "dhcp", + "gateway": "" + } + ], + "ipv6": [] + } + ], + "meta_data_file_id": "", + "network_data_file_id": "", + "type": "", + "upgrade": true, + "user_account": [ + { + "keys": null, + "password": "**********", + "username": "root" + } + ], + "user_data_file_id": "", + "vendor_data_file_id": "" + } + ], + "ipv4_addresses": [], + "ipv6_addresses": [], + "keyboard_layout": "en-us", + "kvm_arguments": "", + "mac_addresses": [ + "BC:24:11:7C:BB:37" + ], + "machine": "", + "memory": [ + { + "dedicated": 2048, + "floating": 0, + "hugepages": "", + "keep_hugepages": false, + "shared": 0 + } + ], + "migrate": false, + "name": "ubuntu-cloud-vm-3", + "network_device": [ + { + "bridge": "vmbr1", + "disconnected": false, + "enabled": true, + "firewall": false, + "mac_address": "BC:24:11:7C:BB:37", + "model": "virtio", + "mtu": 0, + "queues": 0, + "rate_limit": 0, + "trunks": "", + "vlan_id": 0 + } + ], + "network_interface_names": [], + "node_name": "pve1", + "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": 104, + "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" + } + ] + ], + "identity_schema_version": 0, + "private": "bnVsbA==", + "dependencies": [ + "data.proxmox_files.ubuntu_image" + ] } ] } diff --git a/create-vm-ubuntu/terraform.tfstate.backup b/create-vm-ubuntu/terraform.tfstate.backup index 44e951c..6fa58dc 100644 --- a/create-vm-ubuntu/terraform.tfstate.backup +++ b/create-vm-ubuntu/terraform.tfstate.backup @@ -1,7 +1,7 @@ { "version": 4, "terraform_version": "1.15.1", - "serial": 4, + "serial": 27, "lineage": "932f91fd-26ce-0c13-df63-09cd25a0eb0f", "outputs": { "vm_status": { @@ -16,10 +16,39 @@ } }, "resources": [ + { + "mode": "data", + "type": "proxmox_files", + "name": "ubuntu_image", + "provider": "provider[\"registry.terraform.io/bpg/proxmox\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "content_type": "import", + "datastore_id": "local", + "file_name_regex": "jammy", + "files": [ + { + "content_type": "import", + "file_format": "qcow2", + "file_name": "jammy-server-cloudimg-amd64.qcow2", + "file_size": 692407808, + "id": "local:import/jammy-server-cloudimg-amd64.qcow2", + "vmid": null + } + ], + "node_name": "pve1" + }, + "sensitive_attributes": [], + "identity_schema_version": 0 + } + ] + }, { "mode": "managed", "type": "proxmox_virtual_environment_vm", - "name": "ma_super_vm", + "name": "vm_ubuntu_iscsi", "provider": "provider[\"registry.terraform.io/bpg/proxmox\"]", "instances": [ { @@ -31,16 +60,210 @@ "audio_device": [], "bios": "seabios", "boot_order": [ - "ide3", + "scsi0", "net0" ], - "cdrom": [ + "cdrom": [], + "clone": [], + "cpu": [ { - "enabled": false, - "file_id": "local:iso/alpine-standard-3.23.4-x86_64.iso", - "interface": "ide3" + "affinity": "", + "architecture": "", + "cores": 2, + "flags": null, + "hotplugged": 0, + "limit": 0, + "numa": false, + "sockets": 1, + "type": "qemu64", + "units": 0 } ], + "delete_unreferenced_disks_on_destroy": true, + "description": "", + "disk": [ + { + "aio": "io_uring", + "backup": true, + "cache": "none", + "datastore_id": "truenas_lvm", + "discard": "ignore", + "file_format": "raw", + "file_id": "", + "import_from": "local:import/jammy-server-cloudimg-amd64.qcow2", + "interface": "scsi0", + "iothread": false, + "path_in_datastore": "vm-101-disk-0", + "replicate": true, + "serial": "", + "size": 8, + "speed": [], + "ssd": false + } + ], + "efi_disk": [], + "hook_script_file_id": null, + "hostpci": [], + "hotplug": null, + "id": "101", + "initialization": [ + { + "datastore_id": "local-lvm", + "dns": [], + "file_format": "", + "interface": "ide2", + "ip_config": [ + { + "ipv4": [ + { + "address": "dhcp", + "gateway": "" + } + ], + "ipv6": [] + } + ], + "meta_data_file_id": "", + "network_data_file_id": "", + "type": "", + "upgrade": true, + "user_account": [ + { + "keys": null, + "password": "**********", + "username": "root" + } + ], + "user_data_file_id": "", + "vendor_data_file_id": "" + } + ], + "ipv4_addresses": [], + "ipv6_addresses": [], + "keyboard_layout": "en-us", + "kvm_arguments": "", + "mac_addresses": [ + "BC:24:11:FB:1B:D9" + ], + "machine": "", + "memory": [ + { + "dedicated": 2048, + "floating": 0, + "hugepages": "", + "keep_hugepages": false, + "shared": 0 + } + ], + "migrate": false, + "name": "ubuntu-cloud-vm-iscsi", + "network_device": [ + { + "bridge": "vmbr1", + "disconnected": false, + "enabled": true, + "firewall": false, + "mac_address": "BC:24:11:FB:1B:D9", + "model": "virtio", + "mtu": 0, + "queues": 0, + "rate_limit": 0, + "trunks": "", + "vlan_id": 0 + } + ], + "network_interface_names": [], + "node_name": "pve1", + "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": 101, + "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" + } + ] + ], + "identity_schema_version": 0, + "private": "bnVsbA==", + "dependencies": [ + "data.proxmox_files.ubuntu_image" + ] + } + ] + }, + { + "mode": "managed", + "type": "proxmox_virtual_environment_vm", + "name": "vm_ubuntu_local", + "provider": "provider[\"registry.terraform.io/bpg/proxmox\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "acpi": true, + "agent": [], + "amd_sev": [], + "audio_device": [], + "bios": "seabios", + "boot_order": [ + "scsi0", + "net0" + ], + "cdrom": [], "clone": [], "cpu": [ { @@ -58,19 +281,69 @@ ], "delete_unreferenced_disks_on_destroy": true, "description": "", - "disk": [], + "disk": [ + { + "aio": "io_uring", + "backup": true, + "cache": "none", + "datastore_id": "local-lvm", + "discard": "ignore", + "file_format": "raw", + "file_id": "", + "import_from": "local:import/jammy-server-cloudimg-amd64.qcow2", + "interface": "scsi0", + "iothread": false, + "path_in_datastore": "vm-102-disk-0", + "replicate": true, + "serial": "", + "size": 8, + "speed": [], + "ssd": false + } + ], "efi_disk": [], "hook_script_file_id": null, "hostpci": [], "hotplug": null, - "id": "1000", - "initialization": [], + "id": "102", + "initialization": [ + { + "datastore_id": "local-lvm", + "dns": [], + "file_format": "", + "interface": "ide2", + "ip_config": [ + { + "ipv4": [ + { + "address": "dhcp", + "gateway": "" + } + ], + "ipv6": [] + } + ], + "meta_data_file_id": "", + "network_data_file_id": "", + "type": "", + "upgrade": true, + "user_account": [ + { + "keys": [], + "password": "**********", + "username": "root" + } + ], + "user_data_file_id": "", + "vendor_data_file_id": "" + } + ], "ipv4_addresses": [], "ipv6_addresses": [], "keyboard_layout": "en-us", "kvm_arguments": "", "mac_addresses": [ - "BC:24:11:C1:5F:18" + "BC:24:11:52:A8:CA" ], "machine": "", "memory": [ @@ -83,14 +356,14 @@ } ], "migrate": false, - "name": "vm-terraform-demo", + "name": "ubuntu-cloud-vm-local", "network_device": [ { - "bridge": "vmbr0", + "bridge": "vmbr1", "disconnected": false, "enabled": true, "firewall": false, - "mac_address": "BC:24:11:C1:5F:18", + "mac_address": "BC:24:11:52:A8:CA", "model": "virtio", "mtu": 0, "queues": 0, @@ -131,12 +404,44 @@ "usb": [], "vga": [], "virtiofs": [], - "vm_id": 1000, + "vm_id": 102, "watchdog": [] }, - "sensitive_attributes": [], + "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" + } + ] + ], "identity_schema_version": 0, - "private": "bnVsbA==" + "private": "bnVsbA==", + "dependencies": [ + "data.proxmox_files.ubuntu_image" + ] } ] }