https://pulumi.com logo
#python
Title
# python
b

better-actor-92669

12/17/2019, 12:41 PM
Hi guys. Very simple question. I need to get the value of my gcp default region via pulumi config
Copy code
from pulumi import Config, export, get_project, get_stack, Output,\
    ResourceOptions

config = Config(None)

compute.Instance(...,
                 zone=config.get('gcp:region') + '-' +
                      zone_matcher.get(count + 1, 'a'),
                )
But it doesn't work, however in my stack's yaml file it is set up
Copy code
config:
  gcp:project: some-project
  gcp:region: europe-west3
When I do
config.require()
it says that 'some-projectgcpregion' is not setup, and this is correct since I only set up secrets on some-projects level. Gcp region is under config key.
Copy code
error: Missing required configuration variable 'some-project:gcp:region'
        please set a value using the command `pulumi config set some-project:gcp:region <value>`
How can I get the value of the project's default gcp:region?
w

white-balloon-205

12/17/2019, 3:11 PM
There is not currently any concept of “project’s default” configuration in Pulumi. All configuration must be specified on the stack, and default values can be provided in code if needed (which morally accomplishes being a project default - but it is specified in source code not in the project YAML).
b

better-actor-92669

12/17/2019, 3:15 PM
thank you @white-balloon-205. So I basically have to add additional value in stacks.yaml that will duplicate the gcp:region key? Something like this:
Copy code
config:
  gcp:project: some-project
  gcp:region: europe-west3
  some-project:gcp:region: europe-west3
But when I do
pulumi config set gcp:region europe-west-3
it just sets the same value
Copy code
config:
  gcp:region: europe-west3
@white-balloon-205, can you please comment on this? It seems a bit weird to duplicate values in the config, but if it is the only way now - I will do it of course.
g

gentle-diamond-70147

12/17/2019, 4:21 PM
you need to load the the config with the "gcp" namespace...
Copy code
gcp_config = pulumi.Config("gcp") # <----

instance = compute.Instance(...,
    zone=gcp_config.require("region"),
)
b

better-actor-92669

12/17/2019, 4:59 PM
@gentle-diamond-70147 that's amazing! Thank you so much! I can confirm that it works
👍 1
I am sorry, but I didn't realise it was a separate namespace, I am not that efficient with pulumi yet)
g

gentle-diamond-70147

12/17/2019, 5:41 PM
No need to apologize! I think we should handle this better - log a warning or maybe throw an error if you try to get a config value with
bag:key
. I'm not sure that's valid.
5 Views