How to interpolate environment variables within netlify.toml config
It's not supported, but Netlify suggest a work-around in their documentation (https://www.netlify.com/docs/netlify-toml-reference):
Using Environment Variables directly as values ($VARIABLENAME) in your netlify.toml file is not supported. However, the following workflow can be used to substitute values based on environment variables in the file, assuming you are only trying to change headers or redirects. The rest of the file is read BEFORE your build - but those sections are read AFTER the build process.
- Add a placeholder like API_KEY_PLACEHOLDER somewhere in the netlify.toml redirects or headers sections.
- Create an Build Environment Variable, for example API_KEY, with the desired value. You can do this in the toml file or in our UI in the Build and Deploy Settings section of your configuration. You might use the latter to keep sensitive values out of your repository.
- Add a command like this one to your build command: sed -i s/API_KEY_PLACEHOLDER/$API_KEY/g netlify.toml && normal build command.