Skip to content

Terraform Configuration for K3s on OCI

import { Aside } from ‘@astrojs/starlight/components’;

Create tf-k3s/terraform.tfvars with your environment-specific values. This file is gitignored and should never be committed.

tenancy_ocid = "ocid1.tenancy.oc1..aaaa..."
user_ocid = "ocid1.user.oc1..aaaa..."
fingerprint = "12:34:56:..."
private_key_path = "/path/to/oci_api_key.pem"
compartment_ocid = "ocid1.compartment.oc1..aaaa..."
region = "us-ashburn-1"
ssh_public_key_path = "/path/to/ssh_key.pub"
cloudflare_api_token = "your-cloudflare-token"
cloudflare_zone_id = "your-zone-id"
domain_name = "k3s.yourdomain.com"
acme_email = "admin@yourdomain.com"
git_repo_url = "https://github.com/your-username/k3s-oracle.git"
git_username = "your-username"
git_email = "your-email@example.com"
git_pat = "ghp_..."
k3s_token = "your-random-secure-token"
argocd_admin_password = "your-secure-password"
argocd_admin_password_hash = "$2a$10$..." # bcrypt hash of argocd_admin_password
VariableDescriptionStored in Vault
tenancy_ocidOCI Tenancy OCID from the consoleNo
user_ocidOCI User OCID for API accessNo
fingerprintAPI key fingerprintNo
private_key_pathPath to the OCI API private keyNo
compartment_ocidCompartment where resources will be createdNo
regionOCI region identifierNo
ssh_public_key_pathPath to SSH public key in OpenSSH formatYes
cloudflare_api_tokenCloudflare API token with Zone.DNS EditYes
cloudflare_zone_idZone ID from Cloudflare dashboardYes
domain_nameDomain for the cluster applicationsYes
acme_emailEmail for Let’s Encrypt notificationsYes
git_repo_urlHTTPS URL of your forked repositoryYes
git_usernameGitHub usernameYes
git_emailEmail for GHCR authenticationYes
git_patGitHub Personal Access TokenYes
k3s_tokenShared secret for K3s node authenticationYes
argocd_admin_passwordPassword for ArgoCD admin userYes
argocd_admin_password_hashBcrypt hash of the password (for argocd-secret)Yes

ArgoCD requires a bcrypt hash of the admin password for authentication. Generate it with:

Terminal window
htpasswd -nbBC 10 "" "your-password" | tr -d ':\n' | sed 's/^\$/\$2a\$/'

The SSH public key must be in OpenSSH format, starting with ssh-rsa or ssh-ed25519. PEM format keys are not accepted by OCI metadata.

To generate a new key:

Terminal window
ssh-keygen -t ed25519 -f ./oci_key -N ""

After terraform apply, the following Always Free resources are created:

ResourceFree Tier LimitUsage
Object Storage20 GB~1 MB (tfstate)
Vault Secrets15010 secrets
Vault Master Keys20 versions1 key
Ampere A1 Compute4 OCPUs, 24 GB RAM4 OCPUs, 24 GB

Terraform state is stored in OCI Object Storage bucket k3s-tfstate with versioning enabled. The bucket is created during the first apply and reused for subsequent runs.