sam d30ec2074a initial commit: two-VM Proxmox portability test for obmp-docker
Terraform (bpg/proxmox) provisions two Ubuntu 24.04 cloud-init VMs on a
Proxmox host, one running obmp-docker's `deploy.sh --scope full-stack`
and the other running GoBGP as a BMP-source stand-in. `scripts/run-test.sh`
runs the six assertions from docs/design.md (containers healthy, BMP
peer up, ip_rib/bgp_peers non-zero, Grafana healthcheck).

Layout:
  terraform/            provider + VM + cloud-init snippet resources
  terraform/cloud-init/ user-data templates (store + bmpgen)
  scripts/              run-test.sh, teardown.sh
  docs/design.md        topology, assertion set, and rationale

Cred handling:
  terraform.tfvars is gitignored; endpoint + api_token can also come
  from PROXMOX_VE_ENDPOINT / PROXMOX_VE_API_TOKEN env vars.

Not validated locally: `terraform init && terraform validate` -- the
terraform binary is not on the authoring host. YAML + shell + HCL brace
balance verified.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-07-20 18:19:45 -07:00

89 lines
2.6 KiB
HCL

# 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_virtual_environment_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
}
}