diff --git a/cloud-init/user-data.yml b/cloud-init/user-data.yml new file mode 100644 index 0000000..987b0b5 --- /dev/null +++ b/cloud-init/user-data.yml @@ -0,0 +1,19 @@ +package_upgrade: true +packages: + - qemu-guest-agent + +timezone: Europe/Berlin +users: + - name: gyptazy + passwd: $6$F2NA9T240RZLC7cm$9JcyNJ6vHw0FidyCH7YlDGVE3.4y9K/KtWoCIcP1zb7Kdox/cPWwudNybjX.km11mmd2El5jDKTe0eLxI7s5l. + lock-passwd: false + sudo: ALL=(ALL) NOPASSWD:ALL + shell: /bin/bash + ssh_authorized_keys: + - AAAAC3NzaF1D4NTE5AAAAIJe45xj6fsadGHesfdadsJFGZxasdfads/gjVmr gyptazy + +power_state: + delay: now + mode: reboot + message: Rebooting after cloud-init completion + condition: true diff --git a/files.tf b/files.tf new file mode 100644 index 0000000..adac1d3 --- /dev/null +++ b/files.tf @@ -0,0 +1,22 @@ +resource "proxmox_virtual_environment_file" "freebsd14_cloud" { + content_type = "iso" + datastore_id = "local" + node_name = "virt01" + + source_file { + path = "https://cdn.gyptazy.ch/files/amd64/freebsd/images/cloud/freebsd-14.0-ufs-2024-05-04.qcow2" + file_name = "freebsd-14.0-ufs-2024-05-04.img" + #checksum = "f472fa7af26aae23fdc92f4a729f083a6a10ce43b1f2049573382bc755c81750" + } +} + +resource "proxmox_virtual_environment_file" "cloud_config" { + content_type = "snippets" + datastore_id = "local" + node_name = "virt01" + + source_file { + path = "cloud-init/user-data.yml" + } +} + diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..5db4986 --- /dev/null +++ b/main.tf @@ -0,0 +1,21 @@ +terraform { + required_providers { + proxmox = { + source = "bpg/proxmox" + version = "0.63.0" + } + } +} + +provider "proxmox" { + endpoint = "https://cluster-vip02.gyptazy.ch:8006/" + username = "root@pam" + password = "p@ssw0rd!" + insecure = true + + ssh { + agent = true + # TODO: uncomment and configure if using api_token instead of password + # username = "root" + } +} diff --git a/virtual_machines.tf b/virtual_machines.tf new file mode 100644 index 0000000..032c707 --- /dev/null +++ b/virtual_machines.tf @@ -0,0 +1,41 @@ +resource "proxmox_virtual_environment_vm" "managed-vm33" { + name = "managed-vm33.boxybsd.com" + description = "Managed by Terraform" + tags = ["terraform"] + node_name = "virt01" + + cpu { + cores = 1 + } + + memory { + dedicated = 2048 + } + + agent { + enabled = true + } + + network_device { + bridge = "vmbr0" + } + + disk { + datastore_id = "local-lvm" + file_id = proxmox_virtual_environment_file.freebsd14_cloud.id + interface = "scsi0" + size = 32 + } + + serial_device {} + + initialization { + datastore_id = "local-lvm" + user_data_file_id = proxmox_virtual_environment_file.cloud_config.id + ip_config { + ipv4 { + address = "dhcp" + } + } + } +}