The challenge
Like Azure, Oracle Cloud gives you no default network — the full stack of VCN, gateway, routing, security list, and subnet must exist before any compute. And the most capable Always-Free ARM shape is frequently capacity-limited.
Our approach
We build the network in order — VCN, internet gateway, route table, security list, subnet — and then the compute instance with a public IP. Request signing comes from your local OCI config profile, and only the public SSH key is injected through cloud-init metadata. We default to the reliably available AMD micro shape while supporting the larger ARM Flex shape for accounts that can get it.
Technical specifics
- Terraform ≥ 1.5.0 with the oracle/oci provider ~> 6.0.
- Primary shape VM.Standard.E2.1.Micro (AMD, reliably allocatable); ARM VM.Standard.A1.Flex alternative.
- VCN 10.0.0.0/16 and subnet 10.0.1.0/24; security list opening SSH, HTTP, and HTTPS.
- Canonical Ubuntu 24.04; a dynamic shape-config block emitted only for Flex shapes.
- Six resources total; only the compartment id is required; $0 within Always Free.
Example configuration
A dynamic block emits a shape_config only for Flex shapes, so the same module serves both the AMD micro and the ARM Flex shape.
locals { is_flex = length(regexall("Flex", var.shape)) > 0 }
resource "oci_core_instance" "vm" {
compartment_id = var.compartment_id
availability_domain = data.oci_identity_availability_domains.ads.availability_domains[0].name
shape = var.shape # VM.Standard.E2.1.Micro (AMD, reliable)
dynamic "shape_config" {
for_each = local.is_flex ? [1] : [] # only ARM A1.Flex needs this
content { ocpus = 1; memory_in_gbs = 6 }
}
create_vnic_details { subnet_id = oci_core_subnet.subnet.id; assign_public_ip = true }
metadata = { ssh_authorized_keys = file(var.public_key_path) }
}Outcome
One Always-Free Ubuntu VM with a complete, explicit network — reproducible, credential-free, and version-controlled — created in under five minutes and destroyed just as easily.