This is a Terraform configuration that creates an Always Free instance on Oracle Cloud Infrastructure. By default, the instance will have 4 Arm-based Ampere A1 cores, 24 GB of memory and 200 GB volume size.
In order to use Oracle Cloud Free Tier, you'll need to register a free tier account. Once you have that set up, you can proceed with configuring auth.
Generate an API key pair that will be used by the provider.
mkdir ~/.oci
openssl genrsa -out ~/.oci/oci.pem 4096
openssl rsa -pubout -in ~/.oci/oci.pem -out ~/.oci/oci_public.pem
Go to Profile >> My profile >> API keys
and click Add API key
. Paste the public key and copy the configuration preview file. Save the configuration file as terraform.tfvars
in the repository root.
Generate an ed25519 key pair that will be used to SSH into the instance.
For more details, check docs.
ssh-keygen -t ed25519 -C oci -f ~/.ssh/oci_free
Create a terraform.tfvars
file with your OCI configuration:
user = "ocid1.user.oc1..your_user_ocid"
fingerprint = "your:api:key:fingerprint"
tenancy = "ocid1.tenancy.oc1..your_tenancy_ocid"
region = "your_region"
namespace = "your_object_storage_namespace"
key_file = "~/.oci/oci.pem"
instance_public_key_path = "~/.ssh/oci_free.pub" # Optional: leave empty to auto-generate
Create a state.config
file for backend configuration:
bucket = "tfstate"
key = "free/terraform.tfstate"
region = "your_region"
namespace = "your_object_storage_namespace"
user_ocid = "ocid1.user.oc1..your_user_ocid"
fingerprint = "your:api:key:fingerprint"
tenancy_ocid = "ocid1.tenancy.oc1..your_tenancy_ocid"
key_file = "~/.oci/oci.pem"
terraform init -backend-config=state.config
terraform plan -var-file=terraform.tfvars
terraform apply -var-file=terraform.tfvars
# Check the instance's public IP
terraform output instance-public-ip
# SSH into the instance
ssh -i ~/.ssh/oci_free ubuntu@<public_ip>
# Or use this command to do it in one step
ssh -i ~/.ssh/oci_free ubuntu@$(terraform output -raw instance-public-ip)
Name | Version |
---|---|
terraform | >= 1.13.0 |
oci | ~> 7.15.0 |
tls | ~> 4.1.0 |
Name | Version |
---|---|
oci | ~> 7.15.0 |
tls | ~> 4.1.0 |
No modules.
Name | Type |
---|---|
oci_core_instance.free_instance | resource |
oci_core_internet_gateway.free_internet_gateway | resource |
oci_core_route_table.free_route_table | resource |
oci_core_security_list.free_security_list | resource |
oci_core_subnet.free_subnet | resource |
oci_core_vcn.free_vcn | resource |
oci_identity_compartment.free_compartment | resource |
tls_private_key.instance_ssh_key | resource |
oci_core_images.instance_images | data source |
oci_identity_availability_domains.ads | data source |
Name | Description | Type | Default | Required |
---|---|---|---|---|
fingerprint | The fingerprint for the user's RSA key. This can be found in user settings in the Oracle Cloud Infrastructure console. Required if auth is set to 'ApiKey', ignored otherwise. | string |
n/a | yes |
image_operating_system | The image's operating system. | string |
"Canonical Ubuntu" |
no |
image_operating_system_version | The image's operating system version. | string |
"24.04" |
no |
instance_boot_volume_size | The size of the boot volume in GBs. Minimum value is 50 GB and maximum value is 32,768 GB (32 TB). | number |
200 |
no |
instance_hostname | A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information. | string |
"free" |
no |
instance_memory | The total amount of memory available to the instance, in gigabytes. | number |
24 |
no |
instance_ocpus | The total number of OCPUs available to the instance. | number |
4 |
no |
instance_public_key_path | Public SSH key to be included in the ~/.ssh/authorized_keys file for the default user on the instance. | string |
"" |
no |
instance_shape | The shape of an instance. The shape determines the number of CPUs, amount of memory, and other resources allocated to the instance. | string |
"VM.Standard.A1.Flex" |
no |
key_file | The path to the user's PEM formatted private key. A private_key or a private_key_path must be provided if auth is set to 'ApiKey', ignored otherwise. | string |
n/a | yes |
region | The region for API connections (e.g. us-ashburn-1). | string |
n/a | yes |
namespace | The namespace of the OCI Object Storage. | string |
n/a | yes |
tenancy | The tenancy OCID for a user. The tenancy OCID can be found at the bottom of user settings in the Oracle Cloud Infrastructure console. Required if auth is set to 'ApiKey', ignored otherwise. | string |
n/a | yes |
user | The user OCID. This can be found in user settings in the Oracle Cloud Infrastructure console. Required if auth is set to 'ApiKey', ignored otherwise. | string |
n/a | yes |
Name | Description |
---|---|
compartment-id | The OCID of the compartment. |
compartment-name | The name you assign to the compartment during creation. The name must be unique across all compartments in the parent. |
instance-name | A user-friendly name. Does not have to be unique, and it's changeable. |
instance-public-ip | The public IP address of instance VNIC (if enabled). |
instance-region | The region that contains the availability domain the instance is running in. |
instance-shape | The shape of the instance. The shape determines the number of CPUs and the amount of memory allocated to the instance. |
instance-state | The current state of the instance. |
generated_private_key | The generated private key for SSH access (only when no public key path is provided). |