When is it a good idea to use parent as opposed to...
# general
f
When is it a good idea to use parent as opposed to just depends_on?
p
For example when creating component resources.
a
Dependencies are implicitly resolved by Pulumi when you use an output from one resource as input for creating another.
depends_on
is only really needed when you have to do some mangling with the outputs or can't use outputs directly as inputs and have to explicitly define the order of things are created, destroyed etc. I'd say I use parent 95% of the time and as an added benefit it will visually show the logical grouping of resources during Pulumi operations. When developing IaC modules I usually review the output and make sure things are correctly grouped together.
m
@full-lamp-64265 example here:
Copy code
# AmazonEKSVPCResourceController
    aws.iam.RolePolicyAttachment(
        resource_name=dynamic_name(
            data["iam"]["eks-vpc-resource-policy"]["name"]
        ),
        role=eks_role.id,
        policy_arn=data["iam"]["eks-vpc-resource-policy"]["policy_arn"],
        opts=pulumi.ResourceOptions(depends_on=eks_role),
    )
It is so useful when you need to create an EKS/GKE/AKS cluster and expect that a service role will be created before the cluster to allow you to use that service role in the cluster.
f
@mammoth-electrician-64525 but I can do that also with depends_on I think
m
This depends solely on you, it will depend on how you want to coordinate your resource orchestration
for example, as @adventurous-butcher-54166 mentioned, Pulumi implicitly solves this and in most cases it is more than enough, but I have some cases where it is not what I need. When I create a Kubernetes cluster I have some Helm Charts that depend on external resources, like the cluster-autoscaler. I can let Pulumi implicitly define the order, but it usually decides to install the helm chart to the cluster-autoscaler and then it will create the service account in the cloud provider to allow more nodes to be created in the Cluster's NodeGroup from within the cluster. This is a case where I want the cluster-autoscaler helm chart to be deployed only after I already have the service account created and the policies attached. For this, I use depends_on in Pulumi ResourceOptions. Here is a good documentation about the available options for you to choose and use.