Set a value in render.yaml for production ONLY

Is it possible to set a value in render.yaml that will set the environment variable, but only on production and not preview environments?

I thought that this would do that

      - key: MY_ENV
        value: "some_value"
        sync: false

But it results in this warning

services[0].envVars[8]
cannot simultaneously specify fields value and sync

Not that this is not equivalent:

      - key: MY_ENV
        value: "some_value"
        previewValue: null

Because then in preview environments MY_ENV is set to "" which is different than not being set.

Hi @jason_felt, right now there is no way to specify production-only environment variables in your render.yaml. One possible workaround I can think of is to set them like you have in the second example, then programmatically ignore the environment variable in your code if it is set to "".

1 Like

Thanks for the confirmation. It would be nice if there was a cleaner way to do this.