1. Docs
  2. Concepts
  3. Resource options
  4. parent

Resource option: parent

    The parent resource option specifies a parent for a resource. It is used to associate children with the parents that encapsulate or are responsible for them. Good examples of this are component resources. The default behavior is to parent each resource to the implicitly-created pulumi:pulumi:Stack component resource that is a root resource for all Pulumi stacks.

    Although the parent resource option can be used to parent a resource to any other resource, it is strongly recommended to parent resources only to component resources when they are actually children. Parenting a resource to another custom resource can in some cases result in undefined behavior.

    For example, this code creates two resources, a parent and child, the latter of which is a child to the former:

    let parent = new MyResource("parent", {/*...*/});
    let child = new MyResource("child", {/*...*/}, { parent: parent });
    let parent = new MyResource("parent", {/*...*/});
    let child = new MyResource("child", {/*...*/}, { parent: parent });
    parent = MyResource("parent");
    child = MyResource("child", opts=ResourceOptions(parent=parent));
    parent, _ := NewMyResource(ctx, "parent", &MyResourceArgs{/*...*/})
    child, _ := NewMyResource(ctx, "child", &MyResourceArgs{/*...*/}, pulumi.Parent(parent))
    var parent = new MyResource("parent", new MyResourceArgs());
    var child = new MyResource("child", new MyResourceArgs(),
        new CustomResourceOptions { Parent = parent });
    var parent = new MyResource("parent");
    var child = new MyResource("child",
        type: MyResource
        type: MyResource
          parent: ${parent}

    Using parents can clarify causality or why a given resource was created in the first place. For example, this pulumi up output shows an AWS Virtual Private Cloud (VPC) with two subnets attached to it, and also shows that the VPC directly belongs to the implicit pulumi:pulumi:Stack resource:

    Previewing update (dev):
        Type                       Name                             Plan
        pulumi:pulumi:Stack        parent-demo-dev
    +   ├─ awsx:x:ec2:Vpc          default-vpc-866580ff             create
    +   │  ├─ awsx:x:ec2:Subnet    default-vpc-866580ff-public-1    create
    +   │  └─ awsx:x:ec2:Subnet    default-vpc-866580ff-public-0    create

    Child resources inherit default values for many other resource options from their parent, including:

    • provider: The provider instance used to construct a resource is inherited from it’s parent, unless explicitly overridden by the child resource. The parent itself may have inherited the global default provider if no resource in the parent chain specified a provider instance for the corresponding provider type.

    • aliases: Aliases applied to a parent are applied to all child resources, 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: A protected parent will protect all children. This ensures that if a parent is marked as protected, none of it’s children will be deleted ahead of the attempt to delete the parent failing.

    • 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 it’s 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).

      Pulumi AI - What cloud infrastructure would you like to build? Generate Program