This guide covers debugging techniques for developing and testing the Terraform Proxmox Provider.
Using an LLM agent? The
/bpg:debug-apiskill automates most of this workflow. See README.md for details.
Mitmproxy is an essential tool for intercepting and analyzing HTTP/HTTPS traffic between the provider and Proxmox VE API. It helps you verify that API calls are correct, debug issues, and understand provider behavior.
# Install mitmproxy (if not already installed)
brew install mitmproxy # macOS
# or
pip install mitmproxy # Linux/WindowsThe provider uses proxy environment variables (HTTP_PROXY, HTTPS_PROXY) when they are set. The testacc.env file should already configure these for you.
# 1. Start mitmproxy proxy
mitmdump --mode regular --listen-port 8080 --flow-detail 2 > /tmp/mitmproxy.log 2>&1 &
# 2. Run acceptance tests
./testacc TestAccDatasourceFile
# 3. Analyze the captured traffic
grep "storage.*content" /tmp/mitmproxy.log
# 4. Stop the proxy
pkill -f mitmdump| Level | Output |
|---|---|
| 0 | No output (quiet) |
| 1 | Shortened URL + status code (default) |
| 2 | Full URL + headers (recommended - shows query parameters) |
| 3 | Level 2 + truncated response content |
| 4 | Everything untruncated (deep debugging) |
For better visibility into API interactions, use the custom debug script:
# Start proxy with custom script
mitmdump --mode regular --listen-port 8080 \
-s .dev/proxmox_debug_script.py \
> /tmp/debug.log 2>&1 &
# Run tests
./testacc TestAccDatasourceFileContentTypeFiltering
# View formatted output
cat /tmp/debug.log
# Stop proxy
pkill -f mitmdumpThe script provides:
- 🔍 Filtered output (only Proxmox API calls)
- 🎯 Highlighted query parameters (especially
contenttype) - 📊 Item counts for list responses
- ✅/❌ Visual success/error indicators
- JSON pretty-printing
When debugging the content type filtering feature, mitmproxy captured:
127.0.0.1:58448: GET https://pve.bpghome.net:8006/api2/json/nodes/pve/storage/local/content?content=import
Host: pve.bpghome.net:8006
User-Agent: Go-http-client/1.1
Authorization: PVEAPIToken=terraform@pve!provider=...
<< 200 OK 11b
This confirmed:
- ✅ Query parameter
?content=importwas correctly sent - ✅ API accepted the request (200 OK)
- ✅ Empty result (11 bytes) as expected for non-existent file
# Start detailed logging
mitmdump --flow-detail 2 > /tmp/test.log 2>&1 &
# Run test
./testacc TestAccYourNewFeature
# Check the parameter is sent
grep "your_param=" /tmp/test.log
# Stop proxy
pkill -f mitmdump# Use flow-detail 4 to see full response bodies
mitmdump --flow-detail 4 > /tmp/error_debug.log 2>&1 &
# Run failing test
./testacc TestAccFailingTest
# Search for error responses
grep -A 20 "400\|401\|403\|500" /tmp/error_debug.log
pkill -f mitmdump# Custom script shows request bodies
mitmdump -s .dev/proxmox_debug_script.py > /tmp/post_debug.log 2>&1 &
# Run test that creates resources
./testacc TestAccResourceDownloadFile
# View captured POST bodies
grep -A 30 "📤 Request Body" /tmp/post_debug.log
pkill -f mitmdump# Capture from current version
mitmdump --save-stream-file /tmp/before.mitm --flow-detail 3 > /tmp/before.log 2>&1 &
./testacc TestAccSomeFeature
pkill -f mitmdump
# Apply your changes
git checkout your-feature-branch
make build
# Capture from new version
mitmdump --save-stream-file /tmp/after.mitm --flow-detail 3 > /tmp/after.log 2>&1 &
./testacc TestAccSomeFeature
pkill -f mitmdump
# Compare
diff /tmp/before.log /tmp/after.log# View recent requests
tail -50 /tmp/mitmproxy.log
# Find all storage content API calls
grep "storage.*content" /tmp/mitmproxy.log
# Count requests by endpoint
grep "GET\|POST\|DELETE" /tmp/mitmproxy.log | cut -d' ' -f2-3 | sort | uniq -c
# Find requests with query parameters
grep "?" /tmp/mitmproxy.log | grep -v "tasks"
# Extract URLs only
grep "GET\|POST" /tmp/mitmproxy.log | awk '{print $2}' | sort | uniq
# Find error responses
grep -E "400|401|403|404|500" /tmp/mitmproxy.log- Always start proxy before tests - Tests will fail with "connection refused" if proxy is expected but not running
- Use flow-detail 2 for most cases - Shows query parameters without overwhelming detail
- Save proxy PID - Makes it easy to stop the right instance:
PROXY_PID=$! - Check proxy is running -
pgrep -f mitmdumpbefore running tests - Clean up after tests -
pkill -f mitmdumpto stop the proxy - Analyze logs immediately - Review output while test context is fresh
# Check if port is already in use
lsof -i :8080
# Kill existing process
kill $(lsof -t -i:8080)# Verify proxy is running
pgrep -f mitmdump
# Check proxy port
ps aux | grep mitmdump | grep 8080# Increase verbosity
mitmdump --flow-detail 3 -v
# Monitor log file
tail -f /tmp/mitmproxy.log# Install delve
go install github.com/go-delve/delve/cmd/dlv@latest
# Debug a test
dlv test ./fwprovider/test -- -test.run TestAccDatasourceFile# Enable Terraform debug logs
export TF_LOG=DEBUG
export TF_LOG_PATH=/tmp/terraform.log
# Run terraform
terraform plan
terraform apply
# View logs
cat /tmp/terraform.logThe provider uses terraform-plugin-log for structured logging. Logs are visible when TF_LOG is set.
- Mitmproxy Documentation
- Mitmproxy Script API
- Terraform Plugin Development
- Proxmox VE API Documentation
DEBUGGING.md- This fileproxmox_debug_script.py- Enhanced mitmproxy script for API analysis