New Feature: Env Variables in fly.toml

Howdy folks. Starting today you can add environment variables to your fly.toml file:

  LOG_LEVEL = "debug"
  RAILS_ENV = "production"
  S3_BUCKET = "my-app-production"


  • Variable names are passed to your app as-is, so make sure you get your casing right.
  • Variable names cannot begin with FLY_
  • Values must be strings
  • Secrets take priority if both a secret and env variable have the same name
  • Env variables are NOT encrypted… please use secrets for sensitive data :wink:

This is awesome, so many times we continued to set our secrets because we were u sure of their values :joy:.


@michael this is great but unfortunately it’s limited if you want to use the same fly.toml file for multiple environments.

It would be great if we could have multiple environments in the same file.

We’re working through how best to support multiple environments. Do you like to have environment variables in your config file generally? Or would you rather set them with our CLI (like flyctl secrets but less secret)?

For basic flags and configs, we like to have the environment variables in the config file, and for api keys / key pairs / secrets we would set them using the CLI.

Does using --env with deploy override the [env] section from fly.toml?

In my fly.toml I have

  HOST = ""

and that used to work fine. However, after I added --env GIT_SHA="..." to the deploy command, HOST seems to no longer be set. Is that expected?

That’s a bug in the CLI that we’re tracking here - Make sure ENV in the config is not cleared by setting `-e` by sudhirj · Pull Request #582 · superfly/flyctl · GitHub

Expected behaviour is that env vars passed should override the ones in the toml with the same name, but should not disable them as a whole.

1 Like