I think you can use `runtime.allConfig()`
# general
s
I think you can use
runtime.allConfig()
e
is runtime a package?
What would that look like?
s
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
How would I use
allConfig
to get the list key-value pairs, or the list of keys?
s
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
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
Right - something new would need to be added to
Config
to allow for that
e
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
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
So how does one iterate over the allConfig?
I tried the
for (const key of allConfig) {
above but it fails
w
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
Sorry, I gave the wrong specifier there,
in
rather than
of
.
g
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.