This topic describes how to move a resource from one stack to another. An Elastic
IP Address (EIP) resource is used in the example.
Background information
In this example, an EIP resource named EIP2 is moved from Stack A to Stack B.
Procedure
- Remove EIP2 from Stack A.
For more information, see
Remove a resource from a stack.
Before you remove EIP2, it is contained in the template of Stack A. The following
code shows a sample template before EIP2 is removed from Stack A:
ROSTemplateFormatVersion: '2015-09-01'
Resources:
Eip:
Type: ALIYUN::VPC::EIP
Properties:
Bandwidth: 5
Eip2:
Type: ALIYUN::VPC::EIP
DeletionPolicy: Retain
Properties:
Bandwidth: 5
Outputs:
EipAddress:
Value:
Fn::GetAtt:
- Eip
- EipAddress
AllocationId:
Value:
Fn::GetAtt:
- Eip
- AllocationId
EipAddress2:
Value:
Fn::GetAtt:
- Eip2
- EipAddress
AllocationId2:
Value:
Fn::GetAtt:
- Eip2
- AllocationId
Note The DeletionPolicy
parameter is set to Retain
, which indicates that the resource is retained when it is removed from a stack. To
prevent resources from being unexpectedly deleted, we recommend that you set the DeletionPolicy
parameter to Retain.
After you remove EIP2, it is no longer contained in the template of Stack A. The following
code shows a sample template after EIP2 is removed from Stack A:
ROSTemplateFormatVersion: '2015-09-01'
Resources:
Eip:
Type: ALIYUN::VPC::EIP
Properties:
Bandwidth: 5
Outputs:
EipAddress:
Value:
Fn::GetAtt:
- Eip
- EipAddress
AllocationId:
Value:
Fn::GetAtt:
- Eip
- AllocationId
- Import EIP2 to Stack B.
For more information, see
Import an existing resource to a stack.
Before you import EIP2, it is not contained in the template of Stack B. The following
code shows a sample template before EIP2 is imported to Stack B:
ROSTemplateFormatVersion: '2015-09-01'
After you import EIP2, it is contained in the template of Stack B. The following code
shows a sample template after EIP2 is imported to Stack B:
ROSTemplateFormatVersion: '2015-09-01'
Resources:
Eip2:
Type: ALIYUN::VPC::EIP
DeletionPolicy: Retain
Properties:
Bandwidth: 5
Outputs:
EipAddress2:
Value:
Fn::GetAtt:
- Eip2
- EipAddress
AllocationId2:
Value:
Fn::GetAtt:
- Eip2
- AllocationId
Result
After the preceding operations, EIP2 is moved from Stack A to Stack B. You can view
information about the imported EIP2 resource on the Resources tab of the stack management page of Stack B.