# VM A -- the OBMP store. Cloud-init clones obmp-docker, writes a portable # .env, and runs deploy.sh --scope full-stack --auth local --yes. # # Store this cloud-init YAML as a PVE snippet so the provider can reference # it as user_data_file_id. The YAML is a rendered template so we can inject # the ubuntu username, SSH key, repo URL/ref, HOST_IP, and router-facing # port at plan time. locals { store_hostname = "obmp-store-test" # Extract the plain IPv4 from the CIDR for HOST_IP / ROUTER_FACING_IP. # If DHCP is in use, cloud-init discovers it at runtime; we pass an empty # marker and the template falls back to `hostname -I`. store_ip_addr = var.store_vm_ip_cidr != "" ? split("/", var.store_vm_ip_cidr)[0] : "" store_user_data = templatefile("${path.module}/cloud-init/store.cloud-init.yaml.tftpl", { hostname = local.store_hostname ssh_username = var.ssh_username ssh_public_key = trimspace(file(var.ssh_public_key_path)) obmp_repo_url = var.obmp_repo_url obmp_repo_ref = var.obmp_repo_ref router_facing_port = var.router_facing_port static_ip_addr = local.store_ip_addr }) } resource "proxmox_virtual_environment_file" "store_cloud_init" { content_type = "snippets" datastore_id = var.snippet_storage node_name = var.pve_node source_raw { file_name = "obmp-store-user-data.yaml" data = local.store_user_data } } resource "proxmox_virtual_environment_vm" "store" { name = local.store_hostname description = "OpenBMP portability-test STORE VM (managed by terraform)" tags = ["obmp", "portability-test", "store"] node_name = var.pve_node vm_id = var.store_vm_id agent { enabled = true } cpu { cores = var.vm_cpu_cores type = "host" } memory { dedicated = var.vm_memory_mb } disk { datastore_id = var.vm_storage_pool file_id = proxmox_download_file.ubuntu_noble.id interface = "scsi0" size = var.vm_disk_gb ssd = true discard = "on" } network_device { bridge = var.vm_bridge model = "virtio" vlan_id = var.vm_vlan_tag != 0 ? var.vm_vlan_tag : null } operating_system { type = "l26" } initialization { datastore_id = var.vm_storage_pool ip_config { ipv4 { address = var.store_vm_ip_cidr != "" ? var.store_vm_ip_cidr : "dhcp" gateway = var.store_vm_ip_cidr != "" ? var.vm_gateway : null } } dns { servers = var.vm_dns_servers } user_data_file_id = proxmox_virtual_environment_file.store_cloud_init.id } }