is it possible to run a code block based on `depen...
# python
s
is it possible to run a code block based on
dependsOn
the way i can use
dependsOn
for funcitons that accept
ResourceOptions
?
h
i would love to also know this. Currently, I just pick an Output on the resource the resolves at the right time and use the
.apply()
to call that code
s
i'm still pretty new to pulumi, would you mind providing an example of what you just described?
Outputs are the future/promise/deferred/etc of pulumi
.apply()
is the basic "call this function when you have a value"
it gets passed the resolved value, but technically it doesn't have to use it
so i've used it in the past like:
Copy code
wait_on = box.id 
dev = pulumi_tailscale.get_device_output(
    hostname=wait_on.apply(lambda _: name),
    wait_for="20m",
    opts=InvokeOptions(...),
)
i'm in azure, so
box.id
is generally the azure-assigned resource ID that only resolves after the resource has been created
as opposed to something like
.urn
, which every pulumi resource has, regardless of provider, but resolves as soon as pulumi starts creating the resource
s
awesome, thanks for the details!
h
some caveats: • If you're just doing data transformations (eg, taking results from one resource, doing string operations, and handing it to a pulumi resource or function), you can just use
.apply()
or
.all()
and return the values you're producing. Those methods produce an Output that can be handed to pretty much anything pulumi. • I think the functions within
.apply()
might not be called, depending on the specifics. Using the value (eg,
pulumi.export()
) will ensure it'll definitely be called when the state is applied, but I expect the specifics are .... fuzzy • The functions passed to `.apply()`/etc might be called multiple times, eg during the preview and then applying. Again, the specifics are probably complicated.