-
Notifications
You must be signed in to change notification settings - Fork 0
56 lines (52 loc) · 2.11 KB
/
start_azure_vm.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
name: start or stop azure virtual machine
on:
workflow_dispatch:
inputs:
action:
default: "stop"
required: true
type: choice
options:
- start
- stop
vm_name:
required: true
default: "devwithkrishna-vm"
type: string
resource_group:
required: true
default: "DEV-WITH-KRISHNA-VM-RG"
type: string
subscription_name:
required: true
default: "TECH-ARCHITECTS-NONPROD"
type: string
run-name: ${{ inputs.action }} - ${{ inputs.vm_name }} - triggered by ${{ github.actor }}
jobs:
start-or-stop-azure-virtual-machine:
runs-on: ubuntu-latest
name: ${{ github.actor }} ${{ github.event.inputs.action }} ${{github.event.inputs.vm_name}} VM
steps:
- name: echo inputs
run: |
echo " action ${{github.event.inputs.action}} vmname ${{github.event.inputs.vm_name}} "
- name: azure login
uses: azure/login@v1
with:
creds: '{"clientId":"${{ secrets.AZURE_CLIENT_ID }}","clientSecret":"${{ secrets.AZURE_CLIENT_SECRET }}","subscriptionId":"${{ secrets.AZURE_SUBSCRIPTION_ID }}","tenantId":"${{ secrets.AZURE_TENANT_ID }}"}'
- name: az cli commands
uses: azure/CLI@v1
with:
azcliversion: 2.55.0
inlinescript: |
az account set -s ${{ secrets.AZURE_SUBSCRIPTION_ID }}
az account show -o json
- name: az vm start or stop
run: |
if [[ "${{ github.event.inputs.action }}" == "start" ]]; then
az vm start --name ${{ github.event.inputs.vm_name }} --resource-group ${{ github.event.inputs.resource_group }} --subscription ${{ github.event.inputs.subscription_name }}
echo "Vm ${{ github.event.inputs.vm_name }} has been started"
elif [[ "${{ github.event.inputs.action }}" == "stop" ]]; then
az vm deallocate --name ${{ github.event.inputs.vm_name }} --resource-group ${{ github.event.inputs.resource_group }} --subscription ${{ github.event.inputs.subscription_name }}
echo "Vm ${{ github.event.inputs.vm_name }} has been stopped/deallocated"
fi