Skip to content

Resource option: parent ​

The parent resource option specifies a parent for a resource, which has the following effects:

  • The child inherits additional resource options from its parent.
  • The Pulumi CLI shows the parent/child hierarchy in CLI output.

By default, resources are parented to the implicitly created pulumi:pulumi:Stack resource which is at the root of all Pulumi stacks. The most common use of explicitly setting the parent property is when authoring a Component Resource. Resources that are part of a component should be explicitly parented to the component itself. This ensures that all resources within a component share desirable lifecycle behavior. You can also create multiple levels of nesting within a component to improve the visual display in the CLI.

Setting a resource's parent ​

The following example shows a simple parent/child relationship between two resources:

typescript
const parent = new MyResource("parent", {/*...*/});
const child = new MyResource("child", {/*...*/}, { parent: parent });

Parent relationships in the CLI ​

Specifying a resource's parent can help visually organize resources in the CLI. For example, the following pulumi up output shows an AWS Virtual Private Cloud (VPC) with two child subnets (and also shows the VPC's child relationship to the implicit pulumi:pulumi:Stack resource):

bash
Previewing update (dev):

    Type                    Name                             Plan
    pulumi:pulumi:Stack     parent-demo-dev
+   ├─ aws:ec2:Vpc          default-vpc-866580ff             create
+   │  ├─ aws:ec2:Subnet    default-vpc-866580ff-public-1    create
+   │  └─ aws:ec2:Subnet    default-vpc-866580ff-public-0    create

Inherited resource options ​

A child resource inherits the following resource options from its parent unless the child sets the option explicitly. This is the complete list; other resource options are not inherited.

  • provider: Child resources inherit their parent's provider to ensure that child resources are created in the same cloud context (account, region, etc.) as their parent.

  • aliases: Aliases are inherited so that changing the type of a parent resource correctly changes the qualified type of a child resource, and changing the name of a parent resource correctly changes the name prefix of child resources.

  • protect: Child resources inherit their parent's protection bit to ensure that deletions execute correctly. Children are deleted before their parent, so inheriting protection ensures that if a parent is marked as protected, none of its children will be deleted (because deleting the protected parent would fail).

  • retainOnDelete: Child resources inherit their parent's retainOnDelete so that the resources inside a retained component are retained too. Setting retainOnDelete on a component resource has no effect on the component itself, which has no physical infrastructure to keep, but it applies to every child that doesn't set the option explicitly. A child can set retainOnDelete: false to opt out.

  • transforms: Transforms applied to a parent will run on the parent and on all child resources. This allows a transform to be applied to a component to intercept and modify any resources created by its children. As a special case, Stack transforms will be applied to all resources (since all resources ultimately are parented directly or indirectly by the root stack resource).

  • transformations: Transformations applied to a parent will run on the parent and on all child resources. This allows a transformation to be applied to a component to intercept and modify any resources created by its children. As a special case, Stack transformations will be applied to all resources (since all resources ultimately are parented directly or indirectly by the root stack resource). Prefer transforms over transformations as the latter is deprecated.

  • deletedWith: Child resources inherit their parent's deletedWith so that when a parent is being removed alongside the resource named in its deletedWith, child deletions are skipped as well. This matches how containing resources (such as a Kubernetes namespace or a cloud resource group) cascade-delete their contents in the backing provider — individual child deletes are unnecessary, and skipping them also speeds up pulumi destroy.

The Pulumi engine, not the language SDK, applies inheritance for provider, protect, retainOnDelete, and deletedWith. As a result, SDK source code is not a reliable way to tell which options a child inherits.

Content from the official Pulumi documentation (github.com/pulumi/docs).