This topic describes how to move resources 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 already exists in stack A, you can remove the resource from stack A without deleting it and then import the resource into stack B. This topic uses an elastic IP address (EIP) as an example to show how to move an EIP from stack A to stack B.
Prerequisites
Make sure that you have created a stack (stack A) that contains an EIP resource. For more information, see ALIYUN::VPC::EIP and Create a stack.
Remove a resource from a stack
In this example, the EIP resource is removed from stack A but retained. This allows the EIP resource to be imported into another stack, stack B. If you want to retain a resource when you remove it from a stack, set the DeletionPolicy attribute of the resource to Retain. For more information, see Background information.
Procedure
-
Log on to the Resource Orchestration Service (ROS) console.
-
In the navigation pane on the left, click Stacks.
-
In the top navigation bar, select the region where you want to create the stack from the region drop-down list, such as China (Hangzhou).
-
Update the deletion policy of the resource. Set the
DeletionPolicyof the EIP resource toRetain.For more information about the operation, see Update a deletion policy.
You need to perform this step if the resource does not have
DeletionPolicyset, or ifDeletionPolicyis set toDelete. You can skip this step ifDeletionPolicyis set toRetain. -
Remove the EIP resource.
For more information about the operation, see Remove resources.
Import the resource into a new stack
When you import a resource, you must set the DeletionPolicy attribute. Otherwise, the import fails.
Create a stack using an existing resource
You can create stack B by importing the existing EIP resource. For more information about the operation, see Create a stack from existing resources.
After the operation succeeds, you can view the new stack B in the ROS console. The information about the imported EIP resource is available on the Resources tab of stack B.
The following is a sample template for the 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
Make sure that you have created a stack (stack B) that does not contain an EIP resource. For more information about the operation, see Create a stack.
Procedure
You can import the existing EIP resource into stack B. For more information about the operation, see Import existing resources to a stack.
After the operation completes, you can view information about the imported EIP resource on the Resources tab of stack B.
In this example, the template does not contain EIP resources before the resource import, but these resources are added after the import. A sample template is as follows:
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