Move resources between stacks

更新时间:
复制 MD 格式

This topic describes how to move a resource from one stack to another.

Scenarios

A resource can exist in only one stack. If you want to manage a resource using stack B but the resource is already in stack A, you must remove the resource from stack A while retaining it. Then, you can import the resource into stack B. This topic uses an elastic IP address (EIP) as an example to describe how to move an EIP from stack A to stack B.

Prerequisites

Ensure that you have created a stack containing an EIP resource (Stack A). For more information, see ALIYUN::VPC::EIP and Create a stack.

Remove a resource from a stack

This example describes how to remove an EIP from stack A and retain it so that you can import the EIP into stack B. To retain a resource when you remove it, set the DeletionPolicy of the resource to Retain. For more information, see Background information.

Procedure

  1. Log on to the Resource Orchestration Service (ROS) console.

  2. In the navigation pane on the left, click Stacks.

  3. In the top navigation bar, select a region from the region drop-down list, such as China (Hangzhou).

  4. Update the deletion policy of the resource that you want to remove. Set the DeletionPolicy of the EIP to Retain.

    For more information, see Update a deletion policy.

    You must perform this step if a DeletionPolicy is not set for the resource that you want to remove, or if the DeletionPolicy is set to Delete. You can skip this step if the DeletionPolicy is already set to Retain.

  5. Remove the EIP resource.

    For more information, see Remove resources.

Import the resource into a new stack

Note

When you import a resource, you must set the DeletionPolicy. Otherwise, the import operation fails.

Create a stack from an existing resource

Create stack B by importing the existing EIP. For more information, see Create a stack from existing resources.

After the operation is complete, you can go to the ROS console to view the new stack B. Information about the imported EIP is available on the Resources tab.

The following is a sample template for resource import:

ROSTemplateFormatVersion: '2015-09-01'
Resources:
  Eip:
    Type: ALIYUN::VPC::EIP
    DeletionPolicy: Retain
    Properties:
      Bandwidth: 5
Outputs:
  EipAddress:
    Value:
      Fn::GetAtt:
        - Eip
        - EipAddress
  AllocationId:
    Value:
      Fn::GetAtt:
        - Eip
        - AllocationId

Import an existing resource into a stack

Prerequisites

A stack (stack B) that does not contain an EIP resource is created. For more information, see Create a stack.

Procedure

Import the existing EIP into stack B. For more information, see Import existing resources into a stack.

After the operation completes, you can view the imported EIP on the Resources tab of stack B.

The template does not contain the EIP resource before the import. After the import, the template is updated to include the EIP resource. The following are sample templates:

Before import

ROSTemplateFormatVersion: '2015-09-01'

After import

ROSTemplateFormatVersion: '2015-09-01'
Resources:
  Eip:
    Type: ALIYUN::VPC::EIP
    DeletionPolicy: Retain
    Properties:
      Bandwidth: 5
Outputs:
  EipAddress:
    Value:
      Fn::GetAtt:
        - Eip
        - EipAddress
  AllocationId:
    Value:
      Fn::GetAtt:
        - Eip
        - AllocationId