---
policy: /ce/ca/aws/autoscaling/group-multiple-az
logic: /ce/ca/aws/autoscaling/group-multiple-az/prod.logic.yaml
executionTime: 2025-10-25T12:01:40.402457476Z
generationMs: 59
executionMs: 805
rows:
  - id: test1
    match: true
    status:
      expected: DISAPPEARED
      actual: DISAPPEARED
    conditionIndex:
      expected: 99
      actual: 99
    conditionText:
      expected: isDisappeared(CA10__disappearanceTime__c)
      actual: isDisappeared(CA10__disappearanceTime__c)
    runtimeError: {}
  - id: test2
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('caSetFrom_availabilityZones__c').size() <= number(1.0)
      actual: extract('caSetFrom_availabilityZones__c').size() <= number(1.0)
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/autoscaling/group-multiple-az/policy.yaml
    md5Hash: ECFD0E3F4BCECB14AA26D626DE3BB466
    content: "---\nnames:\n  full: \"AWS EC2 Auto Scaling Group does not span multiple\
      \ Availability Zones\"\n  contextual: \"Auto Scaling Group does not span multiple\
      \ Availability Zones\"\ndescription: >\n  Ensure that AWS Auto Scaling Groups\
      \ are configured across multiple Availability \n  Zones to helps applications\
      \ remain resilient in case of an Availability Zone failure.\ncategories:\n \
      \ - \"RELIABILITY\"\ntype: \"COMPLIANCE_POLICY\"\nframeworkMappings:\n  - \"\
      /frameworks/cloudaware/resource-reliability/system-configuration\"\n  - \"/frameworks/aws-fsbp-v1.0.0/auto-scaling/02\"\
      \n  - \"/frameworks/aws-well-architected/rel/06/04\"\n  - \"/frameworks/aws-well-architected/rel/07/02\"\
      \n  - \"/frameworks/aws-well-architected/rel/11/03\"\n  - \"/frameworks/aws-well-architected/sus/02/01\""
  - path: /ce/ca/aws/autoscaling/group-multiple-az/prod.logic.yaml
    md5Hash: F94E1A26546C3086A396E2C20D6FFACA
    content: "---\ninputType: \"CA10__CaAwsAutoScalingGroup__c\"\nimportExtracts:\n\
      \  - file: \"/types/CA10__CaAwsAutoScalingGroup__c/object.extracts.yaml\"\n\
      testData:\n  - file: \"test-data.json\"  \nconditions:\n  - status: \"INCOMPLIANT\"\
      \n    currentStateMessage: \"The Auto Scaling group is configured to use only\
      \ one Availability Zone.\"\n    remediationMessage: \"Modify the Auto Scaling\
      \ group to include instances in at least two Availability Zones.\"\n    check:\n\
      \      LESS_THAN_EQUAL:\n        left:\n          SIZE:\n            arg:\n\
      \              EXTRACT: \"caSetFrom_availabilityZones__c\"\n        right:\n\
      \          NUMBER: 1\notherwise:\n  status: \"COMPLIANT\"\n  currentStateMessage:\
      \ \"The Auto Scaling group spans multiple Availability Zones.\""
  - path: /ce/ca/aws/autoscaling/group-multiple-az/test-data.json
    md5Hash: 7AABEB668F71EE116A80F5DF07E31113
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-21T01:48:33Z"
              },
              "CA10__disappearanceTime__c": "2025-07-29T11:31:15Z",
              "CA10__availabilityZones__c": "us-west-1a\nus-west-1b",
              "Id": "test1"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "extract('caSetFrom_availabilityZones__c').size() <= number(1.0)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-21T01:48:33Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__availabilityZones__c": "us-west-1a",
              "Id": "test2"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "200",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-21T01:48:33Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__availabilityZones__c": "us-west-1a\nus-west-1b",
              "Id": "test3"
          }
      ]
  - path: /types/CA10__CaAwsAutoScalingGroup__c/object.extracts.yaml
    md5Hash: DD26D73C0CF43F8CE9CBE35D8241D89C
    content: "---\nextracts:\n  # AvailabilityZones.member.N\n  # One or more Availability\
      \ Zones for the group.\n  # Type: Array of strings\n  # Length Constraints:\
      \ Minimum length of 1. Maximum length of 255.\n  # Pattern: [\\u0020-\\uD7FF\\\
      uE000-\\uFFFD\\uD800\\uDC00-\\uDBFF\\uDFFF\\r\\n\\t]*\n  # Required: Yes\n \
      \ - name: CA10__availabilityZones__c\n    value: \n      FIELD:\n        path:\
      \ CA10__availabilityZones__c\n        undeterminedIf:\n          isEmpty: Corrupted\
      \ data. Availability zones should always present\n  - name: caSetFrom_availabilityZones__c\n\
      \    value: \n      SET_FROM:\n        separator: \"\\n\"\n        arg:\n  \
      \        EXTRACT: CA10__availabilityZones__c\n# A comma-separated value string\
      \ of one or more health check types.\n# Values: EC2, EBS, ELB, VPC_LATTICE.\
      \  Not nullable. Can't have no access, retrieved via autoscaling:DescribeAutoScalingGroups\n\
      \  - name: CA10__healthCheckType__c\n    value: \n      FIELD:\n        path:\
      \ CA10__healthCheckType__c     \n# Nullable. Can't have no access, retrieved\
      \ via autoscaling:DescribeAutoScalingGroups     \n  - name: CA10__launchConfigurationName__c\n\
      \    value: \n      FIELD:\n        path: CA10__launchConfigurationName__c \
      \         \n# Nullable. Can't have no access, retrieved via autoscaling:DescribeAutoScalingGroups\
      \     \n  - name: CA10A1__launchTemplateId__c\n    value: \n      FIELD:\n \
      \       path: CA10A1__launchTemplateId__c          \n# Nullable. Can't have\
      \ no access, retrieved via autoscaling:DescribeAutoScalingGroups     \n  - name:\
      \ CA10A1__mixedInstancesLaunchTemplateId__c\n    value: \n      FIELD:\n   \
      \     path: CA10A1__mixedInstancesLaunchTemplateId__c          \n# Values: Enable\
      \ | Disable. Nullable, null == Disable. Can't have no access, retrieved via\
      \ autoscaling:DescribeAutoScalingGroups     \n  - name: CA10__capacityRebalancing__c\n\
      \    value: \n      FIELD:\n        path: CA10__capacityRebalancing__c     \
      \     \n"
script: |-
  CREATE TEMP FUNCTION mock_ExpectedResult()
  RETURNS ARRAY<STRUCT<
          Id STRING,
          expectedResult STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, runtimeError STRING>
      >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "Id" : "test1",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('caSetFrom_availabilityZones__c').size() <= number(1.0)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsAutoScalingGroup__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__availabilityZones__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-10-21T01:48:33Z")
    },
    "CA10__disappearanceTime__c" : new Date("2025-07-29T11:31:15Z"),
    "CA10__availabilityZones__c" : "us-west-1a\nus-west-1b",
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-21T01:48:33Z")
    },
    "CA10__availabilityZones__c" : "us-west-1a",
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-21T01:48:33Z")
    },
    "CA10__availabilityZones__c" : "us-west-1a\nus-west-1b",
    "Id" : "test3"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsAutoScalingGroup__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__availabilityZones__c STRING,
          Id STRING
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
  var BytesLib = new function () {
      this.normalize = function(arg) {
          return arg == null ? '' : arg;
      };
      this.isEmpty = function(arg) {
          return this.normalize(arg) == '';
      };
      this.isNotEmpty = function(arg) {
          return this.normalize(arg) != '';
      };
      this.equal = function(left, right) {
          return this.normalize(left) == this.normalize(right);
      };
      this.notEqual = function(left, right) {
          return this.normalize(left) != this.normalize(right);
      };
      this.startsWith = function(arg, substring) {
          return this.normalize(arg).startsWith(this.normalize(substring));
      };
      this.endsWith = function(arg, substring) {
          return this.normalize(arg).endsWith(this.normalize(substring));
      };
      this.contains = function(arg, substring) {
          return this.normalize(arg).includes(this.normalize(substring));
      };
      this.containsAll = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.every(sub => normalizedArg.includes(this.normalize(sub)));
      };
      this.containsAny = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.some(sub => normalizedArg.includes(this.normalize(sub)));
      };
  }();
  var CollectionLib = new function () {
      this.parse = function(arg, separator, skipEmpty, skipDuplicates, sort, normalize) {
          if (arg == null) return [];
          let parts = arg.split(separator);
          return this.fromArray(parts, skipEmpty, skipDuplicates, sort, normalize);
      };
      this.fromArray = function(arr, skipEmpty, skipDuplicates, sort, normalize) {
          if (arr == null) return [];
          let result = [];
          let seen = new Set();
          arr.forEach(el => {
              let normalized = normalize ? TextLib.normalize(el) : BytesLib.normalize(el);
              if (!skipEmpty || (normalize ? TextLib.isNotEmpty(el) : BytesLib.isNotEmpty(el))) {
                  if (!skipDuplicates || !seen.has(normalized)) {
                      if (skipDuplicates) seen.add(normalized);
                      result.push(normalized);
                  }
              }
          });
          if (sort) result.sort();
          return result;
      };
      this.equal = function(left, right) {
          left = left == null ? [] : left;
          right = right == null ? [] : right;
          if (left.length !== right.length) return false;
          for (let i = 0; i < left.length; i++) {
              if (left[i] !== right[i]) return false;
          }
          return true;
      };
      this.notEqual = function(left, right) {
          return !this.equal(left, right);
      };
      this.size = function(collection) {
          return collection == null ? 0 : collection.length;
      };
      this.startsWith = function(collection, search, normalize) {
          if (collection == null || collection.length === 0) return false;
          let normalizedSearch = normalize ? TextLib.normalize(search) : BytesLib.normalize(search);
          return collection[0] === normalizedSearch;
      };
      this.endsWith = function(collection, search, normalize) {
          if (collection == null || collection.length === 0) return false;
          let normalizedSearch = normalize ? TextLib.normalize(search) : BytesLib.normalize(search);
          return collection[collection.length - 1] === normalizedSearch;
      };
      this.contains = function(collection, search, normalize) {
          if (collection == null || collection.length === 0) return false;
          return collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search));
      };
      this.containsAll = function(collection, searchArray, normalize) {
          if (collection == null || collection.length === 0 || searchArray == null || searchArray.length === 0) return false;
          return searchArray.every(search => collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search)));
      };
      this.containsAny = function(collection, searchArray, normalize) {
          if (collection == null || collection.length === 0 || searchArray == null || searchArray.length === 0) return false;
          return searchArray.some(search => collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search)));
      };
  }();
  var TextLib = new function () {
      this.normalize = function(arg) {
          return arg == null ? '' : arg.replace(/\s+/g, ' ').trim().toLowerCase();
      };
      this.isEmpty = function(arg) {
          return this.normalize(arg) == '';
      };
      this.isNotEmpty = function(arg) {
          return this.normalize(arg) != '';
      };
      this.equal = function(left, right) {
          return this.normalize(left) == this.normalize(right);
      };
      this.notEqual = function(left, right) {
          return this.normalize(left) != this.normalize(right);
      };
      this.startsWith = function(arg, substring) {
          return this.normalize(arg).startsWith(this.normalize(substring));
      };
      this.endsWith = function(arg, substring) {
          return this.normalize(arg).endsWith(this.normalize(substring));
      };
      this.contains = function(arg, substring) {
          return this.normalize(arg).includes(this.normalize(substring));
      };
      this.containsAll = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.every(sub => normalizedArg.includes(this.normalize(sub)));
      };
      this.containsAny = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.some(sub => normalizedArg.includes(this.normalize(sub)));
      };
  }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From AWS [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c);
      if (obj.CA10__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[1], conditionIndex:[100..199]
      function fieldChecked7() {
          if (TextLib.isEmpty(obj.CA10__availabilityZones__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__availabilityZones__c.isEmpty()", currentStateMessage: "Corrupted data. Availability zones should always present", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__availabilityZones__c;
      }
      function extract6() { if (!this.out) { this.out = fieldChecked7(); } return this.out; };
      function extract4() { if (!this.out) { this.out = CollectionLib.parse(extract6.call(extract6), '\n', true, true, true, true); } return this.out; };
      references1.push('Availability Zones [obj.CA10__availabilityZones__c]: ' + obj.CA10__availabilityZones__c);
      try {
          if (CollectionLib.size(extract4.call(extract4)) != null && 1.0 != null && CollectionLib.size(extract4.call(extract4)) <= 1.0) {
              return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('caSetFrom_availabilityZones__c').size() <= number(1.0)", currentStateMessage: "The Auto Scaling group is configured to use only one Availability Zone.", currentStateReferences: references1.join('\n'), remediation: "Modify the Auto Scaling group to include instances in at least two Availability Zones.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "The Auto Scaling group spans multiple Availability Zones.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;


  SELECT
    expectedResult.Id as Id,
    IF (
      IFNULL(expectedResult.expectedResult.status, '') = IFNULL(sObject.result.status, '')
      AND IFNULL(expectedResult.expectedResult.conditionIndex, -1) = IFNULL(sObject.result.conditionIndex, -1)
      AND IFNULL(expectedResult.expectedResult.conditionText, '') = IFNULL(sObject.result.conditionText, '')
      AND IFNULL(expectedResult.expectedResult.runtimeError, '') = IFNULL(sObject.result.runtimeError, ''),
      "MATCH",
      "FAIL"
    ) as match,
    expectedResult.expectedResult.status as expectedStatus, sObject.result.status as actualStatus,
    expectedResult.expectedResult.conditionIndex as expectedConditionIndex, sObject.result.conditionIndex as actualConditionIndex,
    expectedResult.expectedResult.conditionText as expectedConditionText, sObject.result.conditionText as actualConditionText,
    expectedResult.expectedResult.runtimeError as expectedRuntimeError, sObject.result.runtimeError as actualRuntimeError
  FROM UNNEST(mock_ExpectedResult()) expectedResult
  LEFT JOIN (
      SELECT
          sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__availabilityZones__c AS CA10__availabilityZones__c,
          sObject.Id AS Id,
          process_CA10__CaAwsAutoScalingGroup__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__availabilityZones__c AS CA10__availabilityZones__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsAutoScalingGroup__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
