name: Handle VM Deployment Issue on: issues: types: [opened, reopened] jobs: process-issue: if: contains(github.event.issue.labels.*.name, 'opentofu') runs-on: docker steps: - name: Checkout repository uses: actions/checkout@v4 - name: Extract Issue Details id: extract run: | echo "Extracting issue details..." ISSUE_BODY="${{ github.event.issue.body }}" VM_NAME=$(echo "$ISSUE_BODY" | grep -A 2 'VM Name' | tail -n 1 | xargs) VM_ID=$(echo "$ISSUE_BODY" | grep -A 2 'VM ID' | tail -n 1 | xargs) RAM=$(echo "$ISSUE_BODY" | grep -A 2 'RAM' | tail -n 1 | xargs) CPUS=$(echo "$ISSUE_BODY" | grep -A 2 'CPU Cores' | tail -n 1 | xargs) SCPU_TYPE=$(echo "$ISSUE_BODY" | grep -A 2 'CPU Type' | tail -n 1 | xargs) NODE_NAME=$(echo "$ISSUE_BODY" | grep -A 2 'Node Name' | tail -n 1 | xargs) VLAN_ID=$(echo "$ISSUE_BODY" | grep -A 2 'VLAN ID' | tail -n 1 | xargs) DATASTORE=$(echo "$ISSUE_BODY" | grep -A 2 'Datastore ID' | tail -n 1 | xargs) DISK_SIZE=$(echo "$ISSUE_BODY" | grep -A 2 'Disk Size' | tail -n 1 | xargs) CLONE_VM_ID=$(echo "$ISSUE_BODY" | grep -A 2 'Clone VM ID' | tail -n 1 | xargs) echo "NODE_NAME=$NODE_NAME" # Determine user_data_file_id if [ "$NODE_NAME" == "prox" ]; then USER_DATA_FILE_ID="proxmox_virtual_environment_file.cloud_config.id" else USER_DATA_FILE_ID="proxmox_virtual_environment_file.cloud_config2.id" fi echo "VM_NAME=$VM_NAME" >> $GITHUB_ENV echo "VM_ID=$VM_ID" >> $GITHUB_ENV echo "RAM=$RAM" >> $GITHUB_ENV echo "CPUS=$CPUS" >> $GITHUB_ENV echo "SCPU_TYPE=$SCPU_TYPE" >> $GITHUB_ENV echo "NODE_NAME=$NODE_NAME" >> $GITHUB_ENV echo "VLAN_ID=$VLAN_ID" >> $GITHUB_ENV echo "IP_METHOD=$IP_METHOD" >> $GITHUB_ENV echo "DATASTORE=$DATASTORE" >> $GITHUB_ENV echo "DISK_SIZE=$DISK_SIZE" >> $GITHUB_ENV echo "CLONE_VM_ID=$CLONE_VM_ID" >> $GITHUB_ENV echo "USER_DATA_FILE_ID=$USER_DATA_FILE_ID" >> $GITHUB_ENV - name: Generate Terraform File run: | cat < terraform/proxmox/$VM_NAME.tf resource "proxmox_virtual_environment_vm" "$VM_NAME" { node_name = "${{ env.NODE_NAME }}" vm_id = "${{ env.VM_ID }}" name = "${{ env.VM_NAME }}" description = "${{ env.VM_NAME }}" cpu { cores = "${{ env.CPUS }}" type = "${{ env.SCPU_TYPE }}" } memory { dedicated = "${{ env.RAM }}" } network_device { bridge = "vmbr0" vlan_id = "${{ env.VLAN_ID }}" } disk { datastore_id = "${{ env.DATASTORE }}" size = "${{ env.DISK_SIZE }}" } clone { vm_id = "${{ env.CLONE_VM_ID }}" } initialization { ip_config { ipv4 { address = "dhcp" } } user_data_file_id = ${{ env.USER_DATA_FILE_ID }} } } EOF - name: Commit and Push Terraform File run: | git config user.name "GitHub Actions" git config user.email "actions@github.com" git add terraform/proxmox/$VM_NAME.tf git commit -m "Add VM $VM_NAME configuration" git push