Automating Oracle Free Tier ARM Instance Creation

// published 12 May 2024 · 5 min read

[oracle][cloud][automation][self-hosting]

Oracle's Always Free tier includes an Ampere A1 ARM instance with up to 4 OCPUs and 24 GB RAM - one of the best free cloud offerings available. The catch: the VM.Standard.A1.Flex shape is almost always out of capacity, and provisioning fails with "Out of host capacity" until Oracle frees up slots in your region. The trick is to keep retrying automatically until it succeeds.

The Tool

oracle-freetier-instance-creation is a Python script that polls the Oracle Cloud API and retries instance creation every 60 seconds (configurable) until it succeeds. Once the instance is created, it writes an INSTANCE_CREATED file with the instance details and sends a notification.

Prerequisites

  • An Oracle Cloud account (Always Free tier is sufficient)
  • A free micro instance (VM.Standard.E2.1.Micro) already running Ubuntu 22.04 - this runs the script 24/7 at no cost and also provides the subnet ID automatically
  • An OCI API Key - generate one at Profile > API Keys > Add API Key and download the private key and config snippet

Setup

1. Clone the repo

SSH into your micro instance and clone:

git clone https://github.com/mohankumarpaluru/oracle-freetier-instance-creation.git
cd oracle-freetier-instance-creation

2. Add your API private key

Create a file named oci_api_private_key.pem in the project directory and paste the contents of your downloaded private key:

nano oci_api_private_key.pem

3. Create the OCI config

Create a file named oci_config in the project directory. Paste the config snippet copied from the Oracle Console during API key creation. It looks like this:

[DEFAULT]
user=ocid1.user.oc1..xxx
fingerprint=xx:xx:xx:...
tenancy=ocid1.tenancy.oc1..xxx
region=eu-frankfurt-1
key_file=/home/ubuntu/oracle-freetier-instance-creation/oci_api_private_key.pem

The key_file must be the absolute path to your oci_api_private_key.pem.

4. Configure oci.env

Either run the interactive setup script:

./setup_env.sh

Or edit oci.env directly. The required fields are:

OCI_CONFIG=/home/ubuntu/oracle-freetier-instance-creation/oci_config

# Availability domain eligible for Always Free tier
# Find this during instance creation in the console - separate multiple by comma
OCT_FREE_AD=xFUj:EU-FRANKFURT-1-AD-1

# Optional
DISPLAY_NAME=my-arm-instance
REQUEST_WAIT_TIME_SECS=60
OCPUS=4
MEMORY_IN_GBS=24

Do not set OCI_SUBNET_ID when running on a micro instance - the script detects the subnet automatically. Only set it when running locally.

5. Run

./setup_init.sh

This installs dependencies and starts the Python script in the background. It will confirm "Script is running successfully." on success.

To check progress:

tail -f launch_instance.log    # API call results
tail -f setup_and_info.log     # Parameters being used

If the script crashes, re-run without reinstalling dependencies:

./setup_init.sh rerun

Notifications

Add any of these to oci.env:

Telegram:

TELEGRAM_TOKEN=your_bot_token
TELEGRAM_USER_ID=your_user_id   # get this from @myidbot on Telegram

Discord:

DISCORD_WEBHOOK_URL=your_webhook_url

Gmail:

NOTIFY_EMAIL=True
EMAIL=you@gmail.com
EMAIL_PASSWORD=your_app_password   # use an App Password if 2FA is enabled

Tips

  • Try multiple availability domains. Capacity varies - list all ADs for your region in OCT_FREE_AD separated by commas and the script will try each.
  • SSH keys are auto-created. If SSH_AUTHORIZED_KEYS_FILE is not set, the script generates a key pair for you.
  • Public IP is not assigned by default. Set ASSIGN_PUBLIC_IP=True in oci.env to get an ephemeral IP automatically, or configure it post-creation in the Console.
  • Check your limits. Confirm your tenancy has the 4 OCPU / 24 GB ARM quota under Limits, Quotas and Usage - new accounts sometimes need a limit increase request.
  • The micro instance can be deleted after the ARM instance is created - it's only needed to run the script.