https://pulumi.com logo
#python
Title
a

able-airport-31667

07/08/2023, 12:25 PM
Hi. I'm learning about
pulumi dynamic resource provider
. Is there any chance to pass
pulumi.Resource
as an
Input
parameter to another
pulumi.Resource
? Example (Foo resource passed as an Input to Bar resource inputs):
Copy code
# Foo Resource
class Foo(Resource):
    foo_out_1: Output[str]
    foo_out_2: Output[str]
    foo_out_3: Output[str]

    def __init__(self, name: str, props: FooInputs, opts=None) -> None:
        super().__init__(FooProvider(),
                         name=name,
                         props={
                             **vars(props),
                         },
                         opts=opts)
        
        

# Bar Resource     
class BarInputs:
    name: Input[str]
    foo_resource: Input[Foo]  #<-- Passed Foo resource as an Input 


class BarProvider(ResourceProvider):
    def create(self, args):
        print(args['foo_resource'])
        # Expected output:
        # {
        #     "foo_out_1": "value1",
        #     "foo_out_2": "value2",
        #     "foo_out_3": "value3",
        # }
b

billowy-engine-58246

07/09/2023, 1:42 PM
Hi Piotr! Fancy seeing you here! Normally, you’d pass an ID so the chain of dependencies is very clear. This is also how most Pulumi objects would do it. Can you let me know why you would want to pass the entire object?
a

able-airport-31667

07/12/2023, 8:07 PM
Hi @billowy-engine-58246. Lets say my
Bar
Resource needs 3 parameters related to
Foo
resource. Then I think it will be more user friendly to write:
Copy code
Bar(
    name="my_resource_name",
    foo_object=foo_resource,
)
rather than
Copy code
Bar(
    name="my_resource_name",
    foo_input_1=foo_resource.foo_out_1,
    foo_input_2=foo_resource.foo_out_2,
    foo_input_3=foo_resource.foo_out_3,
)
Maybe I am wrong and this is an anti pattern? What are a good practices here?