Is there a way (without a new component resource) ...
# general
g
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:
Copy code
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
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:
Copy code
const baseOpts = { parent: someOtherResource };
...
const resX = new Role("resX", { /* ... */, baseOpts);
const resY = new Bucket("resY", { /* ... */, { ...baseOpts, protect: true });
b
What’s the opposition to using a component?
g
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:
Copy code
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.