Set variables and references
Set variables for a service, an environment or a whole project, point one value at another service with ${{ }}, and generate secrets.
Variables reach a service's processes as environment variables. Each variable lives on one tier, and the most specific tier wins: a service's own LOG_LEVEL beats the environment's, which beats the project's.
| Tier | Where you set it | Reaches |
|---|---|---|
| Service | A service's Variables tab | That service, in that environment |
| Environment | The Shared variables panel of an environment | Every service in that environment |
| Project | Project settings…, section Project variables | Every service in every environment |
| External resource | The External resources list in an environment's Shared variables panel | The services you link it to |
An external resource is the lowest tier: any other tier overrides it. A variable can be secret: its value is sealed, shown as dots, and revealed only on request.
Before you begin
- You need the
deployerrole to add, change and reveal variables, and theadminrole to add an external resource. Aviewersees keys with secrets masked. - The environment tier and the service tier are staged as a change set and take effect when you deploy it. The project tier saves at once and applies the next time each service deploys.
Add a variable to a service
Select the service on the canvas, then the Variables tab.
Select + New variable. Enter the Key in UPPER_SNAKE_CASE (lowercase is converted as you type) and the Value. Tick secret to seal the value. Select Stage.
The row appears with a new tag, and a bar at the foot of the sheet reads "1 staged change".
Select Deploy 1 change in the bar. In a protected environment the button reads Request approval.
In the review dialog, optionally describe the change, tick Accept downtime if it appears, and select Deploy 1 change again.
The service starts a deployment with the new value. Follow it on the Deployments tab.
To change a secret later, select its value and type the replacement. Leaving the field blank keeps the sealed value.
Set a value that spans several lines
A PEM private key, a certificate chain or a JSON credential is one value with line breaks in it.
- Select a value to edit it, or select + New variable.
- Type or paste the value. Press Shift+Enter or Ctrl/⌘+Enter to add a line. Enter saves and Esc cancels.
The field grows to 8 lines, then scrolls. A pasted value keeps its line breaks.
A saved value with several lines shows its first line and a chip such as +27 lines. Select the chip to read every line, and show less to fold it again. A secret shows as dots until you reveal it, and then the chip appears. The line breaks are stored and passed to the service exactly as written, including a blank line or a newline at the end. Over the API, send them as \n in the JSON string.
The review dialog, the staged-changes list and an approval show a changed value whole, not cut to its first line: the line breaks are kept and long lines wrap. A secret shows as dots there.
Share a variable with every service in an environment
- Right-click an empty spot on the canvas and select Shared variables. The panel names the environment.
- Select New shared variable, enter a key and value, and select Stage.
- Deploy the staged change as above.
Every service in the environment inherits the variable unless it sets its own. A service's Variables tab shows an inherited row with a shared tag. Select its value to open the panel it comes from. Deploying the change redeploys every service that inherits the key, and every service that references one of them.
Share a variable with every environment
- Right-click the canvas and select Project settings….
- Under Project variables, select Add variable. Enter the Key and Value, tick Secret to seal it, and select Stage variable.
- Select Save changes in the bar that appears above the list. Discard drops the staged change.
A project variable is saved immediately, outside any change set, and starts no deployment. Each service picks it up the next time it deploys. An environment or service value with the same key overrides it.
If any environment of the project is protected, every environment inherits the project tier, so a project variable would change what production runs with no approval. The console shows the section read-only and the API answers 409. Set the value in each environment's Shared variables instead, where a change waits for an approval. An approver can still write a project variable directly when the organization lets people approve their own requests (Settings > Security & policy).
The same rule covers a protected environment's own variables and its external resources: the direct API calls answer 409 and name stageChangeSetItems. nebula variables set and nebula variables unset already stage and print the approval link. External resources of a protected environment have no staged form; put the connection values in the environment's variables.
Point a value at another service
A value can contain expressions between ${{ and }}. Type ${{ in any value field to get suggestions, ranked by exact, prefix, then partial match: the services of the environment, then the functions secret(32) and host(…). Staged services come before committed ones. After service. the field lists that service's keys, each marked with its tier and with secret keys shown by name only. Inside secret( it offers the lengths 32, 48, 64, 96 and 128, and inside host( the services. On an empty value whose key is DATABASE_URL, REDIS_URL or another connection name, the field first offers the matching key of the database service. ↑ and ↓ move through the list, Enter or Tab inserts and closes the braces, and Esc closes the list.
| Expression | Becomes | When |
|---|---|---|
${{ api.DATABASE_URL }} | The value of DATABASE_URL as the service api sees it | At every deploy |
${{ host(api) }} | The in-cluster hostname of api, svc-api | Once, when you stage the value |
${{ secret(32) }} | A random string of letters and digits, at least 32 long: secret(N) draws the larger of N and 32, and secret() draws 32. The variable becomes secret | Once, when you stage the value |
An expression can sit inside other text:
API_URL = http://${{ host(api) }}:8080/v1
DATABASE_URL = ${{ db.DATABASE_URL }}
REDIS_URL = redis://${{ cache.REDIS_APP_USER }}:${{ cache.REDIS_APP_PASSWORD }}@${{ host(cache) }}:6379/0
JWT_SECRET = ${{ secret(64) }}In ${{ service.KEY }}, service is the service's slug as shown on the canvas, and KEY any key that service has on any tier it sees.
- Checked when you stage. A reference to a service that does not exist, or to a key that service will not have, is refused. The message lists the keys the service does have. For a project variable only the service is checked, because its keys differ per environment.
- Resolved at every deploy. A change to the referenced value redeploys the services that reference it.
- Secrets stay secret. A reference to a secret is resolved at deploy time. The resolved value goes to the cluster and is never stored on the release.
- Draws the canvas. Every reference is a dependency, and the canvas draws an edge for it. A reference also makes the service deploy after the one it names.
References are followed up to five deep. A cycle, or a reference whose target is gone, stops the deploy with a message that names the chain. ${{ inputs.KEY }} exists only in templates. Any other text between the braces is refused when you stage it. The full grammar is in Variable expressions.
Generate a secret value
Next to the value field of a key that names a secret your app makes up, such as SESSION_SECRET or ENCRYPTION_KEY, select Generate a random value. The field becomes ${{ secret(32) }}, and the variable is stored as a secret. Keys that name something another party issues, such as an API token, get no offer.
Staging the same key again draws a new value. Anything that still uses the old value stops working once you deploy, so the button reads Generate a new value on a variable that already has one.
Import variables from an env file
- On a service's Variables tab, in the Shared variables panel or under Project variables, select Import variables.
- Choose From repository to read an example file such as
.env.examplefrom a service's repository, or Paste or upload to give the file's text. - Review the list. From a repository, each name is staged empty: the file's example values are shown as hints and never copied. From pasted or uploaded text, each variable keeps the value you gave it, and a name that looks like a password or key is stored as a secret. A value between double quotes, single quotes or backticks may span lines, so a PEM key pastes as written; a multi-line value shows its first line and a count, and its full text is on the variable's row once staged. A value with line breaks is never read as a placeholder. You can switch secret per row. A name that looks like a secret your app makes up, left empty or as a placeholder such as
changeme, is offered a generated value: select Generate all or untick generate per row. - Select the button at the foot of the dialog, for example Stage 5 variables.
A variable that already has a value is kept unless you tick it. Replacing one asks "Replace KEY? It already has a value." and the button reads Replace and stage.
Edit a service's variables as a .env file
On a service's Variables tab, select Edit as .env to change all of the service's own variables as KEY=value lines.
- Secrets stay sealed. A secret shows as a row of dots and keeps its value unless you type a new one on its line. A blank secret line also keeps it.
- Checked as you type. A duplicate key, a name that is not
UPPER_SNAKE_CASE, a line without=and a quote that never closes are listed under the text, and the button stays off until they are fixed. - Multi-line values are quoted. A value that spans lines is written between double quotes, with the line breaks as they are, as a PEM key is. Inside double quotes
\nis a line break,\"a quote and\\a backslash. Single quotes and backticks keep every character as typed.=and#need no escaping, and a#starts a comment only after a space outside quotes. - Read-only variables are listed apart. A variable that a
nebula.tomlsets, or that is a reference to another service, is not in the text. Naming it there is refused. - A diff before you stage. The dialog lists what the text adds, changes and removes, each on one line: a line break in a value shows as
\n. A new name that looks like a password or key is stored as a secret.
Stage N changes puts all of it in the environment's staged changes, to review and deploy like any other variable edit. Nothing is removed until you deploy.
Reveal a secret
Select Reveal on a secret's row. The value shows for 30 seconds, then hides again. Revealing is recorded as an audit event with the key and never the value. Hide closes it sooner.
Read the variables a service runs with
GET /api/v1/services/SERVICE_ID/resolved-variables?environmentId=ENVIRONMENT_ID returns the project, environment and service tiers merged, with every ${{ service.KEY }} reference resolved as a release resolves it. It needs the deployer role, because secret values come back unmasked, and it records each secret returned as revealed, by key and never by value.
curl "$NEBULA_URL/api/v1/services/SERVICE_ID/resolved-variables?environmentId=ENVIRONMENT_ID" \
-H "Authorization: Bearer $NEBULA_TOKEN"The response has items, sorted by key, each with key, value and secret, and revision, the configuration revision a release of that service in that environment carries. A host such as svc-api resolves only inside the cluster. nebula run starts a command on your machine with these values.
Variables that a nebula.toml sets
A variable that the service's nebula.toml names under [env], or that a project's nebula.toml writes, is read-only in the console and carries a badge naming the file and commit. Change it in the file and push, or remove the key from the file to edit it in the console.
Empty variables
An empty value is legal, and a deploy never waits for one. When a service has any, its Variables tab says so above the list and names every one: "5 variables are empty in Production: A, B, C, D, E. The service starts with them empty." Each such row carries an empty tag. An empty secret counts, without its value being opened.
Add an external resource
Use an external resource for a database, cache or SMTP server the cluster does not run.
- Right-click the canvas, select Shared variables, and under External resources select Add external resource.
- Enter a Name, choose the Kind (Postgres, MySQL, Redis, MongoDB, S3, SMTP or Other), add its variables, and under Link to services choose the services that need them.
The variables are sealed. Linked services receive them on their next deploy. A removed resource stops reaching them on their next deploy too.
Verify
After the deployment is healthy, the service runs with the new value. If a key is wrong or a reference does not resolve, the deployment fails with a message on the Deployments tab; see Deployments troubleshooting.
Next steps
- Create and connect a database: connection variables are references to the database's own.
- Release commands and files: mount a variable as a file.
- Variable expressions: where each expression is allowed.
Describe a project in Git
Declare a project's services, databases and connections in a root nebula.toml, point the project at the repository, and review the plan each push stages.
Configure processes
Add web, worker, cron and job processes to a service, set commands, replicas, resources and health checks, and stop, start or restart a service.