I wrote a Netlify Build Plugin over the weekend to automatically fetch a config value from Heroku (in this case a
DATABASE_URL connection string) to be used in conjunction with Prisma and RedwoodJS
I followed the pattern used by the existing netlify-plugin-contextual-env here:
and did essentially the same:
But – while the env is available during the build runtime (and I’ve confirmed this) it is not available to functions that rely on the
DATABASE_URL it sets.
I’ve tried with/without setting a value, seeing if the plugin will override, etc.
Note: my function does in fact work when normally setting ENV via Netlify dashboard UI as it finds the env.
And it sort of makes sense - it’s setting it during the “build process”.
But - is there any way to set and save a env setting during the build runtime that is available to functions?
This concept isn’t limited to database urls – I might refresh an API token used by a 3rd party api in a function and want to set it automatically. Lots and lots of use cases.
My only thought is to use the NetlifyAPI and the updateSite to set envs, but I really really really do not want to do that for many many many reasons re: having peoples’ access tokens and the responsibilities there given the power of the NetlifyAPI once you obtain one. See my post on RedwoodJS about that:
Any ideas how to set the env for functions? Did I miss something?