How to use gcloud runtime config from the app engine or kubernetes platforms?

4/26/2018

I have some shared code that I deploy to firebase functions but also the app engine and kubernetes platforms via a docker image.

For functions there is functions.config() to get to the gcloud runtime config, where I store some api keys that differ between development and production environments.

This is convenient as it keeps you from having to copy the same env variables over multiple configuration files, like I would otherwise do with app.yaml or the kubernetes deployment configs.

Is there an easy way to get to the runtime config from these platforms? There is a rest api but I assume it is meant for admin tasks. Using it in my app would mean having to deal with async calls and authentication before executing the code that depends on the config, so I don't think that's a viable option.

-- Thijs Koerselman
google-app-engine
google-cloud-platform
google-kubernetes-engine

1 Answer

5/15/2018

You could definitively go for RuntimeConfig [1] by setting variable at project level and then retrieve them with projects.configs.get method either trough API or Gcloud command[2]. You could do it from the platform itself but you must authenticate yourself first.

Requires one of the following OAuth scopes: https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/cloudruntimeconfig

[1] https://cloud.google.com/deployment-manager/runtime-configurator/reference/rest/v1beta1/projects.configs

[2] https://cloud.google.com/deployment-manager/runtime-configurator/set-and-get-variables

-- Alessio
Source: StackOverflow