You can remove a resource from a stack by updating the stack template. The resource can either be deleted or retained, depending on its deletion policy.
Scenarios
The following example uses an elastic IP address (EIP) to show how to remove a resource from a stack while retaining the physical resource.
Prerequisites
A stack that contains an EIP resource is created. For more information, see Create a stack from existing resources and ALIYUN::VPC::EIP.
Background information
When you remove a resource from a stack, one of the following outcomes occurs:
-
ROS removes the resource from the stack and deletes the underlying physical resource. This occurs when the resource's
DeletionPolicyattribute is set toDelete.NoteIf you do not specify a deletion policy, this is the default.
-
ROS removes the resource from the stack but retains the physical resource. This occurs when the resource's
DeletionPolicyattribute is set toRetain.NoteTo prevent accidental deletion, set the
DeletionPolicyattribute toRetain.
The following procedure demonstrates the second scenario: removing a resource from a stack while retaining the physical resource.
Procedure
-
Log on to the Resource Orchestration Service (ROS) console.
-
In the left-side navigation pane, click Stacks.
-
In the top navigation bar, select the region where you want to create the stack, such as China (Hangzhou).
-
Update the deletion policy of the resource that you want to remove. Set the
DeletionPolicyattribute of the resource, such as an EIP, toRetain.Perform this step if the resource to be removed does not have
DeletionPolicyset, or ifDeletionPolicyis set toDelete. Skip this step ifDeletionPolicyis set toRetain.-
On the Stacks page, find the stack and click Update in the Actions column.
-
Click Previous. On the Select Template page, select Replace Current Template in the Prepare Template section.
-
In the Template Import Method section, select Enter Template Content. In the Template Content section, change the
DeletionPolicyattribute for the EIP resource toRetain, then click Next.In this example, the template does not specify a
DeletionPolicyattribute for the EIP resource.Before update
ROSTemplateFormatVersion: '2015-09-01' Resources: Eip: Type: ALIYUN::VPC::EIP Properties: Bandwidth: 5 Eip2: Type: ALIYUN::VPC::EIP 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 - AllocationIdAfter update
ROSTemplateFormatVersion: '2015-09-01' Resources: Eip: Type: ALIYUN::VPC::EIP DeletionPolicy: Retain Properties: Bandwidth: 5 Eip2: Type: ALIYUN::VPC::EIP 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 -
On the Configure Parameters page, click Modify to save the new deletion policy.
-
-
Remove the EIP resource.
-
On the Stacks page, find the stack and click Update in the Actions column.
-
Click Previous. On the Select Template page, select Replace Current Template in the Prepare Template section.
-
In the Template Import Method section, select Enter Template Content. In the Template Content section, modify the template content, and then click Next.
In this example, delete the EIP resource definition from the
Resourcessection and its corresponding entry from theOutputssection. The following template shows the result after the EIP resource is removed:ROSTemplateFormatVersion: '2015-09-01' Resources: Eip2: Type: ALIYUN::VPC::EIP Properties: Bandwidth: 5 Outputs: EipAddress2: Value: Fn::GetAtt: - Eip2 - EipAddress AllocationId2: Value: Fn::GetAtt: - Eip2 - AllocationId -
On the Configure Parameters page, click Modify to update the stack.
-
Result
After the stack is updated, the removed resource no longer appears on the Resources tab of the stack details page. Because the deletion policy is set to Retain, ROS does not delete the physical EIP resource. You can find the elastic IP address on the Elastic IP Addresses page in the Virtual Private Cloud (VPC) console.
Next steps
To add resources to an existing stack, see Import existing resources into a stack.