You can perform drift detection on a stack to determine whether the stack has drifted from its expected configurations. The operation returns details about the drift status of resources within a stack that supports drift detection.

Prerequisites

A stack is created. For more information about how to create a stack, see Create a stack.

Detect drift in the ROS console

  1. Log on to the ROS console.
  2. In the left-side navigation pane, click Stacks.
  3. On the Stacks page, click the ID under the name of the target stack.
  4. Click the Drifts tab.
  5. On the Drifts tab, click Detect Stack Drift.check
    Note
    • ROS displays a prompt, indicating that a drift detection operation is initiated for the selected stack.
    • Only a single drift detection operation on one stack can be performed at a time.
    • The drift detection operation may take several minutes. The actual amount of time it takes for a drift detection operation to complete depends on the number of resources in the stack. ROS will continue the drift detection operation even if you close the information window.
  6. In the Basic Information section of the Stack Information tab, view the drift status and last drift detection time of the stack.查看-1
    Note A stack is considered to have drifted if one or more of its resources have drifted.

Detect drift through Alibaba Cloud CLI

You can use the following aliyun ros commands through Alibaba Cloud Command Line Interface (Alibaba Cloud CLI) to detect drift on a stack.

Command Description
DetectStackDrift Initiates a drift detection operation on a stack.
GetStackDriftDetectionStatus Monitors the status of the drift detection operation on a stack.
ListStackResourceDrifts Queries detailed information about resource drift in a stack.
  • You can use the DetectStackDrift subcommand to detect drift on a stack. The stack ID must be specified. Resource names must also be specified to filter resources on which you want to detect drift.
    $ aliyun ros DetectStackDrift --StackId 4334b961-3bfd-419e-9a00-23a95e******
    {
      "DriftDetectionId": "13b48934-6818-4765-8ae1-744241******",
      "RequestId": "B288A0BE-D927-4888-B0F7-B35EF84B6E6F"
    }
  • The stack drift detection operation may take a long time to complete. You can use the GetStackDriftDetectionStatus subcommand to monitor the status of the drift detection operation. This subcommand obtains the stack drift detection ID returned by the DetectStackDrift subcommand.

    In the following example, the drift detection ID of the stack returned by the DetectStackDrift subcommand in the preceding example is passed as a parameter to the GetStackDriftDetectionStatus subcommand. This parameter returns operation details, indicating that the drift detection operation is completed.

    $ aliyun ros GetStackDriftDetectionStatus --StackDriftDetectionId 13b48934-6818-4765-8ae1-744241******
    {
        "RequestId": "52398D3A-E868-4F95-8B5E-6A2DFB778B16",
        "DriftDetectionTime": "2020-03-17T07:21:17",
        "DriftDetectionStatusReason": "Detect stack drift successfully",
        "DriftedStackResourceCount": 2,
        "DriftDetectionStatus": "DETECTION_COMPLETE",
        "StackDriftStatus": "DRIFTED",
        "DriftDetectionId": "13b48934-6818-4765-8ae1-744241******",
        "StackId": "4334b961-3bfd-419e-9a00-23a95e******"
    }
  • After the stack drift detection operation is completed, you can use the ListStackResourceDrifts subcommand to view the results, including the actual and expected drift values of resource properties.
    $ aliyun ros ListStackResourceDrifts --StackId 4334b961-3bfd-419e-9a00-23a95e******
    {
      "ResourceDrifts": [
        {
          "ResourceDriftStatus": "MODIFIED",
          "LogicalResourceId": "Vpc1",
          "PropertyDifferences": [
            {
              "ActualValue": "test11",
              "PropertyPath": "/Description",
              "ExpectedValue": "test1",
              "DifferenceType": "NOT_EQUAL"
            }
          ],
          "PhysicalResourceId": "vpc-m5euqfvmzygb7xq******",
          "ExpectedProperties": "{\"CidrBlock\": \"192.168.0.0/16\", \"Description\": \"test1\", \"VpcName\": \"test1\"}",
          "DriftDetectionTime": "2020-03-17T07:21:17",
          "ResourceType": "ALIYUN::ECS::VPC",
          "ActualProperties": "{\"CidrBlock\": \"192.168.0.0/16\", \"Description\": \"test11\", \"VpcName\": \"test1\"}",
          "StackId": "4334b961-3bfd-419e-9a00-23a95e******"
        },
        {
          "ResourceDriftStatus": "DELETED",
          "LogicalResourceId": "Vpc2",
          "PhysicalResourceId": "vpc-m5exf3skxrxtvtk******",
          "DriftDetectionTime": "2020-03-17T07:21:17",
          "ResourceType": "ALIYUN::ECS::VPC",
          "StackId": "4334b961-3bfd-419e-9a00-23a95e******"
        }
      ],
      "RequestId": "8E1DE57B-6124-482B-8283-EF5562653308"
    }