Get “Always Free” VM instance on Oracle Cloud, and Solve “Out of Host Capacity” Issue: The Easy Way — Part 2
Following Part-1, Since these offerings are gaining popularity, it is becoming increasingly difficult to avail of some free resources like Arm-based Ampere A1 cores VMs, especially in popular regions. You’ll likely end up getting the “Out of Host Capacity” issue since they depend on availability.
I used the Frankfurt region. Comment if you know or find any other region where these resources are easily available.
Anyway, if the other methods mentioned in Part 1 are not feasible for you and you are not in a hurry, you can prepare this automation script following the steps below, and try until you find an available slot.
Steps
We’ll complete most of our tasks utilizing the Oracle resources and Oracle cloud shell. That is, we’ll run the final automation script on the cloud shell instead of running it on our local machine. Smart, eh? ;)
Recommended by LinkedIn
#!/bin/bash
# Define the availability domains ----------------- <UPDATE> ---------------
AD1="bgAk:EU-FRANKFURT-1-AD-1"
AD2="bgAk:EU-FRANKFURT-1-AD-2"
AD3="bgAk:EU-FRANKFURT-1-AD-3"
# Array to hold availability domains
AVAILABILITY_DOMAINS=("$AD1" "$AD2" "$AD3")
# Loop indefinitely until a command succeeds
while true; do
for AVAILABILITY_DOMAIN in "${AVAILABILITY_DOMAINS[@]}"; do
echo "Attempting to launch instance in Availability Domain: $AVAILABILITY_DOMAIN"
# ------------------------ <UPDATE AS NECESSARY> --------------------------
oci compute instance launch \
--availability-domain "$AVAILABILITY_DOMAIN" \
--compartment-id "ocid1.compartment.oc1..aaaaaaaary***EXAMPLE*****UPDATE_ID***vlsopz6lq" \
--shape "VM.Standard.A1.Flex" \
--subnet-id "ocid1.subnet.oc1.eu-frankfurt-1.aaaaaaaahigcy*****EXAMPLE******UPDATE_ID******73qbizvxzjzjq" \
--assign-private-dns-record true \
--assign-public-ip true \
--agent-config '{"is_management_disabled": false, "is_monitoring_disabled": false, "plugins_config": [
{"desired_state": "DISABLED", "name": "Vulnerability Scanning"},
{"desired_state": "DISABLED", "name": "Management Agent"},
{"desired_state": "ENABLED", "name": "Custom Logs Monitoring"},
{"desired_state": "DISABLED", "name": "Compute RDMA GPU Monitoring"},
{"desired_state": "ENABLED", "name": "Compute Instance Monitoring"},
{"desired_state": "DISABLED", "name": "Compute HPC RDMA Auto-Configuration"},
{"desired_state": "DISABLED", "name": "Compute HPC RDMA Authentication"},
{"desired_state": "ENABLED", "name": "Cloud Guard Workload Protection"},
{"desired_state": "DISABLED", "name": "Block Volume Management"},
{"desired_state": "DISABLED", "name": "Bastion"}]}' \
--availability-config '{"recovery_action": "RESTORE_INSTANCE"}' \
--display-name "<PUT_YOUR_VM_NAME>" \
--image-id "ocid1.image.oc1.eu-frankfurt-1.aaaaaaaausfft7********EXAMPLE*********UPDATE_ID*********qf5birrjk2zzcxv3sea" \
--instance-options '{"are_legacy_imds_endpoints_disabled": false}' \
--shape-config '{"memory_in_gbs": 24, "ocpus": 4}' \
--ssh-authorized-keys-file ./vm/id_rsa.pub
if [ $? -eq 0 ]; then
echo "Instance created successfully in $AVAILABILITY_DOMAIN."
exit 0 # Exit the script after successful execution
else
echo "Failed to launch instance in $AVAILABILITY_DOMAIN. Trying the next one..."
sleep 3 # Wait 3 seconds before trying the next domain
fi
done
done
Conclusion
This way you can automate your VM deployment retries. Your automation script will keep trying for you while you can do your other work.
Alternatively, you can modify and prepare multiple Terraform config [main.tf] files for all of your available domains, upload them in the cloud shell, and update this script accordingly. Then you can use this script similarly to run the automation. However, I recommend using the first approach.