Description
Is your feature request related to a problem? Please describe.
Using environment variables in netlify.toml is not supported. Firstly, I find this to be a prominent shortcoming of the Netlify service, and if this were supported, this feature request would be unnecessary.
Some of my site's settings here are either secrets that I don't want in version control or benefit from dynamic assignments, so I use a workaround similar to the last option in https://docs.netlify.com/configure-builds/file-based-configuration/#inject-environment-variable-values
I began with sed replacement as Netlify suggested, but soon found it error prone and unwieldy, so I made a Node script: https://gist.github.com/bdefore/29a40a1028cf414fe51c1b39686765bc (in this file I populate the contents of required
and optional
with variables relevant to my site).
My configuration for command
in netlify.toml is: CI= yarn run build:replace && CI= yarn run build
and this works well during deployments, replacing placeholders with those specified in site configuration.
Where this becomes problematic is when I want to run Netlify Dev, which would rely on a replaced version of netlify.toml. I currently must run the rewrite script locally once before starting Netlify Dev: "build:replace:dev": "netlify dev:exec babel-node rewrite_netlify_vars.js"
, in particular because I rely on netlify.toml for [redirects]
blocks even in local development.
This replaces placeholder values in netlify.toml but since the file is managed by git, there is a risk of accidentally committing the changes and leaking secrets into version control.
Describe the solution you'd like
I'd like to have a .gitignore'd netlify.development.toml which is the output of a replace run, and be able to run netlify dev --toml netlify.development.toml
.
Alternatively, the [dev]
block could support a localOverrides
that is a path to another toml that is internally merged before Netlify Dev runs.
Describe alternatives you've considered
- Look for relevant Netlify plugins
- Remain careful and don't commit replaced netlify.toml
- Write a script that watches Netlify Dev terminating and restores the file.
- Work off of a long-living
local
branch that is regularly rebased withmaster
and is blocked from being pushed
Additional context
Related discussion that proposes ability to override toml values individually: #1265
Related discussion about supporting environment variables in netlify.toml: #457
Can you submit a pull request?
Possibly
Pull requests are welcome! If you would like to help us add this feature, please check our
contributions guidelines.