https://pulumi.com logo
e

echoing-activity-32278

12/13/2021, 2:34 PM
In one of my js file, I created a k8s provider with
Copy code
const provider = new k8s.Provider("k8s", {
  kubeconfig: stack.getOutput("kubeconfig"),
});
How can I reuse this provider in multiple js files? I’d expect some
pulumi.getResourceByName
stuff
b

billowy-army-68599

12/13/2021, 2:37 PM
Wouldn't exporting it and importing it be enough?
e

echoing-activity-32278

12/13/2021, 3:19 PM
I don’t really know how that is achieved in typescript.
e

echoing-activity-32278

12/13/2021, 3:29 PM
Yes. That’s one way to organize it
b

billowy-army-68599

12/13/2021, 3:36 PM
I would generally recommend using component resources instead of this approach, however. If you could describe a little more what you're ultimately trying to achieve, it would help me help you
e

echoing-activity-32278

12/13/2021, 3:37 PM
This approach looks goo.d
What’s the component approach?
e

echoing-activity-32278

12/13/2021, 3:43 PM
I feel these two approaches are basically the same. We define a resource and import it to the index.js. The former is more versatile because it has shared config.
@billowy-army-68599 I am interested in that, if there is a way to retrieve a resource based by name.
For example, res = pulumi.getResource(“some-defined-resource-name”)
b

billowy-army-68599

12/13/2021, 11:56 PM
@echoing-activity-32278 there isn't a way based on the state, but you can
get
a function that's in the cloud already using a data lookup
e

echoing-activity-32278

12/14/2021, 2:57 PM
Could you share with me an example code? Thanks
b

billowy-army-68599

12/14/2021, 3:46 PM
@echoing-activity-32278 what resource are you trying to look up?
e

echoing-activity-32278

12/14/2021, 3:47 PM
I am using azure native, I want to access whatever azure native resources I have applied through pulumi based on the unique name I specified.