async function isDrifted()

in source/drift-detection/index.js [90:122]


async function isDrifted(stackName, region, ) {
  const cloudFormation = new AWS.CloudFormation({ region });

  try {
    const response = await cloudFormation.detectStackDrift({
      StackName: stackName
    }).promise();

    let driftResponse = null;

    do {
      driftResponse = await cloudFormation.describeStackDriftDetectionStatus({
        StackDriftDetectionId: response.StackDriftDetectionId
      }).promise();

      if (driftResponse.DetectionStatus === 'DETECTION_IN_PROGRESS') {
        await sleep(3);
      }
    } while(driftResponse.DetectionStatus === 'DETECTION_IN_PROGRESS');

    if (driftResponse.StackDriftStatus === 'DRIFTED') {
      return true;
    }

    return false;
  } catch (error) {
    if (error.message !== `Stack [${stackName}] does not exist`) {
      throw error;
    }

    return false;
  }
}