RunR v0.7.5

Documentation

runr_project (Resource)

A RunR project: a function (faas), a single-file script (xaas) or a container (caas) in a region. Code is uploaded with runr deploy; container images and deployments can be managed with runr_deployment.

A config change saves a new project version; running deployments pick it up when they are redeployed (see runr_deployment.triggers).

Example Usage#

data "runr_region" "eu" {
  name = "eu-1"
}

# A Python function; its code is uploaded with `runr deploy`.
resource "runr_project" "api" {
  name      = "orders-api"
  type      = "faas"
  runtime   = "python"
  region_id = data.runr_region.eu.id
  handler   = "main.handler"

  resources = {
    cpu             = "250m"
    memory_mb       = 256
    timeout_seconds = 30
  }

  scale = {
    min     = 0
    max     = 10
    to_zero = true
  }

  # Timed warmer: 3 containers warm on weekdays from 09:00, none from 18:00 (organization time zone)
  scale_schedule = [
    { cron = "0 9 * * 1-5", min_scale = 3 },
    { cron = "0 18 * * 1-5", min_scale = 0 },
  ]

  trigger = {
    type = "http"
  }
}

# A nightly job at 02:00 Berlin time ("" or left out on a new schedule: the organization's zone).
resource "runr_project" "report" {
  name      = "nightly-report"
  type      = "faas"
  runtime   = "nodejs"
  region_id = data.runr_region.eu.id

  trigger = {
    type     = "schedule"
    schedule = "0 2 * * *"
    timezone = "Europe/Berlin"
  }
}

# A container.
resource "runr_project" "web" {
  name      = "web"
  type      = "caas"
  region_id = data.runr_region.eu.id
  image     = "ghcr.io/acme/web:1.4.2"
  ports     = [8080]

  # Let runr_deployment (or CI) roll out new images.
  lifecycle {
    ignore_changes = [image]
  }
}

# The whole trigger list: HTTP requests, a schedule, a Kafka topic and a webhook inbox.
resource "runr_project" "orders" {
  name      = "orders"
  type      = "faas"
  runtime   = "python"
  region_id = data.runr_region.eu.id

  triggers = [
    { type = "http" },
    {
      name   = "nightly"
      type   = "schedule"
      config = jsonencode({ cron = "0 2 * * *", timezone = "Europe/Berlin" })
    },
    {
      name    = "orders"
      type    = "kafka"
      config  = jsonencode({ brokers = ["kafka-1:9092"], topic = "orders", sasl = { mechanism = "scram-sha-512", username = "orders" } })
      secrets = { sasl_password = var.kafka_password }
    },
    {
      name    = "github"
      type    = "webhook"
      config  = jsonencode({ verify = "github" })
      secrets = { signing_secret = var.github_webhook_secret }
    },
  ]

  # No public URL: only the orders-api project calls it, on the region's internal network.
  network = {
    access_mode = "internal"
    callers     = [runr_project.api.network.internal_name]
  }

  # New versions take 10 %, then 50 % of the traffic, five minutes each.
  deploy_strategy = {
    strategy = "canary"
    canary = {
      steps                = [10, 50]
      interval_minutes     = 5
      error_rate_threshold = 2
    }
  }
}

# A global project: the primary region (region_id) and a standby region behind one host name.
data "runr_region" "us" {
  name = "us-1"
}

resource "runr_project" "shop" {
  name      = "shop"
  type      = "caas"
  region_id = data.runr_region.eu.id
  image     = "ghcr.io/acme/shop:2.0.0"
  ports     = [8080]

  global = {
    regions  = [data.runr_region.eu.id, data.runr_region.us.id]
    mode     = "ha"
    failover = "automatic"
  }
}

variable "kafka_password" {
  type      = string
  sensitive = true
}

variable "github_webhook_secret" {
  type      = string
  sensitive = true
}

Schema#

Required#

  • name (String) Project name; its slug names the service and the default URL. Changing it creates a new project.
  • region_id (String) Region id (data.runr_region). Changing it moves the project.
  • type (String) faas, xaas or caas. Changing it creates a new project.

Optional#

  • args (List of String) caas: arguments.
  • command (List of String) caas: entrypoint override.
  • deploy_strategy (Attributes) How a deploy rolls out (deploy strategies): direct, blue_green or canary with the options of both. Values left out stay as they are; the project's environments use these settings unless they set their own. Promotion, abort and rollback of a rollout stay with runr rollout. (see below for nested schema)
  • description (String) Free text.
  • filename (String) xaas: the script file (default main.<ext>).
  • global (Attributes) A global project (global projects): the project runs in every region of regions behind one host name, region_id is its primary region. A project is created global or regional: adding global to a regional project replaces it. Left out, a global project stays as it is. The regions need global DNS. (see below for nested schema)
  • handler (String) faas: file.function (default main.handler → main.py, def handler). xaas: the function name (default handler).
  • image (String) caas: container image. Required when the project is created.
  • network (Attributes) Who reaches the project (internal network). Values left out stay as they are. Changing the access mode or the allow list needs network.manage. (see below for nested schema)
  • ports (List of Number) caas: container ports; the first serves HTTP (default 80).
  • resources (Attributes) Container limits. (see below for nested schema)
  • runtime (String) Runtime of faas/xaas projects: python, nodejs, go, php, … Changing it creates a new project.
  • runtime_version (String) Runtime version; default the platform's default version. Changing it creates a new project.
  • scale (Attributes) Autoscaling range. (see below for nested schema)
  • scale_schedule (Attributes List) Timed warmer: each row keeps at least min_scale containers warm from the moment its five-field cron expression fires until the next row fires. The expressions run in the organization's time zone (its Time zone setting, default Europe/Istanbul). While rows are set they replace scale.min; scale.max still applies. RunR applies a changed schedule to the running workload within a minute, without a redeploy. At most 10 rows; [] turns the warmer off, leaving the attribute out keeps the project's schedule as it is. (see below for nested schema)
  • trigger (Attributes) What starts the code: the project's primary trigger, the first enabled one of its trigger list. Setting it changes the primary trigger's type and settings and leaves the project's other triggers as they are; triggers sets the whole list instead (set either trigger or triggers). Read back, it is the primary trigger, which can be of a type only triggers sets (e.g. webhook or kafka). (see below for nested schema)
  • triggers (Attributes List) The project's whole trigger list, in order: the first enabled trigger is the primary one (trigger reads it back). Set, the list replaces the project's list — a trigger whose name and type match one the project has keeps its secrets, webhook inbox URL and stored events; the others are created or removed. Left out, the list stays as it is (and trigger can set the primary trigger). Set either trigger or triggers. A change reaches the running deployment with the next deploy. (see below for nested schema)

Read-Only#

  • endpoint_url (String) Public URL (HTTP trigger).
  • id (String) Project id.
  • latest_version_id (String) Id of the newest version.
  • slug (String) Slug derived from the name.

Nested Schema for deploy_strategy#

Optional:

  • blue_green (Attributes) Options of the blue-green strategy. Left out, the options stay as they are. (see below for nested schema)
  • canary (Attributes) Options of the canary strategy. Left out, the options stay as they are. (see below for nested schema)
  • strategy (String) direct (the new revision replaces the live one once it is ready), blue_green or canary. A strategy other than direct needs an http or workflow trigger.

Nested Schema for deploy_strategy.blue_green#

Optional:

  • auto_promote (Boolean) Promote once the health checks passed; false waits for runr rollout promote.
  • health_checks (Number) Consecutive 2xx answers auto promotion needs (1-20, one every 10 s).
  • health_path (String) Path the health checks call, e.g. /healthz. Not set in a configured blue_green block: the new revision's readiness alone decides.
  • keep_previous_minutes (Number) Minutes the previous revision stays warm after promotion for an instant rollback (0-1440).

Nested Schema for deploy_strategy.canary#

Optional:

  • error_rate_threshold (Number) Roll back above this error rate of the new revision in percent (0-100). Not set in a configured canary block: not checked.
  • interval_minutes (Number) How long each step lasts (1-1440 minutes).
  • p95_threshold_ms (Number) Roll back above this 95th percentile latency in milliseconds (1-600000). Not set in a configured canary block: not checked.
  • steps (List of Number) Traffic percentages of the new revision, strictly increasing (1-10 steps, 1-100); reaching 100 promotes it.

Nested Schema for global#

Required:

  • regions (List of String) Region ids in HA order (2-8), region_id (the primary) among them. A region left out has its copy removed; a new one gets the active version.

Optional:

  • failover (String) automatic (default: RunR moves the primary when its health check keeps failing) or manual (runr projects global failover).
  • mode (String) ha (default: DNS answers the primary while it is healthy, the others when it is not) or proximity (the healthy region closest to the client).

Read-Only:

  • bindings (Attributes List) How the project's bindings are reached from every region: access is direct (an external binding), link (the data link to its home region) or replicas (a replica cluster in every region). (see below for nested schema)
  • failover_after_seconds (Number) How long the primary's health check fails before an automatic failover.
  • hostname (String) The global host name <slug>.<zone> (empty while the platform has no base domain).

Nested Schema for global.bindings#

Read-Only:

  • access (String) direct, link or replicas.
  • binding_id (String) Binding id.
  • home_region_id (String) The region its data lives in.
  • name (String) Binding name.
  • type (String) Binding type.

Nested Schema for network#

Optional:

  • access_mode (String) public (anyone reaches the public URL; the default), allowlist (the public URL answers allowed_cidrs only) or internal (no public URL: the projects in callers call it on the region's internal network).
  • allowed_cidrs (Set of String) IP addresses or CIDR ranges the public URL answers in allowlist mode (empty in the other modes).
  • callers (Set of String) Projects allowed to call this one on the internal network, by internal name <project>.<organization> (another project's network.internal_name; another organization's project where the platform allows it). Set, it is the whole allow list; [] removes every caller.

Read-Only:

  • internal_name (String) The project's internal name <project>.<organization>, for other projects' callers.
  • internal_url (String) The URL other projects of the region call it at on the internal network.

Nested Schema for resources#

Optional:

  • cpu (String) Kubernetes CPU quantity (100m, 0.5).
  • memory_mb (Number) Memory in MB (at least 64).
  • timeout_seconds (Number) Request timeout in seconds.

Nested Schema for scale#

Optional:

  • max (Number) Maximum instances (1-1000).
  • min (Number) Minimum instances (0-10).
  • to_zero (Boolean) Scale to zero instances when idle.

Nested Schema for scale_schedule#

Required:

  • cron (String) Five-field cron expression (minute hour day-of-month month day-of-week), fields separated by one space, e.g. 0 9 * * 1-5.
  • min_scale (Number) Containers kept warm from this moment on (0-10, at most scale.max).

Nested Schema for trigger#

Optional:

  • queue (String) Redis stream of a queue trigger (the region needs Redis).
  • schedule (String) Cron expression of a schedule trigger, e.g. */5 * * * *.
  • timezone (String) IANA time zone the schedule runs in, e.g. Europe/Berlin or UTC. "" runs it in the organization's time zone (its Time zone setting, default Europe/Istanbul), which it then follows. Leaving it out keeps the schedule's zone: a new schedule runs in the organization's, one created before RunR 0.6.0 in UTC.
  • type (String) http (default), schedule, queue or workflow (a durable workflow project; its only trigger). Reads back the primary trigger's type, which can be one triggers sets (e.g. webhook or kafka).

Read-Only:

  • effective_timezone (String) The time zone the schedule runs in: timezone, else the organization's; null without a schedule.

Nested Schema for triggers#

Required:

  • type (String) http, schedule, queue, workflow, webhook, topic, platform_event or an event source: kafka, nats, rabbitmq, mqtt, cdc (Postgres logical replication), email (IMAP) or s3. At most one http trigger; a workflow trigger is the project's only one.

Optional:

  • config (String) The type's settings as JSON (jsonencode({...})), e.g. {cron = "0 2 * * *", timezone = "Europe/Berlin"} for a schedule, {brokers = ["kafka:9092"], topic = "orders"} for kafka, or {verify = "github"} for a webhook; triggers lists every type's settings. RunR fills in defaults: the state keeps this JSON while RunR's config holds every value it sets, and shows RunR's config when a value differs. Left out: RunR's config of the trigger ({} for http).
  • enabled (Boolean) Whether the trigger runs (default true).
  • name (String) Name, unique in the project (lower-case letters, digits and dashes). Default: the type (schedule, then schedule-2, …). Name triggers whose secrets or inbox URL must survive a reordering.
  • secrets (Map of String, Sensitive) Write-only secrets of the type: signing_secret (webhook), sasl_password (kafka), password / token / nkey_seed / creds (nats), url (rabbitmq), password (mqtt, email), dsn (cdc), access_key and secret_key (s3). RunR lists only their names; Terraform keeps the values it set and sets a secret again when it was removed outside Terraform. Set, the map is the trigger's whole set (a secret it leaves out is removed); left out, the trigger's secrets stay as they are.

Read-Only:

  • effective_timezone (String) The time zone a schedule runs in: its timezone, else the organization's.
  • id (String) Trigger id.
  • primary (Boolean) Whether it is the primary trigger (the first enabled one).
  • runs_on (String) What runs it: service (the project's service), gateway (its event gateway), cronjob or disabled.
  • secret_names (List of String) The names of the secrets the trigger has.
  • url (String) The public inbox URL of a webhook trigger (send the provider's webhooks there).

Import#

Import is supported using the following syntax:

The terraform import command can be used, for example:

# A project is imported by name or id.
terraform import runr_project.api orders-api

RunR v0.7.5 · MIT License