Skip to content

Commit

Permalink
Merge pull request #156 from hmcts/vm_autoshutdown
Browse files Browse the repository at this point in the history
Remove redundant code
  • Loading branch information
mokainos authored Sep 25, 2023
2 parents 105026e + e73e952 commit d792ef8
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions scripts/vm/auto-shutdown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ while read subcription; do
else
business_area="CFT"
fi
echo -e "${RED}---------------------------------------------------"

while read id; do
business_area_entry=$(jq -r '."business_area"' <<<$id)
env_entry=$(jq -r '."environment"' <<<$id)
Expand Down Expand Up @@ -60,7 +60,7 @@ while read subcription; do
continue
fi
done < <(jq -c '.[]' issues_list.json)
echo SKIP: $SKIP SKIP_HUB: $SKIP_HUB

if [[ $SKIP == "false" ]]; then
echo "Stopping VM in Subscription: $SUBSCRIPTION_NAME ResourceGroup: $rg Name: $name"
az vm deallocate --ids $app_id --no-wait || echo Ignoring errors Stopping VM
Expand All @@ -85,16 +85,4 @@ if [[ $SKIP_HUB == "false" ]]; then
az vm deallocate --ids $app_id --no-wait || echo Ignoring errors Stopping VM
done
fi
jq -c '.[]' <<<$SUBSCRIPTIONS | while read subcription; do
SUBSCRIPTION_ID=$(jq -r '.id' <<<$subcription)
SUBSCRIPTION_NAME=$(jq -r '.name' <<<$subcription)
az account set -s $SUBSCRIPTION_ID
ENV=$(echo $SUBSCRIPTION_NAME | awk -F "-" '{print $NF}')
echo $SUBSCRIPTION_NAME $ENV
VMS=$(az resource list --resource-type Microsoft.Compute/virtualMachines --query "[?tags.autoShutdown == 'true']" -o json)
jq -c '.[]' <<<$VMS | while read vm; do
ID=$(jq -r '.id' <<<$vm)
echo "Stopping VM in Subscription: $(az account show --query name) ResourceGroup: $(jq -r '.resourceGroup' <<<$vm) Name: $(jq -r '.name' <<<$vm)"
az vm deallocate --ids $ID --no-wait || echo Ignoring errors Stopping VM
done
done

0 comments on commit d792ef8

Please sign in to comment.