How does Pulumi decide which provider to use in th...
# general
l
How does Pulumi decide which provider to use in the
providers
map (in the opt object)?
Is it just based on resource type and provider type? Is it possible, for example, to pass in multiple AWS providers with different regions, credentials etc., and somehow choose the right one for each resource?
e
It's a legacy design that
providers
is a map 😞 The dotnet sdk for example it's just a list. Choosing a provider from there is just a case of looking for the provider with a matching package. So no you can't have multiple AWS providers in the one map/list.
l
Fair enough. How does it decide which package a resource belongs to? Could that logic be abused by something simple like decorators or even
import * as aws-uswest2 from "@pulumi/pulumi-aws
...?
e
It's by the type custom resources declare in their constructor. eg. https://github.com/pulumi/pulumi-aws/blob/master/sdk/nodejs/accessanalyzer/analyzer.ts#L59 states that this is the "aws" package, the "accessanalyzer/analyzer" module, and the "Analyzer" type. So no it's not easily abused. Sounds like you've got an interesting use case though, worth opening an issue at github we can give it a proper think over how to help with what your doing.
l
It could be done by ComponentResources though. You'd have to stick the target env name in the first part of the component resource's URN, but having
myproj-prod:x:y:z:foo
map to provider myproj-prod which is actually an AWS provider hooked up to us-west-2 would be fine.. if it works.
Might have to put logic in the base class to set the aws provider be the myproj-prod provider though.. and that's not hard.
e
Well if your doing logic in ComponentResources then you can just edit the providers list that it passes around to child resources. Changing the package of the ComponentResource won't actually do anything because ComponentResources don't use providers (they aren't real cloud resources)
l
True.