Hi! Is it possible to to trigger an update on a re...
# typescript
g
Hi! Is it possible to to trigger an update on a resource if a dependency changes? For example:
Copy code
const basic1 = new BasicResource("basic1", { value: "value1" })
const basic2 = new BasicResource("basic2", { value: "value2" }, { dependsOn: [basic1] })
I'm working on a dynamic resource and I was hoping to be able to run an update on
basic2
when the value of
basic1
changes. The use case I'm trying to address is rebuilding a search engine index if a facet value changes.
c
Yep you can establish an explicit dependency the way you have it with the use of
dependsOn
. (EDIT: assuming
basic1
changes somehow in order to trigger a change on its dependents.) The other way, if you are interested (and slightly complicated), is to pass some input, that changes based on
basic1
changing, to
basic2
that you can then use in the
diff
function of
basic2
to compare and see if the value has changed. I forget the order of the
DynamicResource
interface functions being called but you might find https://www.pulumi.com/blog/dynamic-providers/ helpful.
g
Thanks @clever-sunset-76585! It looks like the
check
method is called every time but there doesn't seem to be any reference to the depend. I must be missing something small.
That was my basic sample test. The console logs are a bit messy (likey because of the serialization happening). I was hoping to be able to run
pulumi up
. Then, update the value in
basic1
to
value2
and have that trigger the
diff
method of the
basic2
resources on the next
pulumi up
.
I'm also a brand new Pulumi user so I might be missing something basic.
It sounds like the simplest solution would be what you suggested and output something like a
requiresRestart
property that I could use as an input to the other resource.
c
It looks like the 
check
 method is called every time but there doesn’t seem to be any reference to the depend
Yeah
check
is used to validate inputs and return errors if needed to stop execution. You can read more about the various interface functions here, in case you haven’t come across this doc already: https://www.pulumi.com/docs/intro/concepts/programming-model/#check-olds-news
diff
is where you can return an object that indicates whether a replacement/update is required based on some input changing.
t sounds like the simplest solution would be what you suggested and output something like a 
requiresRestart
 property that I could use as an input to the other resource.
While using a boolean might work the first time (going from
false
->
true
, it can only have one of two states. You could use some string output from
basic1
that changes over time based on something else, which in turn could be used within the
diff
function to compare old inputs with new inputs and therefore perform an update/replacement.
Basically, the object that you return from the
diff
function determines which function the engine will call next. That is, if it should call the
delete
,
update
or
create
function of your dynamic provider.
👍 1