Skip to main content

okustera_function (Resource)

Deploys and manages event-driven serverless functions powered by OpenFaaS in Okustera, featuring automated scale-to-zero, autoscaling, custom runtime handlers, and environment variables.

Example Usage​

Python 3.10 Serverless Function​

resource "okustera_function" "image_resizer" {
name = "image-resizer"
description = "Processes and thumbnails uploaded user avatar images"
runtime = "python310"
handler = "handler.handle"
source_code = <<-EOT
def handle(req):
return {"status": "ok", "message": "Image resized successfully"}
EOT
memory_limit = "256Mi"
cpu_limit = "500m"
min_replicas = 0
max_replicas = 5

env_vars = jsonencode({
LOG_LEVEL = "INFO"
BUCKET_NAME = "avatars"
})

layer_version_ids = [1, 5]
}

output "function_endpoint" {
value = okustera_function.image_resizer.route_path
}

Schema​

Required​

  • handler (String) Entrypoint handler function symbol (e.g. handler.handle, index.handler).
  • name (String, Forces new resource) Unique name of the serverless function.
  • runtime (String) Language execution environment (e.g. python310, nodejs18, golang, docker).

Optional​

  • cpu_limit (String) CPU core limit constraint (e.g. 200m, 1000m).
  • description (String) Human-readable description of function purpose.
  • env_vars (String) JSON-formatted environment variables string.
  • image (String) Custom container image URL (for docker runtime).
  • layer_version_ids (List of Number) Optional list of up to 5 layer version IDs mounted into /opt.
  • max_replicas (Number) Maximum horizontal pod autoscaling threshold. Defaults to 5.
  • memory_limit (String) Memory limit constraint (e.g. 128Mi, 512Mi).
  • min_replicas (Number) Minimum idle pod replica count (scale to zero if 0). Defaults to 0.
  • secrets (String) Comma-separated list of mounted Kubernetes secrets.
  • source_code (String) Inline source code string for code-based runtimes.

Read-Only​

  • created_at (String) Timestamp when function was registered.
  • id (String) Unique function identifier.
  • invocation_count (Number) Total invocation executions count.
  • route_path (String) HTTP invocation endpoint path route.
  • status (String) Function deployment status (e.g. Ready, Building, Error).
  • updated_at (String) Timestamp when function was last updated.

Import​

Functions can be imported using the numeric function id:

terraform import okustera_function.example 12