Can a dynamic provider depend on outputs from anot...
# general
m
Can a dynamic provider depend on outputs from another resource?
l
You can pass stack references to the constructor of a provider, and those can be resource outputs.
In general though, it's not a concept that works. You should think of resources as being created in the future, after your program runs (they're created by the Pulumi engine, from the model that your program creates). Providers are created now, so that your program can run. Ideally you shouldn't have a "now" thing depend on "future" things.
The Pulumi engine can handle creating resources inside an
apply()
so creating a provider inside an apply might also work (and that's what you're describing). But it's not a good idea even if it does work. It will lead to unnecessarily complicated code and it might have side effects.
m
I thought normal providers were themselves resources (eg. I can easily create a PostgreSQL provider that connects to a newly created database instance resource)
but I guess dynamic providers are different
l
They are resources, but special ones (like stacks are resources but special). It might be that it will all work, and you might want to give it a go. You might also consider breaking up your project so that your must-already-exist resources can be fully created before your depends-on-those-resources provider needs to be instantiated. And then use stack references, which will definitely work with dynamic resources.
m
ok, thanks 👍 I worked around it earlier by moving those inputs onto the resource instead of the provider, but it's useful to know
I was trying to mimic the postgresql provider, where eg connection info is passed once instead of every resource
but I guess I'd have to create a real provider for that