Skip to content

Instantly share code, notes, and snippets.

@Piotr1215
Created July 21, 2021 19:14
Show Gist options
  • Save Piotr1215/0ded87c51d52e8b3b4e15862c4acde27 to your computer and use it in GitHub Desktop.
Save Piotr1215/0ded87c51d52e8b3b4e15862c4acde27 to your computer and use it in GitHub Desktop.
Create or Delete Azure Resource Group
#!/bin/bash
# Setup variables
group='rg-unique-name'
location='rg-location'
groupExists=$(az group exists -n $group)
if $groupExists; then
echo 'Group' $group 'already exists'
else
az group create --name $group --location $location --output json
echo 'Resource group' $group 'created.'
fi
delete=${1:-false}
if $delete; then
groupExists=$(az group exists -n $group)
if $groupExists; then
az group delete --name $group --yes
echo 'Resource group' $group 'destroyed'
else
echo 'Group' $group 'not found'
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment