forked from oracle-devrel/oracle-autonomous-database-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-compute-vm.sh
More file actions
executable file
·71 lines (60 loc) · 1.95 KB
/
create-compute-vm.sh
File metadata and controls
executable file
·71 lines (60 loc) · 1.95 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
65
66
67
68
69
70
71
#!/bin/bash
# Copyright (c) 2025 Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
echo ""
echo "##"
echo "# deploy compute vm"
echo "##"
echo ""
# ensure you update the config file to match your deployment prior to running the deployment
source ./config
VM_SIZE=""
IP_PUBLIC="${VM_NAME}-pip"
NIC_NAME="${VM_NAME}-nic"
# Function to find the first available size from the priority list
find_available_size() {
#availableSizes=$(az vm list-sizes --location $LOCATION --query "[].name" -o tsv)
availableSizes=$(az vm list-skus --location $LOCATION --resource-type virtualMachines --query "[?restrictions[?reasonCode=='NotAvailableForSubscription']].name" -o tsv)
for size in "${VM_PREFERRED_SIZES[@]}"
do
echo ""
echo "search for $size"
echo ""
if echo "$availableSizes" | grep -q "$size"; then
echo ""
echo "VM size $size is available in $LOCATION. Let's create the VM."
VM_SIZE=$size
break
fi
done
}
# check if there are any available VMs
find_available_size
# if no VMs are available - bail.
if [ -z $VM_SIZE ]; then
echo "No capacity for your VM sizes in $LOCATION. Unable to create a compute VM"
exit -1
fi
# Create a public IP address for the VM
az network public-ip create \
--resource-group $RESOURCE_GROUP \
--name $IP_PUBLIC \
--sku Standard
# Create a virtual NIC and associate with public IP address and NSG
az network nic create \
--resource-group $RESOURCE_GROUP \
--name $NIC_NAME \
--vnet-name $VNET_NAME \
--subnet $SUBNET2_NAME \
--public-ip-address $IP_PUBLIC \
--network-security-group $NSG_NAME
# Create a virtual machine
az vm create \
--resource-group $RESOURCE_GROUP \
--name $VM_NAME \
--image $VM_IMAGE \
--size $VM_SIZE \
--admin-username $USER_NAME \
--admin-password $USER_PASSWORD \
--generate-ssh-keys \
--nics $NIC_NAME