start - devwithkrishna-vm - triggered by githubofkrishnadhas #29
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |