hi guys, i am in the process of creating a compone...
# general
b
hi guys, i am in the process of creating a componentResouce using go, in this component, i need to use multiple providers, i understand the fact that we can pass the provider map, i am assume the map key is the package name? however for our setup, we have 2 roles for managing aws resource, one for iam, another one for everything else. so how can i pass 2 aws provider to the provider map so that the child can use the appropriate provider?
Copy code
map[string]pulumi.ProviderResource{
					"aws":        iamProvider,
					"kubernetes": k8sProvider,
				}
l
I am not sure if there are neater options, but in this case the simplest thing to do might be to pass the two AWS providers as explicit inputs to your component resource. Something like:
Copy code
type MyComponentArgs struct {
  iamProvider aws.Provider
  k8sProvider aws.Provider
} 

type MyComponent struct {
  pulumi.ResourceState
}

func NewMyComponent(ctx *pulumi.Context, name string, args *MyComponentArgs, opts ...pulumi.ResourceOption) (*MyComponent, error) {
  myComponent := &MyComponent{}
  err := ctx.RegisterComponentResource("pkg:index:MyComponent", name, myComponent, opts)
  ...
}
Then, when you create specific sub-resources, pass
pulumi.Provider(args.iamProvider
or
pulumi.Provider(args.k8sProvider)
as you please, for instance.
b
thanks, thats what i am doing right now, i am hoping there will be a better option 🙂
l
FWIW I've done this in TypeScript (not a Go expert) and it generally works quite well, but keen to hear how you get on 🙂