Environment variables

Overview

Walhall is designed to deploy your existing code to Kubernetes without having to change anything.

You can use variable substitutions within environment variables to dynamically reference values that depend on the environment (e.g., the module’s database, auto-generated external DNS names). A variable substitution consists of a string that you enter in the value of an environment variable in a module’s configuration map. When you deploy your app, Walhall will replace these strings with the values that they reference.

See the last section for a list of possible variable substitutions.

Examples

Case 1: Database values

At this time, all apps must use a CloudSQL instance created and managed by Walhall in its own GCP cluster. You can use variable substitutions to map the database variable(s) used in the code of your module to the Walhall-managed database.

Suppose the code uses DATABASE_NAME to reference the name of the database. You would click on your module in Walhall, go to the Variables tab, and create an environment variable with the key DATABASE_NAME and the placeholder ${dbs.postgres.name}.

Screenshot: Creating a configuration with a variable substitution for the database name

Then, when you deploy your app, your module will be able to communicate with the database provisioned by Walhall.

Case 2: Simple frontend & backend references

Suppose you have two modules: product-fe (frontend module) and product-be (backend module). The frontend module serves a web client that makes API requests to the /products endpoint served by the backend.

Diagram: Simple app that consists of a frontend that serves a web client and sends API requests to a backend, which communicates with a database

The frontend module needs to know the DNS name of the backend module in order to send the API requests. However, in Walhall, this name is generated when the app is deployed. The code in the frontend module repository uses the variable PRODUCT_BE_SERVER_URL to communicate with the backend module.

In this example, you could define an environment variable called PRODUCT_BE_SERVER_URL and use a variable substitution to dynamically reference the IP address of the backend, even if it hasn’t been generated yet. As the value of PRODUCT_BE_SERVER_URL, you would enter http://${modules.product-be.service.name}/products.

When you deploy the app, Walhall would create an environment variable PRODUCT_BE_SERVER_URL, and in the value, it would replace the variable substitution with the IP address of the backend. Then, the frontend would be able to make requests to the /products endpoint.

Screenshot: Creating a configuration with a variable substitution for the backend URL

How to create a variable substitution

  1. Log in to Walhall and go to your app.
  2. Click Create draft.
  3. Click on the module where you would like to create the variable substitution.
  4. Scroll down to the Variables section.
  5. Enter the name of the variable that your code references in the key field.
  6. In the value field, type ${ to bring up an autocomplete dropdown.
    Screenshot: Autocomplete dropdown
    • If you want to create a variable substitution for a database variable, then choose the proper value from dbs.
    • If you want to create a variable substitution that will resolve to the name of one of the other modules in your app, choose modules.
      See the next section for information about which variable substitutions you can create.
  7. Click Create.

Your variable substitution will be created. In order to apply it, you must re-deploy your app.

List of variable substitutions

Note: This list will expand over time.

Database references

Variable substitution name Description
dbs.postgres.name The name of the database that your module connects to.
dbs.postgres.engine Database engine used. Will always be POSTGRES.
dbs.postgres.host The DNS name or IP of the database server.
dbs.postgres.username Username of the Postgres ROLE that has access to the database defined in dbs.postgres.name.
dbs.postgres.password Password of the Postgres ROLE that has access to the database defined in dbs.postgres.name.
dbs.postgres.port Port on the server defined by dbs.postgres.host.

Module references

Variable substitution name Description
module.{MODULE-NAME}.service.name In-cluster DNS name of the module.
modules.{MODULE-NAME}.service.external-name DNS name of the module, which is generated if you expose the module externally.