fix(ci): use Terraform provider for ISO upload, fix port/lockfile issues

- Use proxmox_virtual_environment_file resource to upload the auto-install
  ISO via the API. terraform destroy now cleans up both the VM and ISO.
- Remove manual upload-to-pve.sh and cleanup-pve-storage.sh scripts.
- Commit .terraform.lock.hcl for reproducible CI builds.
- Replace iso_file_id variable with iso_local_path and iso_storage.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Clint Branham
2026-03-18 14:19:24 -05:00
parent 910c686abc
commit 0dff14f4ba
8 changed files with 89 additions and 132 deletions
@@ -1,25 +0,0 @@
#!/usr/bin/env bash
# Remove an uploaded ISO from PVE storage.
#
# Usage: cleanup-pve-storage.sh <pve-host> <api-token> <volume-id>
# e.g.: cleanup-pve-storage.sh 172.16.100.150 "root@pam!tok=secret" "local:iso/proxmox-ve_9.1-1-auto.iso"
set -euo pipefail
PVE_HOST="$1"
API_TOKEN="$2"
VOLUME_ID="$3"
# Extract node name from API
NODE=$(curl -sk -H "Authorization: PVEAPIToken=${API_TOKEN}" \
"https://${PVE_HOST}/api2/json/nodes" \
| python3 -c "import json,sys; print(json.load(sys.stdin)['data'][0]['node'])")
echo "Deleting ${VOLUME_ID} from node ${NODE}..."
ENCODED_VOLID=$(python3 -c "import urllib.parse; print(urllib.parse.quote('${VOLUME_ID}', safe=''))")
RESPONSE=$(curl -sk -X DELETE \
-H "Authorization: PVEAPIToken=${API_TOKEN}" \
"https://${PVE_HOST}/api2/json/nodes/${NODE}/storage/local/content/${ENCODED_VOLID}")
echo "Response: $RESPONSE"
echo "Cleanup complete."
@@ -1,69 +0,0 @@
#!/usr/bin/env bash
# Upload a file to PVE storage via the REST API.
#
# Usage: upload-to-pve.sh <pve-host> <api-token> <node> <storage> <file-path> <content-type>
# content-type: "iso" or "vztmpl"
set -euo pipefail
PVE_HOST="$1"
API_TOKEN="$2"
NODE="$3"
STORAGE="$4"
FILE_PATH="$5"
CONTENT_TYPE="${6:-iso}"
FILENAME=$(basename "$FILE_PATH")
API_URL="https://${PVE_HOST}/api2/json/nodes/${NODE}/storage/${STORAGE}/upload"
# Check if file already exists on storage
echo "Checking if ${FILENAME} already exists on ${STORAGE}..."
EXISTING=$(curl -sk \
-H "Authorization: PVEAPIToken=${API_TOKEN}" \
"https://${PVE_HOST}/api2/json/nodes/${NODE}/storage/${STORAGE}/content" \
| python3 -c "
import json, sys
data = json.load(sys.stdin).get('data', [])
for item in data:
if item.get('volid', '').endswith('/${FILENAME}'):
print(item['volid'])
break
" 2>/dev/null || true)
if [ -n "$EXISTING" ]; then
echo "Already exists: $EXISTING (skipping upload)"
echo "$EXISTING"
exit 0
fi
echo "Uploading ${FILENAME} ($(du -h "$FILE_PATH" | cut -f1)) to ${STORAGE}:${CONTENT_TYPE}/..."
RESPONSE=$(curl -sk --progress-bar \
-H "Authorization: PVEAPIToken=${API_TOKEN}" \
-F "content=${CONTENT_TYPE}" \
-F "filename=@${FILE_PATH}" \
"$API_URL")
UPID=$(echo "$RESPONSE" | python3 -c "import json,sys; print(json.load(sys.stdin)['data'])" 2>/dev/null || true)
if [ -z "$UPID" ]; then
echo "ERROR: Upload failed. Response: $RESPONSE" >&2
exit 1
fi
echo "Upload started: $UPID"
# Wait for upload task to complete
echo "Waiting for upload task..."
for i in $(seq 1 60); do
STATUS=$(curl -sk \
-H "Authorization: PVEAPIToken=${API_TOKEN}" \
"https://${PVE_HOST}/api2/json/nodes/${NODE}/tasks/${UPID}/status" \
| python3 -c "import json,sys; d=json.load(sys.stdin)['data']; print(d.get('status','unknown'))" 2>/dev/null || echo "unknown")
if [ "$STATUS" = "stopped" ]; then
echo "Upload complete: ${STORAGE}:${CONTENT_TYPE}/${FILENAME}"
echo "${STORAGE}:${CONTENT_TYPE}/${FILENAME}"
exit 0
fi
sleep 2
done
echo "ERROR: Upload task did not complete within timeout" >&2
exit 1