This topic describes the structure, best practices, common templates, update behaviors, and output values of nested stacks, as well as how to view nested stacks and their parent stacks.

Structure of nested stacks

Nested stacks can themselves contain other nested stacks, resulting in a hierarchy of stacks. The root stack is the top-level stack to which all the nested stacks belong.

Each nested stack has an immediate parent stack. For the first-level nested stacks, the root stack is also the parent stack.

The following example shows the relationship between nested stacks and root stacks:

  • Stack A is the root stack of all the nested stacks in this hierarchy.
  • For Stack B, Stack A is both the parent stack and the root stack.
  • For Stack C, the parent stack is Stack B. For Stack D, the parent stack is Stack C.
1

Certain stack operations, such as stack updates, must be initiated from the root stack rather than performed directly on nested stacks. Also, nested stacks affect how stack operations are performed in some cases.

Use nested stacks to reuse common templates

As your infrastructure grows, similar patterns can be combined to declare common components across multiple templates. You can separate these common components and create dedicated templates for them. This way, you can mix and match different templates but use nested stacks to create a single, unified stack.

Nested stacks are stacks that are created as part of other stacks. You can use the ALIYUN::ROS::Stack resource in another stack to create nested stacks. For more information about the ALIYUN::ROS::Stack resource, see ALIYUN::ROS::Stack.

Assume that you have a load balancer configuration that you use for most of your stacks. Instead of copying and pasting the same configurations into your templates, you can create a dedicated template for the load balancer. Then, you only need to use the ALIYUN::ROS::Stack resource to reference that template from within other templates. If the load balancer template is updated, any stack that references the template will use the updated load balancer after the stack is updated.

Update behaviors of nested stack resources

If a template that you want to update includes multiple nested stacks, ROS will initiate an update for each nested stack. This helps determine whether the nested stacks have been modified.

ROS updates only those resources in the nested stacks that have changes specified in the corresponding templates.

Use the output values of nested stacks

A nested stack is a stack that you create in another stack with the ALIYUN::ROS::Stack resource. With nested stacks, you can deploy and manage all resources from a single stack. You can use outputs from one stack in a nested stack group as inputs to another stack in the group.

View the nested stacks that belong to a parent stack

  1. Log on to the ROS console.
  2. In the left-side navigation pane, click Stacks.
  3. On the Stacks page, find the parent stack whose nested stacks you want to view, and click its ID in the Stack Name column.
    Note If the parent stack is also a nested stack, select Show Nested Stacks.
  4. Click the Resources tab.

    Find resources of the ALIYUN::ROS::Stack type.

View the parent stack of a nested stack

  1. Log on to the ROS console.
  2. In the left-side navigation pane, click Stacks.
  3. On the Stacks page, select Show Nested Stacks and view the stack list.
  4. Find the nested stack whose parent stack you want to view, and click its ID in the Stack Name column.
  5. Click the Stack Information tab and view the value of Parent Stack ID.