Templatization Variables

How to templative parameters for multiple environments

Opta allows you to use the same service yml file with multiple environments. Additionally, you can use variables to customize the behavior on a per-environment basis.

# hello.yaml
name: hello
environments:
  - name: staging
    path: "staging/opta.yaml"
    variables:
      containers: 1
  - name: production
    path: "production/opta.yaml"
    variables:
      containers: 5
modules:
  - name: hello
    type: k8s-service
    port:
      http: 80
    image: ghcr.io/run-x/opta-examples/hello-app:main
    healthcheck_path: "/"
    public_uri: "/hello"
    min_containers: 1
    max_containers: "{variables.containers}"

With this configuration, your service will have 5 max_containers in production but only 1 in staging.

To specify the environment to use use the --env flag:

opta apply -c hello.yaml --env staging