All Products
Search
Document Center

Resource Orchestration Service:Remove a resource from a stack

Last Updated:Jun 16, 2026

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 DeletionPolicy attribute is set to Delete.

    Note

    If 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 DeletionPolicy attribute is set to Retain.

    Note

    To prevent accidental deletion, set the DeletionPolicy attribute to Retain.

The following procedure demonstrates the second scenario: removing a resource from a stack while retaining the physical resource.

Procedure

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

  2. In the left-side navigation pane, click Stacks.

  3. In the top navigation bar, select the region where you want to create the stack, such as China (Hangzhou).

  4. Update the deletion policy of the resource that you want to remove. Set the DeletionPolicy attribute of the resource, such as an EIP, to Retain.

    Perform this step if the resource to be removed does not have DeletionPolicy set, or if DeletionPolicy is set to Delete. Skip this step if DeletionPolicy is set to Retain.

    1. On the Stacks page, find the stack and click Update in the Actions column.

    2. Click Previous. On the Select Template page, select Replace Current Template in the Prepare Template section.

    3. In the Template Import Method section, select Enter Template Content. In the Template Content section, change the DeletionPolicy attribute for the EIP resource to Retain, then click Next.

      In this example, the template does not specify a DeletionPolicy attribute 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
              - AllocationId

      After 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
    4. On the Configure Parameters page, click Modify to save the new deletion policy.

  5. Remove the EIP resource.

    1. On the Stacks page, find the stack and click Update in the Actions column.

    2. Click Previous. On the Select Template page, select Replace Current Template in the Prepare Template section.

    3. 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 Resources section and its corresponding entry from the Outputs section. 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
    4. 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.