Oracle Cloud - Out of capacity?

Oracle Cloud with its Free Tier, gives you 24GB of free A1 Flex resource (+ a LOT more).

Sounds too good to be true?

There is no catch, it's only that, you might not be able to find that moment when there are any available, and you will only see the Out of capacity message. (which by itself didnt rang any bell for me, and without searching for it, i had no clue why im facing this, on the first place..)

I could close this here, wishing you good luck, and just advise you to keep trying, but since I made this journey, and scratched my head for a while, I was more than happy once the solution turned out to be a simple script.

I used the following script to grab 12GB ram and 2 oCPU for 2 VM.

Free Tier only applicable for 24GB ram and 4 oCPU total (resources can be provisioned between 4 machines)

First check the sdkconfig to have a full understanding on what you need in the ./config file, install oci (pip install oci-cli), fill the script with your details, then you are good to go.

import oci
import time

# Create a default config using DEFAULT profile in default location
# Refer to
# https://docs.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm#SDK_and_CLI_Configuration_File
# for more info
config = oci.config.from_file(file_location="./config")

# Create a service client
compute = oci.core.ComputeClient(config)
counter = 0
# Create instance in a loop until successful
while True:
    counter += 1
    i =  counter % 3 + 1
    availability_domain = "ncYW:EU-FRANKFURT-1-AD-" + str(i)
    print("try number", counter, "to instance", availability_domain)
    try:
        # Create instance
        response = compute.launch_instance(
            launch_instance_details=oci.core.models.LaunchInstanceDetails(
                availability_domain=availability_domain,
                compartment_id="ocid1.tenancy.oc1..aaaaaaaa[COMPARTMENT_REDACTED]",
                shape="VM.Standard.A1.Flex",
                subnet_id="ocid1.subnet.oc1.eu-frankfurt-1.aaaaaaaa[SUBNET_REDACTED]",
                metadata={
                    "ssh_authorized_keys": "ssh-rsa [REDACTED]"
                },
                create_vnic_details=oci.core.models.CreateVnicDetails(
                    assign_public_ip=True,
                    assign_private_dns_record=True,
                    subnet_id="ocid1.subnet.oc1.eu-frankfurt-1.aaaaaaaa[SUBNET_REDACTED]"),
                shape_config=oci.core.models.LaunchInstanceShapeConfigDetails(
                    ocpus=2,
                    memory_in_gbs=12),
                source_details=oci.core.models.InstanceSourceViaImageDetails(
                    source_type="image",
                    image_id="ocid1.image.oc1.eu-frankfurt-1.aaaaaaaa[IMAGE_REDACTED]"), 
                display_name="oflexvm"
            )
        )
        instance_id = response.data.id

        # Verify instance is available
        while True:
            instance = compute.get_instance(instance_id).data
            if instance.lifecycle_state == "RUNNING":
                print(f"Instance {instance_id} is running!")
                break

            print(instance)
            print(f"Instance {instance_id} is running!")
            time.sleep(65)  # wait before checking again

        break  # exit the while loop when the instance is successfully created and running
    except Exception as e:
        # print(f"An error occurred: {str(e)}")
        message_part = getattr(e, 'message', 'UNKNOWNERROR')
        print(message_part)
        time.sleep(35)

rev1, to be updated

Please note, this script is originally from Reddit *.