Terraform examples¶
Each example is a complete main.tf; add the provider setup next to it.
Check quota and price first¶
# Check headroom and price before creating anything.
data "rso_quota" "current" {}
data "rso_cost_estimate" "small_vm" {
instance_vcpu = 1
instance_ram_gb = 2
instance_disk_gb = 60
}
output "vcpu_remaining" {
value = data.rso_quota.current.remaining["vcpu"]
}
output "small_vm_monthly" {
value = "${data.rso_cost_estimate.small_vm.monthly} ${data.rso_cost_estimate.small_vm.currency}"
}
A serverless app¶
# A serverless app from a public image, always keeping one instance warm.
resource "rso_app" "hello" {
name = "tf-example-hello"
image = "ghcr.io/knative/helloworld-go:latest"
port = 8080
env = {
TARGET = "Terraform"
}
cpu_request = "50m"
memory_request = "64Mi"
cpu_limit = "250m"
memory_limit = "128Mi"
min_scale = 1
max_scale = 3
}
output "app_url" {
value = rso_app.hello.url
}
A virtual machine¶
# A virtual machine from an OS template, reachable with your SSH key.
data "rso_instance_templates" "all" {}
variable "template_name" {
description = "Name of the OS template to clone."
type = string
default = "ubuntu-26.04"
}
variable "ssh_public_key" {
description = "SSH public key installed for the default user."
type = string
default = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIExampleKeyReplaceMeWithYourOwnPublicKey000 example"
}
resource "rso_instance" "vm" {
name = "tf-example-vm"
template = data.rso_instance_templates.all.by_name[var.template_name]
cpus = 1
memory_mb = 1024
root_disk_gb = 20
ssh_public_key = var.ssh_public_key
}
output "instance_vmid" {
value = rso_instance.vm.vmid
}
A PostgreSQL cluster¶
# A managed PostgreSQL cluster with one primary and one replica.
resource "rso_postgres_cluster" "db" {
name = "tf-example-db"
instances = 2
storage_size = "5Gi"
cpu_request = "100m"
memory_request = "256Mi"
cpu_limit = "500m"
memory_limit = "512Mi"
}
output "postgres_host" {
value = rso_postgres_cluster.db.host
}
A container registry¶
# A private container registry. Push with:
# docker login <domain> -u <service account> -p <token>
resource "rso_docker_registry" "images" {
name = "tf-example-images"
}
output "registry_domain" {
value = rso_docker_registry.images.domain
}
A service account for CI¶
# A machine identity for CI. The token is only available at creation.
resource "rso_service_account" "ci" {
name = "tf-example-ci"
expires_at = "2027-06-30T00:00:00Z"
}
output "ci_token" {
value = rso_service_account.ci.token
sensitive = true
}