-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_azure_resource_group
68 lines (60 loc) · 1.69 KB
/
create_azure_resource_group
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
68
#!/bin/bash
# A script that will create a resource group in Azure
setup() {
# Install az cli
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
# Login
az login --use-device-code
echo "You're logged in."
}
# Print out 5 recommended regions
print_out_regions() {
regions_array=($( az account list-locations --query "[?metadata.regionCategory=='Recommended'].{Name:name}" -o tsv | head -n 5))
for i in "${regions_array[@]}"
do
echo "$i"
done
}
# Select a region
check_region() {
local region_exists=false
while [[ "$region_exists" = false ]]; do
print_out_regions
read -p "Enter your region: " selected_region
for j in "${regions_array[@]}"
do
if [[ "$selected_region" == "$j" ]]; then
region_exists=true
echo "Region exists"
break
else
continue
fi
done
done
}
# Check if resource group already exists.
check_resource_group () {
while true; do
read -p "Enter a name for you resource group: " resource_group
if [ $(az group exists --name $resource_group) = true ]; then
echo "The group $resource_group exists in $selected_region, please provide another name..."
else
break
fi
done
}
# Create the resource group
create_resource_group () {
echo "Creating resource group: $resource_group in $selected_region"
az group create -g $resource_group -l $selected_region | grep provisioningState
}
#List all resource groups
list_resource_groups() {
az group list -o table
}
setup
check_region
check_resource_group
create_resource_group
list_resource_groups