Hej everyone! I'm having trouble finding answers t...
# typescript
t
Hej everyone! I'm having trouble finding answers to this question, but maybe someone can point me in the right direction here. What are best practices to modify a resource during runtime, specifically when the modification depends on a conditional? Let's say we need to provision
Resource A
no matter what, but
Resource B
might be omitted for a stack. If
Resource B
is provisioned however, it will depend on
Resource A
, but also changes will need to happen to
Resource A
after creating
Resource B
. As far as I can tell, there's no
modify
method or similar for resources that have already been created, or am I missing something?
l
Unless the new properties of
Resource A
depend directly on the outputs of
Resource B
, you should be able to approach it like
Copy code
if(bEnabled){
   new ResourceA(argsAB)
   new ResourceB(argsB)
} else {
   new ResourceA(argsA)
}
l
If you need to update resource A after both resource A and resource B are created, then you need a different project / stack. automation-api helps with this. There is no ability within any declarative system to change the declaration after making it. Pulumi is a declarative system.
2
p
Well, you can also see different “runs” of pulumi up as the modify. Run 1, just A, run 2 A+B with all the settings changed (it is ts, you can do anything you want) and pulumi will reconfigure A based on the new settings.
l
Yep, changing the declaration of an existing resource works. I do this when setting up peering between VPCs that are declared in different stacks. It's not the easiest-to-read code since you need to know that the flow changes in stack A based on whether or not stack B has been deployed. But I think it's working (hard to tell without completely destroying everything and deploying from scratch.. which I'm not keen on trying 🙂).