Automate the provisioning of Oracle Cloud's Always Free A1.Flex ARM instances using OCI Resource Manager and get notified via Telegram when successful.
Tip
π Quick Stack Creation Tip Rate Limits have been increased to prevent rate limits even with the proper handling You don't need to write Terraform from scratch! When creating an A1.Flex instance through the Oracle Cloud GUI, simply configure all your settings (shape, image, network, SSH keys, etc.) and at the final step, instead of clicking "Create", click "Save as Stack". This automatically generates a Terraform stack with all your configurations, giving you the Stack OCID you need for automation!
# Download the script
curl -o oracle_a1_automation-v2.sh https://raw.githubusercontent.com/Jaggu762/oracle-vps-script/main/oracle_a1_automation-v2.sh
# Make it executable
chmod +x oracle_a1_automation-v2.sh
# Edit configuration (add your Stack OCID, Telegram bot token, and chat ID)
nano oracle_a1_automation-v2.sh
# Run in screen session
screen -S oracle-automation
./oracle_a1_automation-v2.sh
# Detach: Ctrl+A, then DOracle Cloud's Always Free tier offers powerful A1.Flex ARM instances (up to 4 OCPUs, 24GB RAM), but they're almost never available due to high demand. Instead of manually refreshing the console hoping for capacity, this script automates the entire process.
- 24/7 Automated Retries - Runs continuously until successful
- Stack-based Deployment - More reliable than manual instance creation
- Auto Stack Discovery (Optional) - If
STACK_IDis not set, script tries to find one automatically - Telegram Notifications - Get instant alerts when your instance is created
- Detailed Logging - Track all attempts and errors
- 429 Rate-Limit Protection - Exponential backoff + jitter for Resource Manager API throttling
- Anti-Crash Retry Flow - Transient PLAN/APPLY API failures no longer stop the script
- Graceful Stop Handling -
Ctrl+Cexits cleanly without false crash alerts - Uses Existing E2 Micro - Leverages your always-available free instance
oracle_a1_automation-v2.sh includes these variables at the top:
BASE_WAIT- Base retry wait between attempts (default35seconds)MAX_WAIT- Maximum capped retry wait (default600seconds)OCI_MAX_RETRIES- Retries for a single OCI API call (default8)OCI_BASE_DELAY- Base delay for OCI API retry backoff (default8seconds)OCI_MAX_DELAY- Maximum OCI API retry delay (default180seconds)JOB_POLL_WAIT- Poll interval for PLAN/APPLY job status checks (default15seconds)TELEGRAM_RATE_LIMIT_COOLDOWN- Cooldown for repeated rate-limit alerts (default900seconds)
Suggested first-time setup:
- Set
STACK_IDmanually for the most predictable behavior. - Keep
COMPARTMENT_IDonly as a fallback helper. - Keep retry defaults unless you are hitting unusual API limits.
- An Oracle Cloud account with Always Free tier
- An existing E2 Micro instance (this will run the automation)
- Basic Linux/SSH knowledge
- A1.Flex Instance: ARM Ampere processor, up to 4 OCPUs and 24GB RAM
- Always Free: No charges, runs indefinitely
ssh -i /path/to/your/private-key ubuntu@your-instance-ip# Update system packages
sudo apt update && sudo apt upgrade -y
# Install required tools
sudo apt install -y jq curl screen# Download and install OCI CLI
bash -c "$(curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh)"
# Reload shell
exec bash -lDuring installation:
- Press
Enterfor default install location - Type
Yto update PATH - Type
Yto install optional packages
oci setup configYou'll need:
- User OCID: OCI Console β Profile β User Settings
- Tenancy OCID: OCI Console β Profile β Tenancy
- Region: Your home region (e.g.,
ap-mumbai-1) - Generate API Key: Type
Y
# Display your public key
cat ~/.oci/oci_api_key_public.pemThen:
- Go to OCI Console β Profile β User Settings β API Keys
- Click Add API Key
- Select Paste Public Key
- Paste the entire key
- Click Add
oci iam region listYou should see a JSON list of Oracle Cloud regions.
- Open Telegram and search for
@BotFather - Send
/newbot - Follow prompts to name your bot
- Copy the Bot Token (looks like
123456789:ABCdefGHI...)
Method 1: Using a Bot
- Search for
@RawDataBotor@getmyid_boton Telegram - Send
/start - Copy your Chat ID
Method 2: Using API
- Send any message to your bot
- Run this command:
curl https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates- Look for
"chat":{"id":123456789}- that's your Chat ID
curl -X POST "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/sendMessage" \
-d chat_id="<YOUR_CHAT_ID>" \
-d text="Test! Automation is working!"You should receive a message on Telegram.
Note
Easiest Method: Use the Oracle Cloud GUI to create your stack instead of writing Terraform manually!
- Go to OCI Console β Compute β Instances
- Click Create Instance
- Configure your A1.Flex instance:
- Name:
a1-free-instance - Image: Select Ubuntu or Oracle Linux (ARM-based)
- Shape: Click "Change Shape" β Select
VM.Standard.A1.Flex - OCPUs: 4 (max for free tier)
- Memory: 24 GB (max for free tier)
- Network: Select your VCN and subnet
- SSH Keys: Add your public SSH key
- Name:
- Instead of clicking "Create", scroll down and click "Save as Stack"
- Give your stack a name (e.g.,
a1-automation-stack) - Click Save
- Copy the Stack OCID from the stack details page
That's it! You now have a Terraform stack without writing any code.
If you prefer to write Terraform manually:
You'll need:
- Compartment OCID: OCI Console β Identity β Compartments
- Subnet OCID: OCI Console β Networking β Virtual Cloud Networks β Your VCN β Subnets
- Image OCID: OCI Console β Compute β Custom Images (or use public images)
- Availability Domain: Your region's AD (e.g.,
BqXC:AP-MUMBAI-1-AD-1)
Create a file main.tf:
variable "compartment_id" {
default = "ocid1.compartment.oc1..aaa..."
}
variable "availability_domain" {
default = "BqXC:AP-MUMBAI-1-AD-1"
}
variable "subnet_id" {
default = "ocid1.subnet.oc1..aaa..."
}
resource "oci_core_instance" "a1_instance" {
availability_domain = var.availability_domain
compartment_id = var.compartment_id
shape = "VM.Standard.A1.Flex"
display_name = "a1-free-instance"
shape_config {
ocpus = 4
memory_in_gbs = 24
}
source_details {
source_type = "image"
source_id = "ocid1.image.oc1..aaa..." # Ubuntu ARM image
boot_volume_size_in_gbs = 50
}
create_vnic_details {
subnet_id = var.subnet_id
assign_public_ip = true
}
metadata = {
ssh_authorized_keys = file("~/.ssh/id_rsa.pub")
}
}
output "instance_public_ip" {
value = oci_core_instance.a1_instance.public_ip
}- Go to Developer Services β Resource Manager β Stacks
- Click Create Stack
- Choose My Configuration
- Upload your
main.tffile - Click Next, configure variables
- Click Create
- Copy the Stack OCID (you'll need this!)
curl -o oracle_a1_automation-v2.sh https://raw.githubusercontent.com/Jaggu762/oracle-vps-script/main/oracle_a1_automation-v2.shEdit the file and replace:
your-stack-ocid-herewith your Stack OCID (recommended)your-bot-token-herewith your Telegram Bot Tokenyour-chat-id-herewith your Telegram Chat ID
Notes:
- If
STACK_IDis left as placeholder, the script will try to auto-discover a stack from your tenant. - Auto-discovery is convenient, but manual
STACK_IDis safer in accounts with multiple stacks.
nano oracle_a1_automation-v2.shchmod +x oracle_a1_automation-v2.sh# Create a new screen session
screen -S oracle-automation
# Run the script
./oracle_a1_automation-v2.shPress: Ctrl + A, then D
The script will continue running in the background.
tail -f oracle_automation_v2.logscreen -r oracle-automationscreen -ls# Reattach to screen
screen -r oracle-automation
# Stop script
Ctrl + C
# Exit screen
exit- Script starts β You receive a Telegram notification
- Continuous attempts β It runs PLAN + APPLY in a loop until capacity is available
- Smart backoff β On 429/transient API errors, it backs off automatically (with jitter)
- Success! β You get a Telegram notification with instance details
- Script exits β Automation stops (you got your instance!)
- Could be hours to days depending on Oracle's capacity
- Most users report success within 24-48 hours
- Some get lucky within the first hour!
- During heavy throttling windows, retries may slow down by design to avoid tenant-level 429 blocks
# Check your config
cat ~/.oci/config
# Verify API key is uploaded to OCI Console
oci iam region list# Test manually
curl -X POST "https://api.telegram.org/bot<BOT_TOKEN>/sendMessage" \
-d chat_id="<CHAT_ID>" \
-d text="Test"- Make sure you're running it inside
screenortmux - Check the log file:
cat oracle_automation_v2.log
- This is normal during crowded hours in popular regions.
- Let the script run; it now uses exponential backoff and jitter automatically.
- If needed, increase
BASE_WAIT(for gentler loops) orOCI_BASE_DELAY(for slower API retries).
- Verify all OCIDs are correct
- Check you have available quota
- Ensure subnet and VCN are configured properly
| Action | Command |
|---|---|
| Create session | screen -S oracle-automation |
| Detach | Ctrl+A, D |
| Reattach | screen -r oracle-automation |
| List sessions | screen -ls |
| Kill session | screen -X -S oracle-automation quit |
| Action | Command |
|---|---|
| Create session | tmux new -s oracle-automation |
| Detach | Ctrl+B, D |
| Reattach | tmux attach -t oracle-automation |
| List sessions | tmux ls |
| Kill session | tmux kill-session -t oracle-automation |
Found an improvement? Have a suggestion? Feel free to:
- Open an issue
- Submit a pull request
- Share your success story!
- This script is for educational purposes
- Use at your own risk
- Oracle may change their policies at any time
- Always comply with Oracle Cloud's Terms of Service
MIT License - Feel free to use and modify!
Once you receive the success notification on Telegram:
- Go to OCI Console β Compute β Instances
- Find your new A1.Flex instance
- Note the public IP address
- SSH into your new ARM instance:
ssh ubuntu@<instance-public-ip>
Enjoy your powerful free ARM server! π
Jaggu762
Made with β€οΈ for the Oracle Cloud community