All Products
Search
Document Center

Resource Orchestration Service:Remove a resource from a stack

Last Updated:Jan 24, 2024

This topic describes how to remove a resource from a stack in the Resource Orchestration Service (ROS) console.

Scenario

When you no longer need a resource that is contained in a stack, you can remove the resource by updating the stack template. This topic describes how to remove a resource from a stack and retain the resource. In this example, an elastic IP address (EIP) is used.

Prerequisites

A stack that contains an EIP is created. For more information, see Import an existing resource to create a stack and ALIYUN::VPC::EIP.

Background information

When you remove a resource, one of the following situations occurs:

  • The resource is deleted when it is removed from a stack. This situation occurs when you set the DeletionPolicy property of the resource to Delete.

    Note

    If you do not specify a value for the DeletionPolicy property, the default value is Delete.

  • The resource is retained when it is removed from a stack. This situation occurs when you set the DeletionPolicy property of the resource to Retain.

    Note

    To prevent a resource from being unexpectedly deleted, we recommend that you set the DeletionPolicy property of the resource to Retain.

In this example, the resource is retained when it is removed from a stack.

Procedure

  1. Log on to the ROS console.

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

  3. In the top navigation bar, select the region where the stack you want to manage resides from the region drop-down list. For example, you can select China (Hangzhou).

  4. Set the DeletionPolicy property of the resource that you want to remove to Retain. In this example, an EIP is used.

    You must perform this step if the DeletionPolicy property of the EIP is set to Delete or not specified. You must skip this step if the DeletionPolicy property of the EIP is set to Retain.

    1. On the Stacks page, find the stack from which you want to remove the EIP and click Update in the Actions column.

    2. In the Configure Parameters step, click Previous. In the Prepare Template section of the Select Template step, click Replace Current Template.

    3. Set the Template Import Method parameter to Enter Template Content. In the Template Content section, set the DeletionPolicy property of the EIP to Retain. Then, click Next.

      In this example, the DeletionPolicy property is not specified for the EIP before you set the DeletionPolicy property to Retain. The following sample code provides examples of the templates before and after you set the DeletionPolicy property to Retain.

      Before the 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 the 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. In the Configure Parameters step, click Confirm. This way, the DeletionPolicy property of the EIP is set to Retain.

  5. Remove the EIP.

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

    2. In the Configure Parameters step, click Previous. In the Prepare Template section of the Select Template step, click Replace Current Template.

    3. Set the Template Import Method parameter to Enter Template Content. In the Template Content section, modify the template content. Then, click Next.

      In this example, the parameters of the EIP are deleted from the Resources and Outputs sections of the template. The following sample code provides an example of the template after the parameters of the EIP are deleted:

      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. In the Configure Parameters step, click Confirm to complete the stack update.

Check the result

After you remove the EIP, it is no longer contained in the stack. If you cannot view the EIP on the Resources tab of the stack, but can view the EIP on the Elastic IP Addresses page in the Virtual Private Cloud (VPC) console, the EIP is removed from the stack but is still retained.

What to do next

Add existing resources to the stack. For more information, see Import an existing resource to update a stack.