Is there a way to force a resource to be replaced ...
# general
w
Is there a way to force a resource to be replaced if the properties of a resource that it indirectly links to updates? For example, in AWS I have an elasticache replication group. One of its properties is subnetGroupName. If I change the name of the group, then sure, it triggers a replace. But if I remove one of the subnets in that group - well the name doesn't change, and so I can't trigger a replacement of the cache based on that change (which is necessary, because you can't remove a subnet from an in-use group, so the entire EC replication group needs to be replaced). Another example is - if I change the inline userdata for an EC2 instance, I can trigger a replace. But if that userdata is pulling in info from the parameter store, and I change that info, I want to trigger the instance to be replaced. So...kind of a combination of
replaceOnChanges
and
dependsOn
? Like, replace this thing when this other thing changes.
For the subnet group one, I though oh maybe I can add a replaceOnChanges for subnetIds, which would then change the guid portion of the name automatically - but strangely that didn't trigger a replacement of the group when changing the subnets, even with that. I tried replaceOnChanges with just a wildcard, which is weirdly giving me the message
+- ├─ aws:elasticache:SubnetGroup    graph-qa-redis-subnet   replace   [diff: ~#initerror]
Also, this wouldn't work for the other use case of reading in from param store values in userdata, since the names of those don't change (they don't have the random guid-like portion added onto the ends of the names the way that some other resources do).
l
Odd that it's not supported by default. I think if I was to try to solve this, I'd use a dynamic resource provider which creates a (component) resource that wraps all the resources you want to consider. Your logic would live in
diff()
and
update()
, and maybe
check()
too. https://www.pulumi.com/docs/iac/concepts/resources/dynamic-providers/
w
Hmmm...that feels like overkill at this point but it's interesting to keep in the back of mind in case I just come across too many use cases that trip us up. Thanks!
Filed a bug report re: the subnet group not replacing with the replaceOnChanges set, since that bit really feels like an actual issue