Setting secrets before the first deployment does nothing

If you use fly secrets set before the first deployment the secrets won’t be set.

The cli says Secrets are staged for the first deployment but after i tried to deploy secrets were not added.

Strange. They are set (or at least they were). Since I’ve done that, staging secrets and then deploying. So unless a recent bug has broken that behaviour, they should be there …

Can you confirm how you are accessing them? They should be environment variables so e.g for Node process.env.NAME. The other possibility is with a type error/conversion so e.g a number being converted to a string, and so not being correctly passed to the application. But that’s a total guess!

I have the same problem. I’m trying to fetch an env var in my config.exs using

  dsn: System.fetch_env!("SENTRY_DSN"),

and I set it for fly like so :point_down:

fly secrets set SENTRY_DSN=my_sentry_dsn

but then after I run fly deploy I get

-----> Installing Hex
** (ArgumentError) could not fetch environment variable "SENTRY_DSN" because it is not set
    (elixir 1.13.3) lib/system.ex:698: System.fetch_env!/1
    (stdlib 3.15) erl_eval.erl:685: :erl_eval.do_apply/6
    (stdlib 3.15) erl_eval.erl:893: :erl_eval.expr_list/6
    (stdlib 3.15) erl_eval.erl:237: :erl_eval.expr/5
    (stdlib 3.15) erl_eval.erl:229: :erl_eval.expr/5
    (stdlib 3.15) erl_eval.erl:893: :erl_eval.expr_list/6
    (stdlib 3.15) erl_eval.erl:408: :erl_eval.expr/5
-----> Installing rebar
** (ArgumentError) could not fetch environment variable "SENTRY_DSN" because it is not set
    (elixir 1.13.3) lib/system.ex:698: System.fetch_env!/1
    (stdlib 3.15) erl_eval.erl:685: :erl_eval.do_apply/6
    (stdlib 3.15) erl_eval.erl:893: :erl_eval.expr_list/6
    (stdlib 3.15) erl_eval.erl:237: :erl_eval.expr/5
    (stdlib 3.15) erl_eval.erl:229: :erl_eval.expr/5
    (stdlib 3.15) erl_eval.erl:893: :erl_eval.expr_list/6
    (stdlib 3.15) erl_eval.erl:408: :erl_eval.expr/5
-----> Fetching app dependencies with mix
** (ArgumentError) could not fetch environment variable "SENTRY_DSN" because it is not set

Can you confirm how you are accessing them?

I know secrets were not set because application failed because of missing env var and i checked the secrets page in dashboard.

Also, this problem may also be caused by changing region, before setting the secrets i also changed region of deployment

Also, this problem may also be caused by changing region, before setting the secrets i also changed region of deployment.

I did not change the region but I still get it. I’ll try to delete apps and then re-try. :smiley:

Env vars configured with flyctl secrets command are not available to builds. Check out how to set env vars for build

2 Likes

Ah, so there may be two different issues here. As @klucass says, those Fly secrets are available at run-time but the @andreyuhai output looks like build-time. Hence getting that error.

As for @morse it’s not clear if you are also getting an error at build-time or whether your error is at run-time. Secrets are globally available (you don’t need to set them per region) so it sounds like a build error for you too. But yes, certainly try again and see what happens.