Skip to content

Commit 69151c2

Browse files
committedDec 21, 2024
add test issue tofu
1 parent e9b420a commit 69151c2

File tree

2 files changed

+211
-0
lines changed

2 files changed

+211
-0
lines changed
 
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Handle VM Deployment Issue
2+
on:
3+
issues:
4+
types: [opened]
5+
6+
jobs:
7+
process-issue:
8+
if: contains(github.event.issue.labels.*.name, 'deploy-vm')
9+
runs-on: docker
10+
steps:
11+
- name: Checkout repository
12+
uses: actions/checkout@v4
13+
14+
- name: Extract Issue Details
15+
id: extract
16+
run: |
17+
echo "Extracting issue details..."
18+
ISSUE_BODY="${{ github.event.issue.body }}"
19+
VM_NAME=$(echo "$ISSUE_BODY" | grep 'VM Name:' | cut -d':' -f2 | xargs)
20+
VM_ID=$(echo "$ISSUE_BODY" | grep 'VM ID:' | cut -d':' -f2 | xargs)
21+
RAM=$(echo "$ISSUE_BODY" | grep 'RAM:' | cut -d':' -f2 | xargs)
22+
CPUS=$(echo "$ISSUE_BODY" | grep 'CPU Cores:' | cut -d':' -f2 | xargs)
23+
SCPU_TYPE=$(echo "$ISSUE_BODY" | grep 'CPU Type:' | cut -d':' -f2 | xargs)
24+
NODE_NAME=$(echo "$ISSUE_BODY" | grep 'Node Name:' | cut -d':' -f2 | xargs)
25+
VLAN_ID=$(echo "$ISSUE_BODY" | grep 'VLAN ID:' | cut -d':' -f2 | xargs)
26+
IP_METHOD=$(echo "$ISSUE_BODY" | grep 'IP Configuration Method:' | cut -d':' -f2 | xargs)
27+
DATASTORE=$(echo "$ISSUE_BODY" | grep 'Datastore ID:' | cut -d':' -f2 | xargs)
28+
DISK_SIZE=$(echo "$ISSUE_BODY" | grep 'Disk Size:' | cut -d':' -f2 | xargs)
29+
CLONE_VM_ID=$(echo "$ISSUE_BODY" | grep 'Clone VM ID:' | cut -d':' -f2 | xargs)
30+
31+
# Determine user_data_file_id
32+
if [ "$NODE_NAME" == "prox" ]; then
33+
USER_DATA_FILE_ID="proxmox_virtual_environment_file.cloud_config.id"
34+
else
35+
USER_DATA_FILE_ID="proxmox_virtual_environment_file.cloud_config2.id"
36+
fi
37+
38+
echo "VM_NAME=$VM_NAME" >> $GITHUB_ENV
39+
echo "VM_ID=$VM_ID" >> $GITHUB_ENV
40+
echo "RAM=$RAM" >> $GITHUB_ENV
41+
echo "CPUS=$CPUS" >> $GITHUB_ENV
42+
echo "SCPU_TYPE=$SCPU_TYPE" >> $GITHUB_ENV
43+
echo "NODE_NAME=$NODE_NAME" >> $GITHUB_ENV
44+
echo "VLAN_ID=$VLAN_ID" >> $GITHUB_ENV
45+
echo "IP_METHOD=$IP_METHOD" >> $GITHUB_ENV
46+
echo "DATASTORE=$DATASTORE" >> $GITHUB_ENV
47+
echo "DISK_SIZE=$DISK_SIZE" >> $GITHUB_ENV
48+
echo "CLONE_VM_ID=$CLONE_VM_ID" >> $GITHUB_ENV
49+
echo "USER_DATA_FILE_ID=$USER_DATA_FILE_ID" >> $GITHUB_ENV
50+
51+
- name: Generate Terraform File
52+
run: |
53+
cat <<EOF > terraform/proxmox/$VM_ID.tf
54+
resource "proxmox_virtual_environment_vm" "$VM_NAME" {
55+
node_name = "${{ env.NODE_NAME }}"
56+
vm_id = "${{ env.VM_ID }}"
57+
name = "${{ env.VM_NAME }}"
58+
description = "${{ env.VM_NAME }}"
59+
60+
cpu {
61+
cores = "${{ env.CPUS }}"
62+
type = "${{ env.SCPU_TYPE }}"
63+
}
64+
65+
memory {
66+
dedicated = "${{ env.RAM }}"
67+
}
68+
69+
network_device {
70+
bridge = "vmbr0"
71+
vlan_id = "${{ env.VLAN_ID }}"
72+
}
73+
74+
disk {
75+
datastore_id = "${{ env.DATASTORE }}"
76+
size = "${{ env.DISK_SIZE }}"
77+
}
78+
79+
clone {
80+
vm_id = "${{ env.CLONE_VM_ID }}"
81+
}
82+
83+
initialization {
84+
ip_config {
85+
ipv4 {
86+
address = "dhcp"
87+
}
88+
}
89+
90+
user_data_file_id = ${{ env.USER_DATA_FILE_ID }}
91+
}
92+
}
93+
EOF
94+
95+
- name: Commit and Push Terraform File
96+
env:
97+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
98+
run: |
99+
git config user.name "GitHub Actions"
100+
git config user.email "actions@github.com"
101+
git add terraform/proxmox/$VM_ID.tf
102+
git commit -m "Add VM $VM_NAME configuration"
103+
git push
104+
105+
- name: Trigger Terraform Apply Workflow
106+
uses: actions/github-script@v6
107+
with:
108+
script: |
109+
github.rest.actions.createWorkflowDispatch({
110+
owner: context.repo.owner,
111+
repo: context.repo.repo,
112+
workflow_id: "tofu.yml",
113+
ref: "main"
114+
})

‎.github/ISSUE_TEMPLATE/deploy-vm.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Deploy Virtual Machine
2+
description: Provide details to deploy a new virtual machine.
3+
title: "[VM Deployment] <VM Name>"
4+
labels:
5+
- deploy-vm
6+
assignees:
7+
- mafyuh
8+
body:
9+
- type: input
10+
id: vm_name
11+
attributes:
12+
label: VM Name
13+
placeholder: Enter the name of the VM
14+
description: The name of the virtual machine (e.g., Plausible).
15+
validations:
16+
required: true
17+
18+
- type: input
19+
id: vm_id
20+
attributes:
21+
label: VM ID
22+
placeholder: Enter the VM ID
23+
description: The unique numeric ID for the VM (e.g., 103).
24+
validations:
25+
required: true
26+
27+
- type: input
28+
id: ram
29+
attributes:
30+
label: RAM (MB)
31+
placeholder: Enter the amount of RAM in MB
32+
description: The amount of RAM allocated to the VM (e.g., 4196).
33+
validations:
34+
required: true
35+
36+
- type: input
37+
id: cpus
38+
attributes:
39+
label: CPU Cores
40+
placeholder: Enter the number of CPU cores
41+
description: The number of CPU cores allocated to the VM (e.g., 3).
42+
validations:
43+
required: true
44+
45+
- type: input
46+
id: scpu_type
47+
attributes:
48+
label: CPU Type
49+
placeholder: Enter the CPU type
50+
description: The type of CPU to use (e.g., host).
51+
validations:
52+
required: true
53+
54+
- type: input
55+
id: node_name
56+
attributes:
57+
label: Node Name
58+
placeholder: Enter the node name
59+
description: The Proxmox node name (e.g., prox or pve2).
60+
validations:
61+
required: true
62+
63+
- type: input
64+
id: vlan_id
65+
attributes:
66+
label: VLAN ID
67+
placeholder: Enter the VLAN ID
68+
description: The VLAN ID for the network device (e.g., 1).
69+
validations:
70+
required: true
71+
72+
- type: input
73+
id: datastore
74+
attributes:
75+
label: Datastore ID
76+
placeholder: Enter the datastore ID
77+
description: Specify the datastore where the VM disk is located (e.g., Fast2Tb).
78+
validations:
79+
required: true
80+
81+
- type: input
82+
id: disk_size
83+
attributes:
84+
label: Disk Size (GB)
85+
placeholder: Enter the size of the disk in GB
86+
description: The size of the VM disk in GB (e.g., 30).
87+
validations:
88+
required: true
89+
90+
- type: input
91+
id: clone_vm_id
92+
attributes:
93+
label: Clone VM ID
94+
placeholder: Enter the VM ID to clone from
95+
description: The VM ID to use as the clone source (e.g., 9996).
96+
validations:
97+
required: true

0 commit comments

Comments
 (0)
Please sign in to comment.