-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdestroy.sh
executable file
·67 lines (54 loc) · 1.93 KB
/
destroy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
set -e
shopt -s extglob
current_dir=$(pwd)
script_name=$(basename "${BASH_SOURCE[0]}")
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
environment=$(basename $script_dir)
build_path_terraform=$script_dir/terraform
echo "-------"
echo "environment:"
echo $environment
echo "-------"
echo "script_name:"
echo $script_name
echo "-------"
echo "script_dir:"
echo $script_dir
echo "-------"
echo "build_path_terraform:"
echo $build_path_terraform
echo "-------"
echo "current_dir:"
echo $current_dir
echo "-------"
#### Delete Azure Image Versions #########
azure_gallery_name=${TF_VAR_azure_shared_image_gallery_name}
azure_resource_group=${TF_VAR_azure_resource_group_name}
az login --service-principal --username $ARM_CLIENT_ID --p=$ARM_CLIENT_SECRET --tenant $ARM_TENANT_ID --output none
az account set --subscription $ARM_SUBSCRIPTION_ID
for d in $build_path_terraform/!(_*|.*)/
do
azure_managed_image_name=$(basename "$d")
echo $azure_managed_image_name
for i in `az sig image-version list --gallery-image-definition $azure_managed_image_name --gallery-name $azure_gallery_name --resource-group $azure_resource_group -o tsv --query '[].name'`
do
echo "purging image-versions: $i" && \
$(az sig image-version delete \
--gallery-image-definition $azure_managed_image_name \
--gallery-image-version $i \
--gallery-name $azure_gallery_name \
--resource-group $azure_resource_group)
done
# Delete Image
echo "deleting managed image: $azure_managed_image_name"
az image delete --name $azure_managed_image_name --resource-group $azure_resource_group
# Delete Gallery Image Definition
echo "deleting gallery image definition: $azure_managed_image_name"
cd $build_path_terraform/$azure_managed_image_name
./destroy.sh -i $azure_managed_image_name
done
echo "deleting gallery"
cd $build_path_terraform/_image_gallery
./destroy.sh
cd $current_dir