An OpenTofu/Terraform root module that provisions a self-hosted stack on Oracle Cloud Infrastructure using only Always Free resources: an ARM64 VM with Docker, an optional RunTipi homeserver and an optional WireGuard client.
Upgrading from v4.x or earlier? v5.0.0 lowers the default instance to 2 OCPUs / 12 GB and makes
regionrequired. See the CHANGELOG for breaking changes and migration guide, and What can cost you money — or take your instance away for why.
See CHANGELOG.md for version history, breaking changes, and migration guides.
- OpenTofu (recommended) or Terraform installed on your local machine.
- An Oracle Cloud Infrastructure (OCI) account.
- OCI CLI configured with your credentials.
- To work on the module itself:
tofuandshellcheck(both provided by the toolbox). See CONTRIBUTING.md.
-
Clone the repository:
git clone https://github.com/filippolmt/terraform-oci-free-tier.git cd terraform-oci-free-tier -
Configure your variables: Copy the
terraform.tfvars.templatetoterraform.tfvarsand fill in the required variables. By default, theinstall_runtipivariable is set totrue, which will trigger the installation of RunTipi. If you do not wish to install RunTipi, set this variable tofalse.cp terraform.tfvars.template terraform.tfvars
-
Initialize Terraform or OpenTofu: Depending on the tool you are using, run:
terraform init
or
tofu init
The module supports two OCI provider authentication methods, selected via the auth_method
variable (default: "ApiKey").
Upload an API signing key in the OCI Console and set the matching variables in terraform.tfvars:
auth_method = "ApiKey" # default, can be omitted
oracle_api_key_fingerprint = "aa:bb:cc:..."
user_ocid = "ocid1.user.oc1..aaaa..."
tenancy_ocid = "ocid1.tenancy.oc1..aaaa..."
oracle_api_private_key_path = "~/.oci/oci_api_key.pem" # defaultIf you authenticate through the OCI CLI with a browser-based session token, no API key upload is needed:
oci session authenticate # creates a session-token profile in ~/.oci/configThen set only the auth method and the profile name — the API key fields
(oracle_api_key_fingerprint, user_ocid, tenancy_ocid, oracle_api_private_key_path) can be
left empty, as they are read from the session profile:
auth_method = "SecurityToken"
config_file_profile = "<your-session-profile>" # the profile created by `oci session authenticate`The provider also accepts
InstancePrincipal,InstancePrincipalWithCerts, andResourcePrincipalasauth_methodvalues for in-cloud execution.
This module targets the Always Free allocation: resources Oracle grants
perpetually at no cost, with fixed per-tenancy caps. There are four ways to end
up outside it. The first two the module refuses to do unless you set
acknowledge_billable_resources = true; the last two it cannot prevent.
1. Exceeding an Always Free cap. Since 15 June 2026 the Ampere A1 Compute allocation is 2 OCPUs and 12 GB of memory (previously 4 and 24), with a monthly budget of 1,500 OCPU hours and 9,000 GB hours. Block storage is 200 GB total across the boot volume and the Docker volume — the module's defaults (50 GB + 150 GB) sit exactly on that line. On a Pay-As-You-Go account the excess is billed; on a Free Tier account OCI refuses the resource, and instances already above the cap have been terminated.
Do not assume a Pay-As-You-Go account is safe at the old 4/24 sizing. Oracle Support has told some users it is, but Oracle's own documentation applies the new caps to every tenancy, and Pay-As-You-Go users have reported both the reduction notice and billing alerts on a single 4/24 instance.
2. Building outside your home region. Always Free eligibility is scoped to
the single region your tenancy was anchored to at sign-up. Elsewhere there is no
Always Free allocation at all: the instance and every GB of storage are billed
at full price, not just the excess over the caps. region is a required
variable with no default, and the module compares it against the tenancy's home
region before it will build. (The comparison is skipped when tenancy_ocid is
null — with session-token or principal auth the module has no tenancy to query.)
That comparison reads data.oci_identity_region_subscriptions, so whatever
credentials you run with need inspect tenancies on the tenancy. A tenancy
admin — the usual case on a Free Tier account — already has it. A
compartment-scoped service user may not, and plan will then fail on the data
source read with NotAuthorizedOrNotFound rather than on the precondition.
3. Idle reclamation. Oracle reclaims an Always Free compute instance that stays below 20% CPU, network and memory utilisation across a seven-day window. This is independent of the caps: a perfectly compliant instance can still be taken. A container workload with real traffic generally stays above the threshold; an idle Docker host may not.
4. "Out of host capacity" on recreation. Always Free Ampere A1 capacity is frequently exhausted in popular regions, and failing to create an instance is the common experience rather than the exception. Resizing an existing instance down is an in-place change with a reboot and is safe. Destroying an instance to rebuild it smaller may leave you with nothing.
- 10 TB of outbound data transfer per month, tenancy-wide.
- Network bandwidth and VNIC count scale with OCPUs — at 2 OCPUs you get half the bandwidth of a 4-OCPU instance.
- 2 VCNs per tenancy on a Free Tier account. This module creates one.
-
Plan the deployment:
terraform plan
or
tofu plan
-
Apply the deployment:
terraform apply
or
tofu apply
-
Destroy the deployment:
terraform destroy
or
tofu destroy
versions.tf: Specifies the required Terraform/OpenTofu version and provider versions.providers.tf: OCI provider configuration.network.tf: Networking resources (VCN, Subnet, Internet Gateway, Route Table, Security List).compute.tf: Compute resources (Instance, Public IP, data sources).storage.tf: Storage resources (Block Volume, Volume Attachment, Backup Policy).variables.tf: Defines the variables used in the Terraform configuration. Includes validation rules for OCPUs, RAM, and volume sizes.checks.tf: Always Free cap and home-region logic — the region-subscriptions data source, the shared locals, and the advisorycheckblock.outputs.tf: Defines the outputs of the Terraform configuration.terraform.tfvars.template: Template for user-specific variables.scripts/startup.sh: Instance setup, in two phases. Terraform attaches the block volume only after the instance reaches RUNNING, which is later than cloud-init is willing to wait, so the work is split:- Phase A (cloud-init): system packages, Docker, SSH keys, timezone, and OS tuning and hardening — journald size cap, SSH hardening, open-file and inotify limits, swapfile, optional automatic reboot, optional fail2ban. It then writes the Phase B script and installs it as a systemd oneshot service.
- Phase B (
mnt-data-setup.service): detects the block volume with exponential backoff for up to 60 minutes, mounts it at/mnt/databy UUID, makes Docker wait for that mount on reboot, and installs RunTipi and the WireGuard client if enabled. - Both phases are re-run safe: a completion marker written at the end of Phase B gates the service, and the mount is guarded by
mountpoint. Optional steps log their failures instead of aborting, and network operations retry. - Changes here reach new instances only —
compute.tfignoresuser_datachanges, and cloud-init runs it once. Existing instances need the change applied by hand; theCHANGELOG.mdmigration notes say when.
.github/workflows/: Contains GitHub Actions workflows for CI/CD.documentation.yml: Renders terraform-docs intoREADME.mdand commits it back to the PR branch.terraform.yml: Runs fmt-check, validate, tofu-test and shellcheck, and uploads a Trivy config scan to the Security tab.
Ingress firewall rules are managed automatically based on enabled features. No manual configuration is needed for common use cases.
Always enabled:
- TCP 22 (SSH) — source configurable via
ssh_source_cidr(default:0.0.0.0/0) - ICMP type 3 code 4 (fragmentation needed — required for Path MTU Discovery)
Auto-added when install_runtipi = true:
- TCP 80 (HTTP)
- TCP 443 (HTTPS)
- UDP 51820 (WireGuard)
Optional:
- ICMP ping: set
enable_ping = true(default:false)
Custom rules — use custom_ingress_security_rules with a simplified format:
custom_ingress_security_rules = [
{
description = "Allow Minecraft"
protocol = "6" # "6" (TCP) or "17" (UDP)
port_min = 25565
port_max = 25565
# source defaults to "0.0.0.0/0"
}
]By default, all outbound traffic is allowed (enable_unrestricted_egress = true). To apply restrictive egress rules, set enable_unrestricted_egress = false — the default restrictive set allows only:
- TCP 443 (HTTPS)
- TCP 80 (HTTP)
- UDP/TCP 53 (DNS)
- UDP 123 (NTP)
To further customize restrictive egress rules, override egress_security_rules.
- KMS Encryption: Set
kms_key_idto encrypt boot and data volumes with customer-managed keys - Resource Tagging: All resources are tagged with
freeform_tags(default:ManagedBy=Terraform)
If install_runtipi is set to true, the setup script will install RunTipi and configure the local network for running applications within the local domain. Follow these steps to correctly configure RunTipi:
-
Access RunTipi via Public IP:
- Install AdGuard from the RunTipi apps.
- In the "Network Interface" section, add the IP
127.0.0.1and ensure the system is also reachable from the internet. - Add a valid DNS or any DNS by modifying the
hostsfile if needed.
-
Configure DNS Resolution for VPN Network:
- Access the RunTipi dashboard and follow this guide for DNS resolution within the VPN network: RunTipi DNS Resolution Guide.
- Configure the IP to
172.18.0.254, which is the IP set for Traefik.
-
Configure WireGuard:
- Install and configure WireGuard by adding a public IP or DNS.
- Set a password and configure the AdGuard IP to
172.18.0.253. - Restart RunTipi.
-
Disable Internet Access:
- Once AdGuard is configured and running, you can disable internet access to ensure that applications are only reachable within the local network.
Once these steps are complete, you will be able to use the local network without the applications being accessible externally.
This project is licensed under the MIT License. See the LICENSE file for details.
| Name | Version |
|---|---|
| terraform | >= 1.6 |
| oci | 8.29.0 |
| Name | Version |
|---|---|
| oci | 8.29.0 |
No modules.
| Name | Type |
|---|---|
| oci_core_default_route_table.default_route_table | resource |
| oci_core_instance.instance | resource |
| oci_core_internet_gateway.internet_gateway | resource |
| oci_core_public_ip.public_ip | resource |
| oci_core_security_list.security_list | resource |
| oci_core_subnet.subnet | resource |
| oci_core_vcn.vcn | resource |
| oci_core_volume.docker_volume | resource |
| oci_core_volume_attachment.docker_volume_attachment | resource |
| oci_core_volume_backup_policy.docker_volume_backup_policy | resource |
| oci_core_volume_backup_policy_assignment.docker_volume_backup_policy_assignment | resource |
| oci_core_private_ips.instance_private_ip | data source |
| oci_identity_availability_domain.ad | data source |
| oci_identity_region_subscriptions.tenancy | data source |
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| acknowledge_billable_resources | Acknowledge that the configuration provisions resources outside the Always Free allocation. Unlocks three things: compute above 2 OCPUs / 12 GB, more than 200 GB of total block storage, and a region other than the tenancy home region. On a Pay-As-You-Go account these are billed; on a Free Tier account they are refused by OCI. | bool |
false |
no |
| additional_ssh_public_key | Additional SSH public key to add to authorized_keys (optional) | string |
"" |
no |
| auth_method | OCI provider authentication method. Use "ApiKey" for API key auth or "SecurityToken" for CLI session-token auth (oci session authenticate). | string |
"ApiKey" |
no |
| auto_reboot_time | Time of day (HH:MM, 24-hour) for the unattended-upgrades automatic reboot. Only used when enable_auto_reboot=true. | string |
"03:30" |
no |
| availability_domain_number | The availability domain number (1-3 depending on region) | number |
1 |
no |
| compartment_ocid | The OCID of the compartment | string |
n/a | yes |
| config_file_profile | Profile in ~/.oci/config to use. Relevant for SecurityToken auth (the session-token profile created by oci session authenticate). |
string |
"DEFAULT" |
no |
| custom_ingress_security_rules | Additional custom ingress rules. SSH (22/TCP) and ICMP fragmentation are always enabled. HTTP (80), HTTPS (443), and WireGuard (51820/UDP) are auto-added when install_runtipi=true. Ping is controlled by enable_ping. | list(object({ |
[] |
no |
| docker_data_root_on_block_volume | Move Docker's data-root to the block volume (/mnt/data/docker) via a one-time guarded copy-then-switch migration. Merges into any existing /etc/docker/daemon.json, preserving log-driver/log-opts and default-address-pools. Default false. | bool |
false |
no |
| docker_volume_size_gb | The size of the secondary block volume in GBs (mounted at /mnt/data for Docker data) | number |
150 |
no |
| egress_security_rules | List of egress (outbound) security rules. Only used when enable_unrestricted_egress=false. Default allows HTTP, HTTPS, DNS, and NTP. | list(object({ |
[ |
no |
| enable_auto_reboot | Enable automatic reboot via unattended-upgrades so kernel security updates take effect. Reboot occurs at auto_reboot_time. Default false (preserves current behavior). | bool |
false |
no |
| enable_fail2ban | Install and enable fail2ban (Phase A, non-fatal). Low value with key-only SSH but reduces auth-log noise. Default false (preserves current behavior). | bool |
false |
no |
| enable_ping | Whether to allow ICMP echo requests (ping) from anywhere | bool |
false |
no |
| enable_unrestricted_egress | Allow all outbound traffic (all protocols, all ports, 0.0.0.0/0). When false, only egress_security_rules are applied. NOTE: if using WireGuard with restrictive egress, add a UDP rule for your WireGuard server endpoint port to egress_security_rules. | bool |
true |
no |
| fault_domain | The fault domain for the instance (FAULT-DOMAIN-1, FAULT-DOMAIN-2, or FAULT-DOMAIN-3) | string |
"FAULT-DOMAIN-2" |
no |
| freeform_tags | Freeform tags to apply to all resources | map(string) |
{ |
no |
| install_runtipi | Whether to install RunTipi homeserver (https://runtipi.io) | bool |
true |
no |
| instance_display_name | The display name of the instance (also used as hostname label — alphanumeric and hyphens only, must start with a letter) | string |
"DockerHost" |
no |
| instance_image_ocids_by_region | Map of OCI region to Ubuntu 24.04 ARM64 image OCID | map(string) |
{ |
no |
| instance_shape | The OCI compute shape (VM.Standard.A1.Flex for Always Free ARM instances) | string |
"VM.Standard.A1.Flex" |
no |
| instance_shape_boot_volume_size_gb | The size of the boot volume in GBs | number |
50 |
no |
| instance_shape_config_memory_gb | The amount of memory in GBs for the instance. The Always Free cap is 12 GB; anything above it requires acknowledge_billable_resources. | number |
12 |
no |
| instance_shape_config_ocpus | The number of OCPUs for the instance. The Always Free cap is 2 OCPUs; anything above it requires acknowledge_billable_resources. | number |
2 |
no |
| kms_key_id | The OCID of the KMS key to use for volume encryption. If null, volumes will not be encrypted with customer-managed keys. | string |
null |
no |
| oracle_api_key_fingerprint | The fingerprint of the OCI API public key (required only for ApiKey auth). | string |
null |
no |
| oracle_api_private_key_path | The path to the OCI API private key file | string |
"~/.oci/oci_api_key.pem" |
no |
| region | The OCI region to deploy resources. Must be the tenancy home region: Always Free eligibility is scoped to it, and instances and volumes built anywhere else are billed at full price. Building outside it requires acknowledge_billable_resources. | string |
n/a | yes |
| runtipi_adguard_ip | The static IP for AdGuard. Must be within runtipi_main_network_subnet and different from reverse proxy IP | string |
"172.18.0.253" |
no |
| runtipi_main_network_subnet | The Docker network subnet for RunTipi containers | string |
"172.18.0.0/16" |
no |
| runtipi_reverse_proxy_ip | The static IP for RunTipi reverse proxy (Traefik). Must be within runtipi_main_network_subnet | string |
"172.18.0.254" |
no |
| ssh_public_key | The public key to use for SSH access | string |
n/a | yes |
| ssh_source_cidr | Source CIDR allowed for SSH access (default: 0.0.0.0/0 — all IPs) | string |
"0.0.0.0/0" |
no |
| subnet_cidr_block | The CIDR block for the subnet (must be within vcn_cidr_block; OCI will reject it at apply time otherwise) | string |
"10.1.0.0/24" |
no |
| swap_size_gb | Size in GB of an optional swapfile created on the boot disk (/swapfile). 0 disables swap. When > 0, vm.swappiness=10 is also applied. Defaults to 4 GB, which offsets the reduced Always Free memory cap. | number |
4 |
no |
| tenancy_ocid | The OCID of the tenancy (for SecurityToken auth it is read from the session profile and can be left null). | string |
null |
no |
| timezone | IANA timezone for the instance (e.g. Europe/Rome, America/New_York, UTC) | string |
"Europe/Rome" |
no |
| user_ocid | The OCID of the user to use for authentication (required only for ApiKey auth). | string |
null |
no |
| vcn_cidr_block | The CIDR block for the VCN | string |
"10.1.0.0/16" |
no |
| wireguard_client_configuration | WireGuard client configuration (wg0.conf content). If provided, WireGuard will be installed and configured automatically | string |
"" |
no |
| Name | Description |
|---|---|
| availability_domain | The availability domain where resources are deployed |
| docker_volume_id | The OCID of the Docker volume |
| instance_id | The OCID of the instance |
| internet_gateway_id | The OCID of the internet gateway |
| private_ip | The private IP of the instance |
| public_ip | The public IP of the instance |
| security_list_id | The OCID of the security list |
| ssh_connection | SSH command to connect to the instance |
| subnet_cidr_block | The CIDR block of the subnet |
| subnet_id | The OCID of the subnet |
| vcn_cidr_block | The CIDR block of the VCN |
| vcn_id | The OCID of the VCN |