https://pulumi.com logo
#golang
Title
# golang
q

quick-king-51158

04/25/2023, 6:25 PM
can i set env vars during runtime? setting GOOGLE_CREDENTIALS for gcp provider for example doesn’t seem to work
l

limited-rainbow-51650

04/25/2023, 6:28 PM
@quick-king-51158 this should definitely work. The docs explain all the settings you can have, also via env variables. https://www.pulumi.com/registry/packages/gcp/installation-configuration/ If you have a reproducible case where it indeed doesn’t work, please create a Github issue and attach the setup to reproduce.
q

quick-king-51158

04/25/2023, 6:28 PM
yes, if i set in the shell before pulumi up, it works
but i’d like to set it programatically in go, with os.Setenv before i call pulumi.Run
l

limited-rainbow-51650

04/25/2023, 6:32 PM
That won’t work unfortunately. Due to the architecture of Pulumi, our CLI, the language runtime and all the providers need access to these environment variables. If you set it in Go (which is the language host at that moment), you only have these available there and these aren’t propagated to the CLI/engine and providers.
q

quick-king-51158

04/25/2023, 6:35 PM
ok, thanks. and can i configure the provider from code?
l

limited-rainbow-51650

04/25/2023, 6:38 PM
You have the option to set it as stack configuration when using the default provider, or as constructor arguments to an explicit provider object. Keep in mind though, that the more you hardcode, the less flexible it can be in a team context.
q

quick-king-51158

04/25/2023, 6:40 PM
ok, thanks
a

adventurous-apartment-93389

04/26/2023, 7:50 AM
have a look here, one of our best practices is to use multiple service accounts with least privilege, this code gets a access token and sets a provider up with those credentials - the caller needs "service account user" permissions to assume the service account however. https://github.com/garybowers/google-cloud-pulumi/blob/garyb/defaults/go/blueprints/gke-multicluster-gateway/main.go
q

quick-king-51158

04/26/2023, 8:00 AM
thanks, i will take a look into this