mirror of
https://github.com/GoodOlClint/PSProxmoxVE.git
synced 2026-08-09 13:59:24 +00:00
80871f750b
Major provisioning pipeline changes: Terraform: - Add kreuzwerker/docker provider to manage iSCSI and NFS storage containers alongside PVE VMs in a single Terraform config - New storage.tf with Docker container, image, and volume resources - docker_host_ip variable for PVE nodes to reach storage services Provisioning: - Replace docker-compose storage management with Terraform - Replace create-api-token.sh with wait-for-pve.sh (IP discovery + API readiness + auth verification only — no token creation) - Tests use root@pam credentials, not API tokens Cleanup: - Replace preflight-cleanup.sh loop with terraform destroy - Supports version filtering: cleanup 9 destroys only PVE 9 resources - Full cleanup also removes config.json and tfvars New commands: - taint [8|9|all]: marks VMs for recreation on next provision - dev.ps1 -Reprovision: runs taint before provision to force VM rebuild Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
85 lines
2.5 KiB
Terraform
85 lines
2.5 KiB
Terraform
# ── Docker images & volumes ──────────────────────────────────────────
|
|
|
|
resource "docker_image" "ubuntu" {
|
|
name = "ubuntu:24.04"
|
|
}
|
|
|
|
resource "docker_volume" "iscsi_data" {
|
|
name = "pvetest-iscsi-data"
|
|
}
|
|
|
|
resource "docker_volume" "nfs_data" {
|
|
name = "pvetest-nfs-data"
|
|
}
|
|
|
|
# ── iSCSI target container ──────────────────────────────────────────
|
|
|
|
resource "docker_container" "iscsi_target" {
|
|
name = "pvetest-iscsi"
|
|
image = docker_image.ubuntu.image_id
|
|
privileged = true
|
|
restart = "unless-stopped"
|
|
|
|
network_mode = "host"
|
|
|
|
volumes {
|
|
volume_name = docker_volume.iscsi_data.name
|
|
container_path = "/srv/iscsi"
|
|
}
|
|
|
|
env = [
|
|
"ISCSI_IQN=${var.storage_iscsi_iqn}",
|
|
"ISCSI_LUN_SIZE=${var.storage_iscsi_lun_size}",
|
|
]
|
|
|
|
entrypoint = ["/bin/bash", "-c"]
|
|
command = [<<-EOT
|
|
set -e
|
|
apt-get update -qq && apt-get install -y -qq tgt >/dev/null 2>&1
|
|
mkdir -p /srv/iscsi
|
|
if [ ! -f /srv/iscsi/lun0.img ]; then
|
|
truncate -s $${ISCSI_LUN_SIZE} /srv/iscsi/lun0.img
|
|
fi
|
|
tgtd --foreground &
|
|
sleep 2
|
|
if ! tgtadm --lld iscsi --op show --mode target | grep -q "Target 1: $${ISCSI_IQN}"; then
|
|
tgtadm --lld iscsi --op new --mode target --tid 1 -T $${ISCSI_IQN}
|
|
fi
|
|
if ! tgtadm --lld iscsi --op show --mode logicalunit --tid 1 2>/dev/null | grep -qE "LUN:[[:space:]]*1($$|[^0-9])"; then
|
|
tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 --backing-store /srv/iscsi/lun0.img
|
|
fi
|
|
if ! tgtadm --lld iscsi --op show --mode target --tid 1 2>/dev/null | grep -q "Initiator-address: ALL"; then
|
|
tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL
|
|
fi
|
|
echo "iSCSI target ready: $${ISCSI_IQN} (port 3260)"
|
|
wait
|
|
EOT
|
|
]
|
|
}
|
|
|
|
# ── NFS server container ────────────────────────────────────────────
|
|
|
|
resource "docker_container" "nfs_server" {
|
|
name = "pvetest-nfs"
|
|
image = "erichough/nfs-server:2.2.1"
|
|
privileged = true
|
|
restart = "unless-stopped"
|
|
|
|
network_mode = "host"
|
|
|
|
volumes {
|
|
volume_name = docker_volume.nfs_data.name
|
|
container_path = "/srv/nfs/shared"
|
|
}
|
|
|
|
volumes {
|
|
host_path = "/lib/modules"
|
|
container_path = "/lib/modules"
|
|
read_only = true
|
|
}
|
|
|
|
env = [
|
|
"NFS_EXPORT_0=/srv/nfs/shared *(rw,sync,no_subtree_check,no_root_squash)",
|
|
]
|
|
}
|