diff --git a/.forgejo/workflows/tofu-issue-deploy.yml b/.forgejo/workflows/tofu-issue-deploy.yml new file mode 100644 index 0000000..10d450f --- /dev/null +++ b/.forgejo/workflows/tofu-issue-deploy.yml @@ -0,0 +1,114 @@ +name: Handle VM Deployment Issue +on: + issues: + types: [opened] + +jobs: + process-issue: + if: contains(github.event.issue.labels.*.name, 'deploy-vm') + 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 'VM Name:' | cut -d':' -f2 | xargs) + VM_ID=$(echo "$ISSUE_BODY" | grep 'VM ID:' | cut -d':' -f2 | xargs) + RAM=$(echo "$ISSUE_BODY" | grep 'RAM:' | cut -d':' -f2 | xargs) + CPUS=$(echo "$ISSUE_BODY" | grep 'CPU Cores:' | cut -d':' -f2 | xargs) + SCPU_TYPE=$(echo "$ISSUE_BODY" | grep 'CPU Type:' | cut -d':' -f2 | xargs) + NODE_NAME=$(echo "$ISSUE_BODY" | grep 'Node Name:' | cut -d':' -f2 | xargs) + VLAN_ID=$(echo "$ISSUE_BODY" | grep 'VLAN ID:' | cut -d':' -f2 | xargs) + IP_METHOD=$(echo "$ISSUE_BODY" | grep 'IP Configuration Method:' | cut -d':' -f2 | xargs) + DATASTORE=$(echo "$ISSUE_BODY" | grep 'Datastore ID:' | cut -d':' -f2 | xargs) + DISK_SIZE=$(echo "$ISSUE_BODY" | grep 'Disk Size:' | cut -d':' -f2 | xargs) + CLONE_VM_ID=$(echo "$ISSUE_BODY" | grep 'Clone VM ID:' | cut -d':' -f2 | xargs) + + # 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_ID.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 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + git config user.name "GitHub Actions" + git config user.email "actions@github.com" + git add terraform/proxmox/$VM_ID.tf + git commit -m "Add VM $VM_NAME configuration" + git push + + - name: Trigger Terraform Apply Workflow + uses: actions/github-script@v6 + with: + script: | + github.rest.actions.createWorkflowDispatch({ + owner: context.repo.owner, + repo: context.repo.repo, + workflow_id: "tofu.yml", + ref: "main" + }) diff --git a/.github/ISSUE_TEMPLATE/deploy-vm.yml b/.github/ISSUE_TEMPLATE/deploy-vm.yml new file mode 100644 index 0000000..76a340d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/deploy-vm.yml @@ -0,0 +1,97 @@ +name: Deploy Virtual Machine +description: Provide details to deploy a new virtual machine. +title: "[VM Deployment] " +labels: + - deploy-vm +assignees: + - mafyuh +body: + - type: input + id: vm_name + attributes: + label: VM Name + placeholder: Enter the name of the VM + description: The name of the virtual machine (e.g., Plausible). + validations: + required: true + + - type: input + id: vm_id + attributes: + label: VM ID + placeholder: Enter the VM ID + description: The unique numeric ID for the VM (e.g., 103). + validations: + required: true + + - type: input + id: ram + attributes: + label: RAM (MB) + placeholder: Enter the amount of RAM in MB + description: The amount of RAM allocated to the VM (e.g., 4196). + validations: + required: true + + - type: input + id: cpus + attributes: + label: CPU Cores + placeholder: Enter the number of CPU cores + description: The number of CPU cores allocated to the VM (e.g., 3). + validations: + required: true + + - type: input + id: scpu_type + attributes: + label: CPU Type + placeholder: Enter the CPU type + description: The type of CPU to use (e.g., host). + validations: + required: true + + - type: input + id: node_name + attributes: + label: Node Name + placeholder: Enter the node name + description: The Proxmox node name (e.g., prox or pve2). + validations: + required: true + + - type: input + id: vlan_id + attributes: + label: VLAN ID + placeholder: Enter the VLAN ID + description: The VLAN ID for the network device (e.g., 1). + validations: + required: true + + - type: input + id: datastore + attributes: + label: Datastore ID + placeholder: Enter the datastore ID + description: Specify the datastore where the VM disk is located (e.g., Fast2Tb). + validations: + required: true + + - type: input + id: disk_size + attributes: + label: Disk Size (GB) + placeholder: Enter the size of the disk in GB + description: The size of the VM disk in GB (e.g., 30). + validations: + required: true + + - type: input + id: clone_vm_id + attributes: + label: Clone VM ID + placeholder: Enter the VM ID to clone from + description: The VM ID to use as the clone source (e.g., 9996). + validations: + required: true