Skip to content

Instantly share code, notes, and snippets.

@kenchon
Created May 21, 2020 03:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kenchon/a2b859794f246a796e8340cc3652f2b9 to your computer and use it in GitHub Desktop.
# !/bin/bash
# Specify target resource group and tag
subscription='{your_subscription_id}'
resource_group='{your_resource_group}'
tag='{target_tag}' # e.g. tag='type=api'
# Set subscription
az account set --subscription ${subscription}
# Get list of resources with specific tag
resource_list=`az resource list --tag ${tag} --subscription ${subscription}`
# Get number of resources to be deleted
num_resources=`echo $resource_list | jq length`
echo 'Found' $num_resources 'resources'
# Delete resources
for((i=0; i<$num_resources; i++)); do
# Get $i th resource name and type
name=`echo $resource_list | jq .[$i].name | tr -d '"'`
type=`echo $resource_list | jq .[$i].type | tr -d '"'`
echo 'Deleting following resource ...'
echo 'resource name': $name
echo 'resource type': $type
# Delete $i th resource
az resource delete -g ${resource_group} -n ${name} --resource-type ${type}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment