-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdestroy.sh
More file actions
executable file
·24 lines (18 loc) · 784 Bytes
/
destroy.sh
File metadata and controls
executable file
·24 lines (18 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash
# Variables
service_perincipal_name="pyapp"
# End of Variables
# Delete the service principal if it exists
sp_id=$(az ad sp list --display-name $service_perincipal_name --query "[0].appId" -o tsv)
if [ -n "$sp_id" ]; then
echo "Service principal exists. Deleting the service principal..."
az ad sp delete --id $sp_id || { echo "Failed to delete service principal"; exit 1; }
else
echo "Service principal does not exist, skipping deletion."
fi
# Build the infrastructure
echo "--------------------Destroying Infrastructure--------------------"
cd terraform || { echo "Terraform directory not found"; exit 1; }
terraform init || { echo "Terraform init failed"; exit 1; }
terraform destroy -auto-approve || { echo "Terraform destroy failed"; exit 1; }
cd ..