您可以根据需要将资源从一个资源栈移动到另外一个资源栈。本文以移动弹性公网IP(EIP)资源为例进行介绍。

背景信息

本示例中,资源栈A中有一个EIP(例如:EIP2),您需要将EIP2移动到资源栈B中。

操作步骤

  1. 将EIP2从资源栈A中移除。
    具体操作,请参见从资源栈移除资源

    移除前,资源栈A的模板中包含EIP2。示例模板如下所示:

    {
      "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"
            ]
          }
        }
      }
    }
    说明 DeletionPolicy:取值为Retain,表示删除保护策略为保留资源。为防止资源被误删除,请务必设置该项。

    移除后,资源栈A的模板中不包含EIP2。示例模板如下所示:

    {
      "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"
            ]
          }
        }
      }
    }
  2. 将EIP2导入资源栈B。
    具体操作,请参见将现有资源导入资源栈

    导入前,资源栈B的模板中不包含EIP2。示例模板如下所示:

    {
      "ROSTemplateFormatVersion": "2015-09-01"
    }

    导入后,资源栈B的模板中包含EIP2。示例模板如下所示:

    {
      "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"
            ]
          }
        }
      }
    }

执行结果

操作成功后,EIP2将从资源栈A移动到资源栈B。您可以在资源栈B的资源页签,查看已导入的EIP2资源信息。