This question isn't really specific to typescript,...
# typescript
s
This question isn't really specific to typescript, but that's what i'm using for my project. I am looking for a way to either detect at runtime that a resource will be updated, or just create a dependent resource that will always replace when its source resource is updated. The former would be good enough, but the latter is what i'm trying to accomplish.
l
Hi Johnny, if you mean you want to encode a dependency between two resources in your program, would
dependsOn
achieve what you want?
s
based on my testing, that doesn't cause dependent resources to be replaced when upstream resource is updated. just affects order. is that not correct?
l
Ah I see -- when you say "source resource", you mean the actual cloud resource. So when that changes, you want Pulumi's state to be updated, is that right?
I don't believe there's a way to do what you want "in program" right now, though there is
pulumi refresh
, which instructs Pulumi to look at all cloud resources and update its state accordingly
s
not refresh, no. imagine 2 resources. i update some property of resource 1, causing pulumi to determine that resource needs to be updated. i'd like resource 2 in this case to be replaced, though none of its properties changed. does that make sense?
it would be enough if i could do something like:
Copy code
const resource1 = new aws.Resource("resource1", { property: value })
if (resource1.isDirty()) {
    // force resource2 to update
}
though i can't find any such runtime method to determine that resource1 is set to be updated
l
Hm indeed I'm not sure there's a way to do this neatly at present 🤔
s
neatly is not a requirement thankfully 🙂
i'm down to kludge
l
Well, currently I'm struggling to do it at all 😂
s
that's what i was worrying
l
I know for e.g.
pulumi.Command
there is
triggers
but that is specific to that resource
s
just gonna have to keep manually updating the description for the dependent resource. definitely introduces a heap of human error risk, but oh well
l
There is Pulumi Automation, but obviously that's a chunk of work
o
To force a replace (delete & recreate) I think you're looking for the replaceOnChanges resource option. There is a downside which is that some input to the dependent resource must depend on the first. Is it not possible to have Resource2's description be defined as an input property, derived from Resource1's outputs? Making these two resources concrete would be helpful, are they resources in AWS, elsewhere?
g
you could make some resources "reactive" with
intialize
method which is not properly documented here: https://github.com/pulumi/docs/issues/11432
s
@frial
replaceOnChanges
is definitely the surface area i'm looking to attack. but apart from doing something really heavy handed like sha-ing the entire configuration for
resourceA
and injecting the hash in to the description field for
resourceB
or whatever, there is no mechanism i can devise to ensure that the
replaceOnChanges
field i'm targeting updates if and only if
resourceA
will be created or updated
o
It would be helpful to make this example a bit more concrete - what is it we're trying to accomplish by destroying and recreating Resource B?
s
resourceA is an aws lambda, and resourceB is a lambda version. this is only an issue with
aws-native
as
aws
has
publish: true
directly on the lambda resource which works great. but with
aws-native
, the lambda and lambda version being 2 separate resources means it only publishes the initial version, then does not create a new version unless the version resource itself is updated, whereas i need a new version to be created every time any property of the lambda changes (an environment variable, say)
o
Ah, that makes sense - that seems like a bug in the AWS native provider and a weird quirk. So on the
aws_native.lambda.Function
you pass it in a changing zipFile or other code, but it is a separate
aws_native.lambda.Version
resource that creates a new instance using the current code of the lambda. Would you be able to switch to using the
aws
package's lambda function? It seems like it'll be better behaved. In the mean time I'll flag this issue with the providers team that owns AWS Native for them to create an issue.
@shy-whale-9556 I conferred with some folks on the team and we recommend using
aws.lambda.Function
instead of the AWS Native implementation, as it does what you want on handling version updates. The AWS Native provider implements the CloudControl & CloudFormation API from AWS, and in this case it results in a very hard to use set of resources.