Hi sorry if this is a FAQ, I’ve done some searchin...
# general
f
Hi sorry if this is a FAQ, I’ve done some searching and haven’t found anything. As a Terraform user who’s new to Pulumi, I’m surprised to see that the graph of my stack has only two levels. There’s just the stack, and then it depends on every other resource. And in the graph I don’t see any relationships between any of the resources. This is surprising to me because Terraform automatically registers the relationships (dependencies) between resources and then renders a more useful graph. Am I missing something?
Maybe I’m not organizing my project properly?
b
I think the graph you are seeing is driven by the
parent
property, not resource dependencies. Pulumi is smart enough to deploy in the order that dependencies require (and I think if you look in the state file you'll see those dependencies) but by default each resource's
parent
is the top-level
Stack
resource unless provided otherwise - and I think that's the graph you're seeing
yea in the docs: https://www.pulumi.com/docs/intro/concepts/resources/#parent They use the graph you see during a
preview
as an example of the parent/child relationship. And
dependsOn
(to set explicit dependencies) is a different property / function
f
Interesting.
Thank you!
I wonder what the reasons are for this difference.
Aha, that link on parent resources led me to the docs on component resources — that was another question I was going to ask: how to create logical groupings of resources. So that’s certainly helpful!
I still would prefer not to have to explicitly declare the parents of every resource. Or, if there’s some value in the parent/child graph that I don’t understand, it’d be helpful, it seems to me, if Pulumi would also make available a dependency graph of all resources.
1
b
Usually you only use the
parent
property inside component resources. The vast majority of users are able to do what they need to do inside the
Stack
constructor or inside the initial pulumi delegate, and never make use of component resources. So it seems like a lot of work has been done to cater to the most common use-case. For instance the
Stack
constructor doesn't make you call
RegisterOutputs(...)
, or like you said, it doesn't make you pass the
parent
. But as soon as you make a component resource you take on the responsibility for that functionality and have to do
parent: this,
and remember to call
.RegisterOutputs(..)
🙏 1
Does the
pulumi stack graph
command give you a more comprehensive graph, or is it the same graph? https://www.pulumi.com/docs/reference/cli/pulumi_stack_graph/ because it seems like it has flags that differentiate between "parent edges" and "dependency edges"
1
f
That’s helpful context, thank you!
Not sure, I’ll give it a try
Looks like by default (no flags) I get the dependency graph — same as Terraform. This is helpful. Thank you!
b
awesome! Yea I'd wager that the graph you're seeing during deployment is just limited by what they can draw in a console while still being read-able, so they chose to just do the parent/child tree.
1
f
That makes sense. I think in my particular project, that graph will be more useful when I reorganize it into components.
h
any particular reason why
parent
cannot automatically be inferred from the dependency graph?
b
I can't say for sure since I didn't write it, we could maybe ask someone that might be able to give a more informed answer - but a resource can have more than 1 dependency so how would the pulumi engine know which one to choose? I think they're just different concepts. One is a logical grouping mechanism and the other is like a practical or physical grouping
👍 1
b
Hey all, quick bit of info on this topic The parent property is cosmetic only. It does not affect the dependency graph in anyway, it only updates the console output to make things look prettier. The dependency graph is all managed in state with inputs and outputs. If you need explicitly dependencies, you’d use dependsOn
b
So the console output then is not a dependency graph, just a visual of parent/child relationships?
1
r
Yeah if you want to see the dependency graph you can use the
pulumi stack graph
command https://www.pulumi.com/docs/reference/cli/pulumi_stack_graph/
Ah Josh I see you already mentioned that. But yes, the console output (and the graph at app.pulumi.com) is only a visual of the parent/child relationships. The sibling dependencies can only be seen in the
stack graph
command for now.
b
Sweet. Honestly it wasn't a difference I had thought about until @fierce-holiday-69805 brought it up
h
if i specify
depends_on
, does it override automatically inferred dependencies or just augment them?
r
Yeah… I tried once to make the console graph more like the dependency graph and realized that it spirals out of hand very quickly and is most certainly not a one-day-hack-job kinda project 😂
😅 1
if i specify 
depends_on
 , does it override automatically inferred dependencies or just augment them?
It augments them
🙌 2