Currently, when I create a new PR and a corresponding preview environment is generated, all of my prod env vars are automatically copied over to the preview env
This means I have to remember to go in and update each of them to, for example, use our testing db rather than the prod db and more.
Obviously, this is not desirable and also not sustainable. Worse, there is the risk that I or someone else will forget to change this and then make an update that impacts prod.
Is there a recommended way to set up env vars in render to prevent this? Ideally, I would like for it to work in Vercel, where you can have separate env vars for each environment.
Thanks for that info. However, doesn’t that mean I would have to include an env var such as a database url string directly in my repo? Or am I not understanding. I definitely cannot include api keys and database urls in the checked in code, even for preview envs.
Thanks for that info. Do you have an ETA for when this might be supported? I am at this point unfortunately actively looking for hosting alternatives in part due to this issue.
Thanks! I read through the workarounds, and maybe I missed it, but I did not see way to at least prevent env vars from being copied over. Also, I tried using the value / previewValue option and was not able to get that to work, ie getting a different value for previews.
The situation here is that it is currently not possible to exclude the copying of envGroup values to your PR (Pull Request) environment instances. This can only be achieved using the “sync: false” flag if the environment variables were individually set in your .yaml file, as explained in the workaround.
The suggested workaround, in this case, would be to create two environment groups that are carried over to each environment. However, you can implement logic in your code that retrieves the variables from one group or the other, depending on the environment you want your code to run on (e.g., prod/dev). You can also check if the current instance is a PR environment using the “IS_PULL_REQUEST” environment variable.