/
action.yml
58 lines (51 loc) · 1.66 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
name: 'Power ON/OFF or DEALLOCATE a specific Azure VM'
description: 'This action either powers on/off or deallocates a specific Azure VM'
branding:
icon: download
color: blue
inputs:
POWER_SWITCH:
description: 'Turn ON or OFF the VM, or DEALLOCATE'
required: true
type: string
AZURE_VM_NAME:
description: 'Name of the VM'
required: true
AZURE_RG_NAME:
description: 'Resource Group where the VM lives'
required: true
AZURE_SP_CLIENTID:
description: 'Service Principal ClientID'
required: true
AZURE_SP_SECRET:
description: 'Service Principal Secret'
required: true
AZURE_TENANTID:
description: 'Service Principal TenantID'
required: true
runs:
using: "composite"
steps:
- name: "Login with az CLI"
shell: bash
run: |
az login --service-principal -u ${{ inputs.AZURE_SP_CLIENTID }} -p ${{ inputs.AZURE_SP_SECRET }} --tenant ${{ inputs.AZURE_TENANTID }}
- name: 'Debug POWER'
shell: bash
run: |
echo ${{ inputs.POWER_SWITCH }}
- name: "Deallocate VM"
shell: bash
if: ${{ inputs.POWER_SWITCH == 'DEALLOCATE' }}
run: |
az vm deallocate --name ${{ inputs.AZURE_VM_NAME }} --resource-group ${{ inputs.AZURE_RG_NAME }} --no-wait
- name: "Stop VM"
shell: bash
if: ${{ inputs.POWER_SWITCH == 'OFF' }}
run: |
az vm stop --name ${{ inputs.AZURE_VM_NAME }} --resource-group ${{ inputs.AZURE_RG_NAME }} --no-wait
- name: "Start VM"
shell: bash
if: ${{ inputs.POWER_SWITCH == 'ON' }}
run: |
az vm start --name ${{ inputs.AZURE_VM_NAME }} --resource-group ${{ inputs.AZURE_RG_NAME }} --no-wait