https://pulumi.com logo
Title
g

gorgeous-architect-28903

12/01/2022, 6:26 PM
Is there a way (without a new component resource) to just wrap some resources and have them inherit resource options? I have a couple of sets of basically unrelated resources, but that happen to share a common dependency. I’d love to just do something like:
WithResourceOptions([dependencyResource, providers], func() {
  ResourceOne(ctx, name, ...)
  ResourceTwo(ctx, name, ...)
})
And have them all automatically get the dependency without having to type it 5 times, or move them around in the tree. Kind of like registering a stack transformation, but not globally.
l

little-cartoon-10569

12/01/2022, 7:43 PM
You can use transformations. Or you can use a single opts template object, and customize it for specific resources when necessary.
The latter is a language-specific solution. It's probably the better option, for languages that make it easy. E.g. in typescript:
const baseOpts = { parent: someOtherResource };
...
const resX = new Role("resX", { /* ... */, baseOpts);
const resY = new Bucket("resY", { /* ... */, { ...baseOpts, protect: true });
b

billowy-army-68599

12/01/2022, 8:48 PM
What’s the opposition to using a component?
g

gorgeous-architect-28903

12/02/2022, 11:21 AM
Thanks for the suggestions. I did end up using a component in the end, just not in the way I usually do. I have a method now that creates an “empty” component resource instance with the options I want, and returns
pulumi.Parent(res)
-- so now I can do something like:
withCluster := withOpts([DependsOn(cluster), provider])
ResourceX(ctx, name, withCluster)
ResourceY(ctx, name, withCluster, anotherOption)
Which at least saves me a bit of typing, and lets me append additional options to the individual resources easily.