https://pulumi.com logo
#typescript
Title
# typescript
t

thousands-area-40147

09/09/2021, 9:06 AM
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

lively-crowd-44886

09/09/2021, 6:38 PM
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

little-cartoon-10569

09/09/2021, 8:05 PM
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

proud-pizza-80589

09/12/2021, 7:27 AM
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

little-cartoon-10569

09/12/2021, 9:11 PM
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 🙂).