forked from susegrant/azure-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-vm.sh
More file actions
64 lines (47 loc) · 1.99 KB
/
build-vm.sh
File metadata and controls
64 lines (47 loc) · 1.99 KB
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
#!/bin/bash
# Add VMs to existing RG and Network
# Author: Grant Marcroft
# Tag with service request number
tag=""
read -p "Does this involve an active Microsoft Support Request? (y|n): " srbool
if [ $srbool == 'y' ]; then
read -p "SUSE Service Request #: " srtag
tag=" --tags ServiceRequest=$srtag"
fi
echo -e "--------\nVM Setup\n--------"
read -p "Remind me, what's your Resource Group name again?: " group
read -p "Region?: " region
read -p "VNet name?: " vnet
read -p "Subnet name?: " subnet
read -p "NSG name?: " nsg
read -p "List Sizes? (y|n): " list_sizes
if [ $list_sizes == "y" ]; then
sizes=$(az vm list-sizes --location $region | grep "name" | cut -d'"' -f 4 | sort )
echo "$sizes"
fi
read -p "List SUSE Images? (y|n): " list_images
if [ $list_images == "y" ]; then
images=$(az vm image list --publisher suse --all | grep urn | cut -d'"' -f4 | sort -r -k 4 -t':')
echo "$images";
fi
read -p "Name your VM: " vm_name
read -p "Existing SSH Key Pair? (y|n): " key_exists
if [ $key_exists == "y" ]; then
read -p "Path To Public Key: " pub_key
ssh_config="--ssh-key-value $pub_key"
else
ssh_config="--generate-ssh-keys"
fi
read -p "Select size (Default is Standard_DS1_v2): " size
if [ -z $size ]; then size="Standard_DS1_v2"; fi
read -p "Image to use: (Default is urnAlias: suse:sles-15-sp4:gen2:latest): " image
if [ -z $image ]; then image="suse:sles-15-sp4:gen2:latest"; fi
az vm create --resource-group $group --name $vm_name --image $image --size $size --public-ip-sku Standard $ssh_config --vnet-name $vnet --subnet $subnet --nsg $nsg $tag
# Auto-shutdown
read -p "Auto-Shutdown Enabled? defaults to yes (y|n): " autoshutdown
if [ -z $autoshutdown ]; then autoshutdown="y"; fi
if [ "$autoshutdown" != "n" ]; then
read -p "Time in UTC for auto-shutdown (format hhmm, default 0000): " time
if [ -z $time ]; then time="0000"; fi
az vm auto-shutdown --resource-group $group --name $vm_name --time $time
fi