https://pulumi.com logo
#general
Title
# general
s

stocky-spoon-28903

11/08/2018, 10:34 PM
I think you can use
runtime.allConfig()
e

early-musician-41645

11/08/2018, 10:36 PM
is runtime a package?
What would that look like?
s

stocky-spoon-28903

11/08/2018, 10:38 PM
Copy code
import * as pulumi from "@pulumi/pulumi"

const allConfig = pulumi.runtime.allConfig();
That’s what the Config class is implemented in terms of, so it’s coming from the same source
That said, perhaps you have identified a need for something better in the Config object to handle this kind of situation, (cc @white-balloon-205)
e

early-musician-41645

11/08/2018, 10:42 PM
How would I use
allConfig
to get the list key-value pairs, or the list of keys?
s

stocky-spoon-28903

11/08/2018, 10:43 PM
allConfig
at that point would be a string dictionary, so you can do:
Copy code
for (const key of allConfig) {
    const value = allConfig[key];

    // do something with value
}
You could also filter the keys etc using the higher order functions and then map them onto a new collection depending on what you’re aiming to do
e

early-musician-41645

11/08/2018, 10:47 PM
okay, that works. But it doesn't really let me get config in only a single namespace
I'd have to do further string comparison and then splitting to get the keys in a namespace
s

stocky-spoon-28903

11/08/2018, 10:48 PM
Right - something new would need to be added to
Config
to allow for that
e

early-musician-41645

11/08/2018, 10:50 PM
Okay, I'm unblocked for now. Thanks
Do you know why this is failing?
Copy code
pulumi.runtime.allConfig().forEach((value: string, key: string) => {
  console.log(key + ": " + value);
});
Copy code
error: Running program '/home/tsi.lan/eshamay/git/mustang/sdp-mustang-terraform/pulumi/mustang-tas-services' failed with an unhandled exception:
    error: TSError: ⨯ Unable to compile TypeScript:
    index.ts(23,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
w

white-balloon-205

11/08/2018, 11:00 PM
allConfig() returns an object, not an array. So you can't use
Array#forEach
on it.
Copy code
export declare function allConfig(): {
    [key: string]: string;
};
e

early-musician-41645

11/08/2018, 11:02 PM
So how does one iterate over the allConfig?
I tried the
for (const key of allConfig) {
above but it fails
w

white-balloon-205

11/08/2018, 11:03 PM
Copy code
const allConfig = pulumi.runtime.allConfig();
Object.keys(allConfig).forEach(key  => {
    console.log(key + ": " + allConfig[key]);
});
or:
Copy code
const allConfig = pulumi.runtime.allConfig();
for (const key in allConfig) {
    console.log(key + ": " + allConfig[key]);
}
s

stocky-spoon-28903

11/08/2018, 11:29 PM
Sorry, I gave the wrong specifier there,
in
rather than
of
.
g

glamorous-printer-66548

11/09/2018, 12:47 AM
You can also use :
Copy code
Object.entries(allConfig).forEach(([key, value]) => {
console.log(`${key}: ${value}`)
})
at least that’s what It’d personally use haha.
you probably have to create a
tsconfig.json
and set
Copy code
{
  "compilerOptions": {
    "target": "es2017"
  }
}
to let typescript know that
Object.entries
exists. And you should use node 8 or higher.