diff --git a/tofu/e2e/main.tf b/tofu/e2e/main.tf new file mode 100644 index 0000000..59c6c2e --- /dev/null +++ b/tofu/e2e/main.tf @@ -0,0 +1,43 @@ +locals { + vm_offset = tonumber(var.run_id) % 44 # 211 - 254 + clone_vmid = 9100 + local.vm_offset + clone_ip = "192.168.178.${211 + local.vm_offset}/24" +} + +resource "proxmox_virtual_environment_vm" "e2e_clone" { + name = "e2e-run-${var.run_id}" + description = "Ephemeral E2E test VM for run ${var.run_id}" + tags = ["opentofu", "e2e", "ephemeral", "clone"] + + node_name = var.node_name + vm_id = local.clone_vmid + + clone { + vm_id = var.clone_template_id + full = false + } + + agent { + enabled = false + } + stop_on_destroy = true + + initialization { + ip_config { + ipv4 { + address = local.clone_ip + gateway = var.gateway + } + } + } +} + +output "clone_vmid" { + description = "VMID of the cloned E2E VM" + value = local.clone_vmid +} + +output "clone_ip" { + description = "IP address of the cloned E2E VM (without CIDR)" + value = "192.168.178.${211 + local.vm_offset}" # 211-254 +} diff --git a/tofu/e2e/provider.tf b/tofu/e2e/provider.tf new file mode 100644 index 0000000..f65f7b0 --- /dev/null +++ b/tofu/e2e/provider.tf @@ -0,0 +1,12 @@ +provider "proxmox" { + endpoint = "https://192.168.178.2:8006/" + username = "root@pam" + password = var.proxmox_password + insecure = true + + ssh { + agent = false + username = "root" + password = var.proxmox_password + } +} diff --git a/tofu/e2e/variables.tf b/tofu/e2e/variables.tf new file mode 100644 index 0000000..b992153 --- /dev/null +++ b/tofu/e2e/variables.tf @@ -0,0 +1,34 @@ +variable "proxmox_password" { + description = "Password for root@pam on Proxmox" + type = string + sensitive = true +} + +variable "node_name" { + description = "Proxmox node name" + type = string + default = "pve" +} + +variable "run_id" { + description = "Unique identifier for this E2E run (e.g. Drone build number)" + type = string +} + +variable "clone_template_id" { + description = "VMID of the E2E template to clone from" + type = number + default = 9000 +} + +variable "clone_vm_password" { + description = "Password for the cloned VM" + type = string + sensitive = true +} + +variable "gateway" { + description = "Network gateway IP" + type = string + default = "192.168.178.1" +} diff --git a/tofu/e2e/versions.tf b/tofu/e2e/versions.tf new file mode 100644 index 0000000..3930822 --- /dev/null +++ b/tofu/e2e/versions.tf @@ -0,0 +1,26 @@ +terraform { + required_version = ">= 1.6.0" + + backend "s3" { + bucket = "tofu-state" + key = "e2e/${var.run_id}/terraform.tfstate" + region = "garage" + + endpoints = { + s3 = "https://garage.gilmour109.de" + } + + skip_credentials_validation = true + skip_metadata_api_check = true + skip_requesting_account_id = true + skip_region_validation = true + use_path_style = true + } + + required_providers { + proxmox = { + source = "bpg/proxmox" + version = "~> 0.96.0" + } + } +}