What's the correct syntactic sugar for accessing C...
# typescript
o
What's the correct syntactic sugar for accessing Config variables that are not prefixed with <stackname>? I have the following config file contents:
Copy code
config:
  mystackname:SCHEMA:
    secure: qqqqq
  mystackname:SCHEMA_CONFIG: https://
  azure-native:location: westus2
  azure-native:subscriptionId: aaaaaa
  azure-native:tenantId: bbbbbb
  fluid:password:
    secure: ccccccc
  fluid:username: abc*<http://xyz.com|xyz.com>
A simple require() or get() can access the mystackname: prefixed values. What's the syntax for accessing the other variables?
Copy code
const config = new pulumi.Config()
const schema = config.require( 'SCHEMA' )

// the following don't work
const location = config.require( 'location' )
const location = config.require( 'azure-native:location' )
const location = config.require( 'azure-native.location' )
l
You create a config instance per prefix.
Copy code
const location = new pulumi.Config('azure-native").require("location");
o
thx!
A sample like that could be added to the Pulumi Config wiki page.
l
Yes, it's only in there as a few sentences, and in a specific context that does not seem to apply (but actually does):
If you are writing code that will be imported into a broader project, such as your own library of components, you should pass your library’s name to the constructor. This string is used as a namespace for all configuration keys. Similarly, if you want to access the config of another library, such as the config for a standard library like aws, you should also pass the library’s name to the constructor.
o
Ah. It's a Typescript-ism. Unfortunately I'm a Python programmer coming into a Typescript+Pulumi project. Never sure which patterns might be standards from one or the other language.
I know what namespacing looks like in Python but not so much in TS.
l
This isn't TS namespacing, it's specific to pulumi.Config's implementation.
Which is why I say that this is a specific context (a library has a namespace). But in fact there's no need for it to be a library: if you want configuration for your firewall and for your ACLs in the same config file, you can add a call to
new pulumi.Config('acl')
and
new pulumi.Config('firewall')
, and it'll get values from those namespaces. Nothing to do with libraries...
The docs are unnecessarily-specific.
o
Thanks. And I recognize the challenge of maintaining language generic documentation while also trying to support language & context specific queries from newbies like me. Always appreciate your help.
👍 1