https://pulumi.com logo
Title
l

limited-rainbow-51650

01/09/2020, 2:49 PM
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

busy-umbrella-36067

01/09/2020, 2:53 PM
There’s an exported interface for the opts
l

limited-rainbow-51650

01/09/2020, 2:58 PM
In this case, are you referring to the
ClusterOptions
interface?
b

busy-umbrella-36067

01/09/2020, 3:10 PM
‘pulumi.ComponentResourceOptions’ Set that as the type for your opts in the constructor for your component class
c

clever-sunset-76585

01/09/2020, 4:31 PM
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

rhythmic-finland-36256

01/13/2020, 10:02 AM
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

clever-sunset-76585

01/14/2020, 2:48 AM
@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:
export class MyComponent extends pulumi.ComponentResource {
  constructor(args: MyComponentArgs, opts: pulumi.ComponentResourceOptions) {
  }
}
then you can use it as:
new MyComponent({}, {
  providers:{
   "azure": azureProvider,
   "kubernetes": k8sProvider
  }
});
Is this what you are asking about?
r

rhythmic-finland-36256

01/14/2020, 8:42 AM
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

busy-umbrella-36067

01/14/2020, 3:23 PM
It uses those providers if you parent all the resources to the class
{ parent: this }
c

clever-sunset-76585

01/14/2020, 4:27 PM
@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

rhythmic-finland-36256

01/14/2020, 8:03 PM
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 💪