Skip to main content
Template functions enable dynamic configuration across all installation types. These generic functions work in both blueprint configurations and installation configs.
kind: ServiceInstallation
metadata:
  name: my-app-production
spec:
  service: my-app
  environment: production
  config:
    - key: service_name
      value: '{{ lower "MY-SERVICE" }}'
    - key: replicas
      value: '{{ default 3 .ryvn.env.config.replicas }}'
    - key: environment
      value: '{{ .ryvn.env.name }}'

Template Context Object

All templates have access to the .ryvn context object. The following properties are available:

.ryvn.env — Environment context

PropertyTypeDescription
.ryvn.env.namestringEnvironment name
.ryvn.env.orgIdstringOrganization ID
.ryvn.env.defaultNamespacestringDefault Kubernetes namespace
.ryvn.env.releaseChannelstringEnvironment’s release channel
.ryvn.env.provider.typestringCloud provider (aws, gcp, azure, k3s)
.ryvn.env.provider.aws.accountIdstringAWS account ID (AWS only)
.ryvn.env.provider.gcp.projectIdstringGCP project ID (GCP only)
.ryvn.env.configobjectEnvironment config as key-value map (e.g., .ryvn.env.config.region)
.ryvn.env.stateobjectProvisioned infrastructure state (cluster info, VPC, domains, etc.)
For the full list of .ryvn.env.state properties (VPC IDs, subnet CIDRs, cluster endpoints, domain names, etc.), see the Outputs section of the environment reference for your provider: AWS, GCP, Azure.

.ryvn.installation — Installation context

PropertyTypeDescription
.ryvn.installation.namestringInstallation name
.ryvn.installation.outputsobjectInstallation outputs

.ryvn.release — Release context

PropertyTypeDescription
.ryvn.release.images.<name>.repostringImage repository for a named artifact
.ryvn.release.images.<name>.tagstringImage tag for a named artifact

.ryvn.registrySecrets — Registry credentials

PropertyTypeDescription
.ryvn.registrySecretsmapMap of registry name to Kubernetes secret name for image pull secrets

Template helper functions

FunctionDescription
serviceInstallation "<name>"Get another service installation’s .outputs and .outputsSecret
blueprintInstallation "<name>"Get a blueprint installation’s .outputs and .outputsSecret
k8sSecretName "<name>"Get the Kubernetes secret name for a variable group
k8sSecretValue "<name>" ["<key>"]Get a secret value from a variable group (optionally by key)

String Functions

lower, upper, title, trim

Transform string values.
config: |
  # Convert to lowercase
  env_name: {{ lower "PRODUCTION" }}

  # Convert to uppercase
  region: {{ upper "us-east-1" }}

  # Title case
  display_name: {{ title "my service" }}

  # Remove whitespace
  cleaned: {{ trim "  value  " }}

contains

Check if a string contains a substring. Returns boolean.
config: |
  # Check if environment name contains "prod"
  is_production: {{ contains "prod" .ryvn.env.name }}

  # Check for feature flag
  {{ if contains "beta" .ryvn.env.releaseChannel }}
  enable_experimental: true
  {{ end }}

substring

Extract a substring from a string. If start is < 0, extracts from beginning to end position. If end is < 0 or greater than length, extracts from start to end of string.
config: |
  # Get first 5 characters
  short_name: {{ substring 0 5 .ryvn.env.name }}

  # Get from position 3 to end
  suffix: {{ substring 3 -1 .ryvn.installation.name }}

default

Provide a default value if the given value is empty or undefined.
config: |
  # Use default if config value is not set
  replicas: {{ default 3 .ryvn.env.config.replicas }}

  # Provide default timeout
  timeout: {{ default "30s" .ryvn.env.config.timeout }}

  # Default log level
  log_level: {{ default "info" .ryvn.env.config.log_level }}

Data Formatting Functions

toYaml

Convert data structures to YAML format. Useful for including complex configuration objects.
config: |
  # Include environment config as YAML
  environment:
{{ toYaml .ryvn.env.config | nindent 4 }}

  # Include installation outputs
  outputs:
{{ toYaml .ryvn.installation.outputs | indent 2 }}

toJson

Convert data structures to JSON format.
config: |
  # Convert to JSON string
  metadata: {{ toJson .ryvn.env.config }}

  # Include state as JSON
  state_json: {{ toJson .ryvn.env.state }}

indent, nindent

Add indentation to multi-line strings. indent adds spaces to each line. nindent adds a newline before indenting.
config: |
  # Using indent (no leading newline)
  nested:
    {{ indent 4 (toYaml .ryvn.env.config) }}

  # Using nindent (adds newline first)
  data:{{ nindent 2 (toYaml .ryvn.env.state) }}

join

Join array elements with a separator.
config: |
  # Join with comma
  {{ if .ryvn.env.config.zones }}
  availability_zones: {{ join "," .ryvn.env.config.zones }}
  {{ end }}

Control Flow

Go templates support control flow statements for conditional logic.

Conditionals

Use if, else if, else, and end:
config: |
  {{ if eq .ryvn.env.provider.type "aws" }}
  cloud: aws
  storage_class: gp3
  {{ else if eq .ryvn.env.provider.type "gcp" }}
  cloud: gcp
  storage_class: pd-ssd
  {{ else }}
  cloud: unknown
  {{ end }}

Comparison Operators

  • eq - equal to
  • ne - not equal to
  • lt - less than
  • le - less than or equal to
  • gt - greater than
  • ge - greater than or equal to
config: |
  {{ if gt .ryvn.env.config.replicas 5 }}
  high_availability: true
  {{ end }}

  {{ if ne .ryvn.env.releaseChannel "stable" }}
  experimental_features: true
  {{ end }}

Boolean Logic

Use and, or, and not:
config: |
  {{ if and (eq .ryvn.env.provider.type "aws") (eq .ryvn.env.name "production") }}
  enable_cloudwatch: true
  {{ end }}

  {{ if or (contains "prod" .ryvn.env.name) (contains "staging" .ryvn.env.name) }}
  monitoring: enabled
  {{ end }}

  {{ if not (eq .ryvn.env.releaseChannel "stable") }}
  log_level: debug
  {{ end }}

Examples

Provider-Specific Configuration

Configure differently based on cloud provider:
config: |
  service_name: my-app
  environment: {{ .ryvn.env.name }}

  storage:
    {{ if eq .ryvn.env.provider.type "aws" }}
    type: ebs
    class: gp3
    iops: 16000
    {{ else if eq .ryvn.env.provider.type "gcp" }}
    type: persistent-disk
    class: pd-ssd
    {{ else if eq .ryvn.env.provider.type "azure" }}
    type: azure-disk
    class: managed-premium
    {{ end }}
    size: {{ default "100Gi" .ryvn.env.config.storage_size }}

Using Installation Outputs

Reference outputs from other installations in the same environment using the installation function:
config: |
  # Reference database installation outputs
  database:
    host: {{ (serviceInstallation "postgres").outputs.host }}
    port: {{ (serviceInstallation "postgres").outputs.port }}
    name: {{ (serviceInstallation "postgres").outputs.database }}

  # Reference cache installation
  {{ with (serviceInstallation "redis") }}
  cache:
    enabled: true
    host: {{ .outputs.host }}
  {{ else }}
  cache:
    enabled: false
  {{ end }}

Using Blueprint Outputs

Reference outputs exposed by blueprints installed in the same environment using the blueprint function. Blueprint outputs are declared in the blueprint spec and resolved from underlying installation outputs.
config: |
  # Reference outputs from a blueprint called "database-stack"
  database:
    host: {{ (blueprintInstallation "database-stack").outputs.host }}
    port: {{ (blueprintInstallation "database-stack").outputs.port }}
Secret outputs (isSecret: true in the blueprint output definition) are not available via .outputs template syntax. Use valueFromOutput in env vars to consume them (see Server or Job reference). For Helm charts, use .outputsSecret to get the Kubernetes secret name and reference individual keys:
config: |
  # .outputsSecret returns the K8s secret name containing the secret outputs
  # Use this in Helm values to wire secrets without exposing them in plaintext
  env:
    - name: DATABASE_URL
      valueFrom:
        secretKeyRef:
          name: {{ (blueprintInstallation "database-stack").outputsSecret }}
          key: connection_string
    - name: API_KEY
      valueFrom:
        secretKeyRef:
          name: {{ (serviceInstallation "auth-service").outputsSecret }}
          key: api_key

Complex Data Transformation

Combine multiple functions:
config: |
  service:
    name: {{ lower .ryvn.installation.name }}
    environment: {{ upper .ryvn.env.name }}
    namespace: {{ .ryvn.env.defaultNamespace }}

  # Include all environment config
  envConfig:
{{ toYaml .ryvn.env.config | nindent 4 }}

  # Provider-specific settings
  {{ if eq .ryvn.env.provider.type "aws" }}
  aws:
    region: {{ default "us-east-1" .ryvn.env.config.region }}
    account_id: {{ .ryvn.env.provider.aws.accountId }}
  {{ else if eq .ryvn.env.provider.type "gcp" }}
  gcp:
    project_id: {{ .ryvn.env.provider.gcp.projectId }}
    region: {{ default "us-central1" .ryvn.env.config.region }}
  {{ end }}

  # Feature flags based on release channel
  features:
    beta_features: {{ contains "beta" .ryvn.env.releaseChannel }}
    stable_only: {{ eq .ryvn.env.releaseChannel "stable" }}

Using Release Images

Reference images from releases:
config: |
  containers:
    - name: app
      image: {{ .ryvn.release.images.app.repo }}:{{ .ryvn.release.images.app.tag }}

    {{ if .ryvn.release.images.sidecar }}
    - name: sidecar
      image: {{ .ryvn.release.images.sidecar.repo }}:{{ .ryvn.release.images.sidecar.tag }}
    {{ end }}

Environment-Specific Scaling

Configure resources based on environment:
config: |
  replicas: {{ default 1 .ryvn.env.config.replicas }}

  resources:
    {{ if contains "prod" .ryvn.env.name }}
    limits:
      cpu: "2000m"
      memory: "4Gi"
    {{ else if contains "staging" .ryvn.env.name }}
    limits:
      cpu: "1000m"
      memory: "2Gi"
    {{ else }}
    limits:
      cpu: "500m"
      memory: "1Gi"
    {{ end }}

  # Include custom resource requirements if specified
  {{ if .ryvn.env.config.resources }}
  customResources:
{{ toYaml .ryvn.env.config.resources | nindent 4 }}
  {{ end }}