https://pulumi.com logo
Title
f

full-artist-27215

10/25/2021, 3:44 PM
Is it possible to access values from
pulumi.Config()
inside a Dynamic Provider implementation? I've tried this in both Python and TypeScript, and whenever I try to get something from the config, I get this error:
error: Program run without the Pulumi engine available; re-run using the `pulumi` CLI
b

billowy-army-68599

10/25/2021, 3:46 PM
i don't think it's possible at the moment, you'd need to set a property on the provider and then use
pulumi.Config
in your main program and pass it in from there
f

full-artist-27215

10/25/2021, 3:46 PM
ah, I see... thanks!
Is this documented somewhere and I missed it?
b

billowy-army-68599

10/25/2021, 3:48 PM
i'll try dig up the issue, but it's there somewhere
in general it's best not to have config in providers or components like this anyway
f

full-artist-27215

10/25/2021, 3:50 PM
how so?
b

billowy-army-68599

10/25/2021, 5:07 PM
providers and components are intended to be reused, if you're adding config, you're making that less possible
example:
export interface MyAppArgs {
  configItem: string
}

export interface MyApp {
  // do some stuff here
  const foo= args.configItem 
}
if you follow this pattern, you can let the user decided if they want to set the config
if not, you're forcing the user to use config
r

red-match-15116

10/25/2021, 5:10 PM
Amongst probably other reasons, your component should have explicit dependencies defined as part of their inputs, having a dependency on config is hidden away in the implementation and reliant on global state. The reason that this doesn’t work though is probably because dynamic providers are serialized into state, and config is not available at the time of serialization. Also, even if it were, you would only have the config value at the time of serialization stored in state.
👍 1
b

billowy-army-68599

10/25/2021, 5:14 PM
Komal with the much better explanation than i could hope to give 😄
❤️ 1
f

full-artist-27215

10/25/2021, 5:21 PM
Gotcha, thanks for the explanation.
Sorry to revive a thread, but I must have a bad mental model of the under-the-hood differences between dynamic providers and "normal" providers. I don't have to specify, say, my
aws:region
on every AWS resource I want to create. What's the distinction that I'm missing?
(Thanks in advance 🙇)
r

red-match-15116

10/26/2021, 3:57 PM
For aws I believe the region is a property set on the default provider
So the provider object being passed around to each resource contains the region. It all just happens sort of magically when you don’t use an explicit provider object
f

full-artist-27215

10/26/2021, 4:33 PM
Right, but I still don't need to set the region as an input to any specific resource. Is it different with a dynamic provider because the provider is (or at least seems to be) bundled up with the resource itself?
r

red-match-15116

10/26/2021, 5:10 PM
Right, but I still don’t need to set the region as an input to any specific resource.
But you do need to set it as an input to the provider which itself is an input to each resource.
f

full-artist-27215

10/26/2021, 10:13 PM
So... my particular dynamic resource needs to access the configuration information from another provider (to be concrete, I need to work around a hole in the Vault provider to create a particular resource in Vault, so I want to use the same Vault connection parameters that the rest of my project is using). However, it doesn't even appear that I can call, say,
pulumi.Config().require("vault:address")
anywhere in my program (dynamic resource implementation or otherwise), without it trying to look for it in
my-project:vault:address
. Is there a better way to try and approach this? Do I need to eschew the default Vault provider entirely, specify the relevant configuration parameters in my project's own namespace, create the provider in my code, and then manually pass that provider into every resource?
r

red-match-15116

10/26/2021, 11:09 PM
Have you tried
pulumi.Config("vault").require("address")
?
Like to access “aws:region” you would do
cfg = pulumi.Config("aws")
region = cfg.require("region")
So I wonder if the namespaced config is what you’re missing
f

full-artist-27215

10/27/2021, 2:04 PM
Wow, I'm not sure how I overlooked that; this is exactly what I need! Thanks!
1