---
policy: /ce/ca/aws/account/iam-external-access-analyzer-for-all-regions
logic: /ce/ca/aws/account/iam-external-access-analyzer-for-all-regions/prod.logic.yaml
executionTime: 2025-04-24T23:44:08.494994346Z
rows:
  - id: test1
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test2
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10A1__AWS_IAM_Access_Analyzers__r.count(COMPLIANT) == CA10__AWS_Account_Regions__r.count(COMPLIANT)
      actual: CA10A1__AWS_IAM_Access_Analyzers__r.count(COMPLIANT) == CA10__AWS_Account_Regions__r.count(COMPLIANT)
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/account/iam-external-access-analyzer-for-all-regions/policy.yaml
    md5Hash: 60B6AA2A70CCCAB14C844CC20D1C6E6B
    content: |
      ---
      names:
        full: AWS Account IAM Access Analyzer is not enabled for all regions
        contextual: IAM Access Analyzer is not enabled for all regions
      description: "Enable IAM Access analyzer for IAM policies about all resources in each\
        \ active AWS region. IAM Access Analyzer is a technology introduced at AWS reinvent\
        \ 2019. After the Analyzer is enabled in IAM, scan results are displayed on the\
        \ console showing the accessible resources. Scans show resources that other accounts\
        \ and federated users can access, such as KMS keys and IAM roles. So the results\
        \ allow you to determine if an unintended user is allowed, making it easier for\
        \ administrators to monitor least privileges access. Access Analyzer analyzes only\
        \ policies that are applied to resources in the same AWS Region."
      type: COMPLIANCE_POLICY
      categories:
        - SECURITY
        - RELIABILITY
      frameworkMappings:
        - "/frameworks/cis-aws-v5.0.0/01/19"
        - "/frameworks/cloudaware/resource-security/secure-access"
        - "/frameworks/cloudaware/resource-reliability/system-configuration"
      similarPolicies:
        internal:
          - dec-x-ab7fc52e
        cloudConformity:
          - url: https://www.trendmicro.com/cloudoneconformity/knowledge-base/aws/IAM/access-analyzer-in-use.html
            name: IAM Access Analyzer in Use
  - path: /ce/ca/aws/account/iam-external-access-analyzer-for-all-regions/prod.logic.yaml
    md5Hash: 2C6E705582C8B0BA2E0960984E485181
    content: "---\ninputType: \"CA10__CaAwsAccount__c\"\ntestData:\n - file: test-data.json\n\
      importExtracts:\n  - file: /types/CA10__CaAwsAccount__c/object.extracts.yaml\n\
      conditions:\n  - status: \"COMPLIANT\"\n    currentStateMessage: \"IAM Access\
      \ analyzer is enabled for all regions.\"\n    check:\n          IS_EQUAL:\n\
      \            left:\n              RELATED_LIST_COUNT:\n                status:\
      \ \"COMPLIANT\"\n                relationshipName: \"CA10A1__AWS_IAM_Access_Analyzers__r\"\
      \n            right:\n              RELATED_LIST_COUNT:\n                status:\
      \ \"COMPLIANT\"\n                relationshipName: \"CA10__AWS_Account_Regions__r\"\
      \notherwise:\n  status: \"INCOMPLIANT\"\n  currentStateMessage: \"IAM Access\
      \ analyzer is not enabled for all regions.\"\n  remediationMessage: \"Configure\
      \ the IAM Access analyzer in each active region.\"\nrelatedLists:\n  - relationshipName:\
      \ \"CA10A1__AWS_IAM_Access_Analyzers__r\"\n    importExtracts:\n      - file:\
      \ /types/CA10A1__CaAwsIamAccessAnalyzer__c/object.extracts.yaml\n    conditions:\
      \      \n      - status: \"INAPPLICABLE\"\n        currentStateMessage: \"This\
      \ is not an External Access Analyzer.\"\n        check:\n          AND:\n  \
      \          args:\n              - NOT_EQUAL:\n                  left:\n    \
      \                EXTRACT: \"CA10A1__type__c\"\n                  right:\n  \
      \                  TEXT: \"ACCOUNT\"\n              - NOT_EQUAL:\n         \
      \         left:\n                    EXTRACT: \"CA10A1__type__c\"\n        \
      \          right:\n                    TEXT: \"ORGANIZATION\"\n      - status:\
      \ \"COMPLIANT\"\n        currentStateMessage: \"Active AWS IAM External Access\
      \ Analyzer.\"\n        check:\n            IS_EQUAL:\n              left:\n\
      \                EXTRACT: \"CA10A1__status__c\"\n              right:\n    \
      \            TEXT: \"ACTIVE\"\n    otherwise:\n      status: \"INAPPLICABLE\"\
      \n      currentStateMessage: \"There is no active AWS IAM External Access Analyzer.\"\
      \n  - relationshipName: \"CA10__AWS_Account_Regions__r\"\n    importExtracts:\n\
      \      - file: /types/CA10__CaAwsAccountRegion__c/object.extracts.yaml\n   \
      \ conditions:      \n    - status: \"COMPLIANT\"\n      currentStateMessage:\
      \ \"Active AWS Account Region.\"\n      check:\n          NOT_EQUAL:\n     \
      \       left:\n              EXTRACT: \"CA10__status__c\"\n            right:\n\
      \              TEXT: \"not-opted-in\"\n    otherwise:\n      status: \"INAPPLICABLE\"\
      \n      currentStateMessage: \"This AWS Account Region not active.\""
  - path: /types/CA10A1__CaAwsIamAccessAnalyzer__c/object.extracts.yaml
    md5Hash: 72D380FE6BF927AAF32782CD4F6277F7
    content: "---\nextracts:\n  - name: CA10A1__status__c\n    value:\n      FIELD:\
      \ \n        path: CA10A1__status__c\n        undeterminedIf:\n          isEmpty:\
      \ Possibly corrupted data. Status should not be empty.\n  - name: CA10A1__type__c\n\
      \    value:\n      FIELD: \n        path: CA10A1__type__c\n        undeterminedIf:\n\
      \          isEmpty: Possibly corrupted data. Type should not be empty."
  - path: /ce/ca/aws/account/iam-external-access-analyzer-for-all-regions/test-data.json
    md5Hash: 98EEF7F281AADBE8F102C11F1CDE7AB7
    content: |-
      [
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "200",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-07-10T20:44:00Z"
              },
              "Id": "test1",
              "CA10A1__AWS_IAM_Access_Analyzers__r": [
                  {
                      "Id": "test1_1",
                      "CA10A1__status__c": "ACTIVE",
                      "CA10A1__type__c": "ACCOUNT",
                      "CA10A1__account__c": "test1",
                      "CA10A1__disappearanceTime__c": null
                  }
              ],
              "CA10__AWS_Account_Regions__r": [
                  {
                      "Id": "test1_2",
                      "CA10__status__c": "opt-in-not-required",
                      "CA10__account__c": "test1"
                  },
                  {
                      "Id": "test1_3",
                      "CA10__status__c": "opt-in-not-required",
                      "CA10__account__c": "test1"
                  },
                  {
                      "Id": "test1_4",
                      "CA10__status__c": "opt-in-not-required",
                      "CA10__account__c": "test1"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "CA10A1__AWS_IAM_Access_Analyzers__r.count(COMPLIANT) == CA10__AWS_Account_Regions__r.count(COMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-07-10T20:44:00Z"
              },
              "Id": "test2",
              "CA10A1__AWS_IAM_Access_Analyzers__r": [
                  {
                      "Id": "test2_1",
                      "CA10A1__status__c": "ACTIVE",
                      "CA10A1__type__c": "ACCOUNT",
                      "CA10A1__account__c": "test2",
                      "CA10A1__disappearanceTime__c": null
                  },
                  {
                      "Id": "test2_2",
                      "CA10A1__status__c": "ACTIVE",
                      "CA10A1__type__c": "ACCOUNT",
                      "CA10A1__account__c": "test2",
                      "CA10A1__disappearanceTime__c": null
                  },
                  {
                      "Id": "test2_3",
                      "CA10A1__status__c": "ACTIVE",
                      "CA10A1__type__c": "ACCOUNT",
                      "CA10A1__account__c": "test2",
                      "CA10A1__disappearanceTime__c": null
                  }
              ],
              "CA10__AWS_Account_Regions__r": [
                  {
                      "Id": "test2_4",
                      "CA10__status__c": "opt-in-not-required",
                      "CA10__account__c": "test2"
                  },
                  {
                      "Id": "test2_5",
                      "CA10__status__c": "opt-in-not-required",
                      "CA10__account__c": "test2"
                  },
                  {
                      "Id": "test2_6",
                      "CA10__status__c": "opt-in-not-required",
                      "CA10__account__c": "test2"
                  }
              ]
          }
      ]
  - path: /types/CA10__CaAwsAccountRegion__c/object.extracts.yaml
    md5Hash: B5D54D4844B8E77238E14E730ABEE3C4
    content: "---\nextracts:\n  - name: CA10__status__c\n    value: \n      FIELD:\n\
      \        path: CA10__status__c\n        undeterminedIf:\n          isEmpty:\
      \ \"Account Region status must be specified \"\n  - name: CA10__ebsStorageEncryption__c\n\
      \    value: \n      FIELD:\n        path: CA10__ebsStorageEncryption__c\n  \
      \      undeterminedIf:\n          isEmpty: \"EBS Storage Encryption can not\
      \ be empty. Possibly corrupted data.\""
  - path: /types/CA10__CaAwsAccount__c/object.extracts.yaml
    md5Hash: FF575E27BEBAF3C8E85968E44798945B
    content: "---\nextracts:\n  - name: CA10__accountId__c\n    value: \n      FIELD:\n\
      \        path: CA10__accountId__c\n        undeterminedIf:\n          isEmpty:\
      \ \"Account ID can not be empty. Possibly corrupted data.\"\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" : "INCOMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "CA10A1__AWS_IAM_Access_Analyzers__r.count(COMPLIANT) == CA10__AWS_Account_Regions__r.count(COMPLIANT)",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsAccount__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "test2"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10A1__CaAwsIamAccessAnalyzer__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10A1__disappearanceTime__c TIMESTAMP,
      CA10A1__type__c STRING,
      CA10A1__status__c STRING,
      CA10A1__account__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "test1_1",
    "CA10A1__type__c" : "ACCOUNT",
    "CA10A1__status__c" : "ACTIVE",
    "CA10A1__account__c" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "test2_1",
    "CA10A1__type__c" : "ACCOUNT",
    "CA10A1__status__c" : "ACTIVE",
    "CA10A1__account__c" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "test2_2",
    "CA10A1__type__c" : "ACCOUNT",
    "CA10A1__status__c" : "ACTIVE",
    "CA10A1__account__c" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "test2_3",
    "CA10A1__type__c" : "ACCOUNT",
    "CA10A1__status__c" : "ACTIVE",
    "CA10A1__account__c" : "test2"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsAccountRegion__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__status__c STRING,
      CA10__account__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "test1_2",
    "CA10__status__c" : "opt-in-not-required",
    "CA10__account__c" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "test1_3",
    "CA10__status__c" : "opt-in-not-required",
    "CA10__account__c" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "test1_4",
    "CA10__status__c" : "opt-in-not-required",
    "CA10__account__c" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "test2_4",
    "CA10__status__c" : "opt-in-not-required",
    "CA10__account__c" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "test2_5",
    "CA10__status__c" : "opt-in-not-required",
    "CA10__account__c" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "test2_6",
    "CA10__status__c" : "opt-in-not-required",
    "CA10__account__c" : "test2"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsAccount__c(
      obj STRUCT<
          Id STRING,
          CA10A1__AWS_IAM_Access_Analyzers__r ARRAY<STRUCT<
              Id STRING,
              CA10A1__disappearanceTime__c TIMESTAMP,
              CA10A1__type__c STRING,
              CA10A1__status__c STRING,
              CA10A1__account__c STRING,
              result STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
          >>,
          CA10__AWS_Account_Regions__r ARRAY<STRUCT<
              Id STRING,
              CA10__status__c STRING,
              CA10__account__c STRING,
              result STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError 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 references1 = [];
      // condition[0], conditionIndex:[0..99]
      if (false) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared()", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10A1__AWS_IAM_Access_Analyzers__r_COMPLIANT2 = 0;
      if (obj.CA10A1__AWS_IAM_Access_Analyzers__r != null) {
          for (var i4 = 0; i4 < obj.CA10A1__AWS_IAM_Access_Analyzers__r.length; i4++) {
              if (obj.CA10A1__AWS_IAM_Access_Analyzers__r[i4].result.status == 'COMPLIANT') {
                  count_CA10A1__AWS_IAM_Access_Analyzers__r_COMPLIANT2 += 1;
              }
          }
      }
      var count_CA10__AWS_Account_Regions__r_COMPLIANT3 = 0;
      if (obj.CA10__AWS_Account_Regions__r != null) {
          for (var i5 = 0; i5 < obj.CA10__AWS_Account_Regions__r.length; i5++) {
              if (obj.CA10__AWS_Account_Regions__r[i5].result.status == 'COMPLIANT') {
                  count_CA10__AWS_Account_Regions__r_COMPLIANT3 += 1;
              }
          }
      }
      // condition[1], conditionIndex:[100..199]
      references1.push('Related list [CA10A1__AWS_IAM_Access_Analyzers__r] has ' + count_CA10A1__AWS_IAM_Access_Analyzers__r_COMPLIANT2 + ' objects in COMPLIANT status');
      references1.push('Related list [CA10__AWS_Account_Regions__r] has ' + count_CA10__AWS_Account_Regions__r_COMPLIANT3 + ' objects in COMPLIANT status');
      if (count_CA10A1__AWS_IAM_Access_Analyzers__r_COMPLIANT2 == count_CA10__AWS_Account_Regions__r_COMPLIANT3) {
          return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "CA10A1__AWS_IAM_Access_Analyzers__r.count(COMPLIANT) == CA10__AWS_Account_Regions__r.count(COMPLIANT)", currentStateMessage: "IAM Access analyzer is enabled for all regions.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'INCOMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "IAM Access analyzer is not enabled for all regions.", currentStateReferences: references1.join('\n'), remediation: "Configure the IAM Access analyzer in each active region.", runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10A1__AWS_IAM_Access_Analyzers__r(
      obj STRUCT<
          Id STRING,
          CA10A1__disappearanceTime__c TIMESTAMP,
          CA10A1__type__c STRING,
          CA10A1__status__c STRING,
          CA10A1__account__c 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 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));
          };
      }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From AWS [CA10A1__disappearanceTime__c]: ' + obj.CA10A1__disappearanceTime__c);
      if (obj.CA10A1__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10A1__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[1], conditionIndex:[100..199]
      function fieldChecked4() {
          if (TextLib.isEmpty(obj.CA10A1__type__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10A1__type__c.isEmpty()", currentStateMessage: "Possibly corrupted data. Type should not be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10A1__type__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Type [obj.CA10A1__type__c]: ' + obj.CA10A1__type__c);
      try {
          if (TextLib.notEqual(extract3.call(extract3), 'ACCOUNT') && TextLib.notEqual(extract3.call(extract3), 'ORGANIZATION')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10A1__type__c') != 'ACCOUNT' && extract('CA10A1__type__c') != 'ORGANIZATION'", currentStateMessage: "This is not an External Access Analyzer.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[2], conditionIndex:[200..299]
      function fieldChecked8() {
          if (TextLib.isEmpty(obj.CA10A1__status__c)) {
              throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "CA10A1__status__c.isEmpty()", currentStateMessage: "Possibly corrupted data. Status should not be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10A1__status__c;
      }
      function extract7() { if (!this.out) { this.out = fieldChecked8(); } return this.out; };
      references1.push('Status [obj.CA10A1__status__c]: ' + obj.CA10A1__status__c);
      try {
          if (TextLib.equal(extract7.call(extract7), 'ACTIVE')) {
              return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "extract('CA10A1__status__c') == 'ACTIVE'", currentStateMessage: "Active AWS IAM External Access Analyzer.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'INAPPLICABLE', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "There is no active AWS IAM External Access Analyzer.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__AWS_Account_Regions__r(
      obj STRUCT<
          Id STRING,
          CA10__status__c STRING,
          CA10__account__c 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 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));
          };
      }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      if (false) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared()", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[1], conditionIndex:[100..199]
      function fieldChecked4() {
          if (TextLib.isEmpty(obj.CA10__status__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__status__c.isEmpty()", currentStateMessage: "Account Region status must be specified ", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__status__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Status [obj.CA10__status__c]: ' + obj.CA10__status__c);
      try {
          if (TextLib.notEqual(extract3.call(extract3), 'not-opted-in')) {
              return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__status__c') != 'not-opted-in'", currentStateMessage: "Active AWS Account Region.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'INAPPLICABLE', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "This AWS Account Region not active.", 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.Id AS Id,
          `CA10A1__AWS_IAM_Access_Analyzers__r`.arr AS CA10A1__AWS_IAM_Access_Analyzers__r,
          `CA10__AWS_Account_Regions__r`.arr AS CA10__AWS_Account_Regions__r,
          process_CA10__CaAwsAccount__c(
              STRUCT(
                  sObject.Id AS Id,
                  `CA10A1__AWS_IAM_Access_Analyzers__r`.arr AS CA10A1__AWS_IAM_Access_Analyzers__r,
                  `CA10__AWS_Account_Regions__r`.arr AS CA10__AWS_Account_Regions__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsAccount__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10A1__account__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.CA10A1__disappearanceTime__c AS CA10A1__disappearanceTime__c,
                      sObject.CA10A1__type__c AS CA10A1__type__c,
                      sObject.CA10A1__status__c AS CA10A1__status__c,
                      sObject.CA10A1__account__c AS CA10A1__account__c,
                      process_CA10A1__AWS_IAM_Access_Analyzers__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.CA10A1__disappearanceTime__c AS CA10A1__disappearanceTime__c,
                              sObject.CA10A1__type__c AS CA10A1__type__c,
                              sObject.CA10A1__status__c AS CA10A1__status__c,
                              sObject.CA10A1__account__c AS CA10A1__account__c
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10A1__CaAwsIamAccessAnalyzer__c()) AS sObject
          GROUP BY sObject.CA10A1__account__c
      ) AS `CA10A1__AWS_IAM_Access_Analyzers__r`
          ON sObject.Id = `CA10A1__AWS_IAM_Access_Analyzers__r`.CA10A1__account__c
      LEFT JOIN (
          SELECT
              sObject.CA10__account__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.CA10__status__c AS CA10__status__c,
                      sObject.CA10__account__c AS CA10__account__c,
                      process_CA10__AWS_Account_Regions__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.CA10__status__c AS CA10__status__c,
                              sObject.CA10__account__c AS CA10__account__c
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaAwsAccountRegion__c()) AS sObject
          GROUP BY sObject.CA10__account__c
      ) AS `CA10__AWS_Account_Regions__r`
          ON sObject.Id = `CA10__AWS_Account_Regions__r`.CA10__account__c
  ) sObject ON sObject.Id = expectedResult.Id;
