When I create a custom `pulumi.ComponentResource` ...
# typescript
l
When I create a custom
pulumi.ComponentResource
subclass, how can I define the
opts
so I have the same VSCode IntelliSense as for the default Pulumi libs. Example could be handy. 😉
b
There’s an exported interface for the opts
l
In this case, are you referring to the
ClusterOptions
interface?
b
‘pulumi.ComponentResourceOptions’ Set that as the type for your opts in the constructor for your component class
c
CompomentResourceOptions
is used to pass some resource options to the Pulumi engine. I think Ringo is talking about components args with custom properties that are specific to the component only. If that's the case you can define a custom interface (similar to
ClusterOptions
from your example above) and have that as an argument of your constructor in addition to also accepting
ComponentResourceOptions
as a param as well. The latter will allow you to set things like
provider
,
parent
,
dependsOn
etc.
💯 1
r
I was wondering where to put some standard (like azure, kubernetes) providers when I build a
ComponentResource
that internally creates resources with those standard providers. I ended up putting them in the args as for some cases (e.g. cert-manager) I need both, azure and kubernetes providers and I want to have them defined explicitly, not using the ambient (default) ones. Is this the intended way or should I have some special
ComponentResourceOptions
that support more than one provider? For now I’m always passing providers explicitly but this might not be the case if I build some reusable library and people want to leverage their default providers.
c
@rhythmic-finland-36256 just noticed your question. I don’t think you need to put the providers inside your custom args. Just declare
ComponentResourceOptions
as one of the params of your component’s constructor and pass it there. Here’s an example:
Copy code
export class MyComponent extends pulumi.ComponentResource {
  constructor(args: MyComponentArgs, opts: pulumi.ComponentResourceOptions) {
  }
}
then you can use it as:
Copy code
new MyComponent({}, {
  providers:{
   "azure": azureProvider,
   "kubernetes": k8sProvider
  }
});
Is this what you are asking about?
r
Oh, nice. Thanks! I didn’t know there was also
providers
besides the single
provider
field. Does passing them as
ComponentResourceOptions
to a
ComponentResource
then automatically use them in all child resources without explicitly passing them to e.g. a
kubernetes.Deployment
?
b
It uses those providers if you parent all the resources to the class
{ parent: this }
c
@busy-umbrella-36067 is right. See https://www.pulumi.com/docs/intro/concepts/programming-model/#components. Definitely worth reading that whole page to make sure you are aware of all the good stuff Pulumi's programming model offers.
r
Thanks for that pointer. I’m sure I read that page some time ago but somehow missed that part with the
ComponentResourceOptions
providers list. Everything I wanted to know was already well documented. That docs really rock 💪