Environment variables and secrets
Give your application its settings: plain variables in the project file, and secrets whose values stay outside your repository.
On this page
Your application reads its settings from environment variables. Values that are not secret go into the project file and are committed. Secrets, such as API keys and passwords, are only named in the project file: their values are kept by Tilizy, outside your repository, and you set them with the CLI.
Variables that are not secret
Write them under env in .tilizy/app.yaml:
env:
SITE_MODE: production
SEARCH_INDEX: main
To give one environment a different value, override it for that environment. The value for the environment wins:
environments:
staging:
env:
SITE_MODE: staging
A change takes effect with the next deploy of the environment.
Secrets
-
Declare the name in the project file. This says "my application needs this value" and nothing more:
secrets: - HASH_SALT - PAYMENT_API_KEY -
Set the value. Give only the name, and the command asks for the value without showing it on screen:
tilizy var:set PAYMENT_API_KEYIn a script, pass the value on standard input:
echo "$VALUE" | tilizy var:set PAYMENT_API_KEY --stdinThe form
tilizy var:set NAME=valuealso works, but it leaves the value in your shell history. -
Read what the command reports. A value reaches an environment with a deploy. For each environment, the command says whether a redeploy has started or whether the value is still waiting, and prints the command that applies it.
Which environments see a secret
Every secret has a scope. Choose it with --scope when you set the value.
| Scope | Meaning | Use it for |
|---|---|---|
shared | One value for every environment. This is the default. | Keys that are tied to the data, such as a hash salt. A staging database copied from live cannot be read without the live value. |
per_env | The value belongs to one environment. The value of live never reaches another environment. | Anything that signs in to another company's system: a payment key, a mail password. |
generated | Tilizy creates a fresh value for each environment. | Keys that no person needs to know. |
Set a secret for one environment by naming the environment:
tilizy var:set PAYMENT_API_KEY --scope per_env --prod
tilizy var:set PAYMENT_API_KEY --scope per_env -e staging
If staging has no value of its own for a per_env secret, it gets nothing, and its deploy fails with a message that names the secret. It never falls back to the value of live.
List, read and remove
List the secrets of the project. The output shows each name, its scope and whether a value is set. It never shows the value:
tilizy var:list
Add --prod or -e <branch> to see what one environment holds.
Print one value. Only the value is written to standard output, so that a script can capture it:
tilizy var:get PAYMENT_API_KEY
Remove a secret:
tilizy var:rm PAYMENT_API_KEY
Note: On thevarcommands the long form of the environment flag is--env. On most other commands it is--environment. The short form-eworks on both.
Variables the platform sets
Tilizy passes your application what it needs to reach its services: the connection details of each service arrive as environment variables named after the service in capitals, for example DB_HOST and DB_PASSWORD. Variables that start with TILIZY_ come from the platform, for example TILIZY_DOMAINS, the list of your domains. Choose other names for your own variables.
Secrets on your own computer
The copy on your computer never needs the live values. Put local values in .tilizy/local/.env, one NAME=value per line. The folder .tilizy/local/ is not committed. See Run your website locally.
What can go wrong
- A new environment is refused.
tilizy app:createstops before it creates anything when the project file declares a secret that has no value. Set the value and run the command again. - The application does not see the new value. The value is waiting for a deploy. Deploy the environment, for example with
tilizy app:deploy -e staging. - A secret ends up in a log.
tilizy var:getprints the value. Do not run it where output is recorded, and prefer the prompt or--stdinoverNAME=valuewhen you set one. - A secret in the repository. Never write a secret under
env. That file is committed, and every copy of the repository then holds the value.
Next: The project file and Environments.