---
policy: /ce/ca/aws/rds/aurora-cluster-access-consistency
logic: /ce/ca/aws/rds/aurora-cluster-access-consistency/prod.logic.yaml
executionTime: 2025-04-24T23:45:01.599496509Z
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: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: CA10__AWS_RDS_Instances__r.hasNo(COMPLIANT) && CA10__AWS_RDS_Instances__r.hasNo(INCOMPLIANT)
      actual: CA10__AWS_RDS_Instances__r.hasNo(COMPLIANT) && CA10__AWS_RDS_Instances__r.hasNo(INCOMPLIANT)
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: CA10__AWS_RDS_Instances__r.hasNo(COMPLIANT) && CA10__AWS_RDS_Instances__r.hasNo(INCOMPLIANT)
      actual: CA10__AWS_RDS_Instances__r.hasNo(COMPLIANT) && CA10__AWS_RDS_Instances__r.hasNo(INCOMPLIANT)
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 499
      actual: 499
    conditionText:
      expected: CA10__AWS_RDS_Instances__r.has(COMPLIANT) && CA10__AWS_RDS_Instances__r.hasNo(INCOMPLIANT)
      actual: CA10__AWS_RDS_Instances__r.has(COMPLIANT) && CA10__AWS_RDS_Instances__r.hasNo(INCOMPLIANT)
    runtimeError: {}
  - id: test5
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: CA10__AWS_RDS_Instances__r.has(INCOMPLIANT) && CA10__AWS_RDS_Instances__r.hasNo(COMPLIANT)
      actual: CA10__AWS_RDS_Instances__r.has(INCOMPLIANT) && CA10__AWS_RDS_Instances__r.hasNo(COMPLIANT)
    runtimeError: {}
  - id: test6
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 500
      actual: 500
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/rds/aurora-cluster-access-consistency/policy.yaml
    md5Hash: 79346DCB17FC324055AB6EBE1C389A72
    content: |+
      ---
      names:
        contextual: "Aurora Cluster access is not consistent"
        full: "AWS RDS Aurora Cluster access is not consistent"
      description: "Ensure that all the database instances within your Amazon Aurora clusters\
        \ have the same accessibility (either public or private) in order to follow AWS best practices."
      type: "COMPLIANCE_POLICY"
      categories:
        - "RELIABILITY"
        - "SECURITY"
      frameworkMappings:
        - "/frameworks/cloudaware/resource-reliability/system-configuration"
        - "/frameworks/cloudaware/resource-security/secure-access"
      similarPolicies:
        cloudConformity:
          - url: https://www.trendmicro.com/cloudoneconformity-staging/knowledge-base/aws/RDS/aurora-instance-accessibility.html
            name: Aurora Database Instance Accessibility
        awsTrustedAdvisor:
          - checkId: xuy7H1avtl
            name: Amazon Aurora DB Instance Accessibility
            url: https://docs.aws.amazon.com/awssupport/latest/user/fault-tolerance-checks.html#amazon-aurora-db-instance-accessibility

  - path: /ce/ca/aws/rds/aurora-cluster-access-consistency/prod.logic.yaml
    md5Hash: 86D3EF26A0994303F4006B88E8621D0F
    content: "---\ninputType: CA10__CaAwsDbCluster__c\nimportExtracts:\n  - file:\
      \ /types/CA10__CaAwsDbCluster__c/object.extracts.yaml\ntestData:\n  - file:\
      \ \"test-data.json\"\nconditions:\n  - status: INAPPLICABLE\n    currentStateMessage:\
      \ This Policy applies only to AWS RDS Aurora clusters.\n    check:\n      NOT:\n\
      \        arg:\n          STARTS_WITH:\n              arg:\n                EXTRACT:\
      \ CA10__engine__c\n              prefix:\n                TEXT: aurora\n  -\
      \ status: INAPPLICABLE\n    currentStateMessage: This AWS RDS Aurora cluster\
      \ has no related AWS RDS Instances.\n    check:\n      AND:\n        args:\n\
      \          - RELATED_LIST_HAS_NO:\n              relationshipName: CA10__AWS_RDS_Instances__r\n\
      \              status: COMPLIANT\n          - RELATED_LIST_HAS_NO:\n       \
      \       relationshipName: CA10__AWS_RDS_Instances__r\n              status:\
      \ INCOMPLIANT        \n  - status: COMPLIANT\n    currentStateMessage: This\
      \ AWS RDS Aurora cluster's accessibility is consistent. \n      All RDS Aurora\
      \ Instances within the cluster are publicly accessible.\n    check:\n      AND:\n\
      \        args:\n          - RELATED_LIST_HAS:\n              relationshipName:\
      \ CA10__AWS_RDS_Instances__r\n              status: INCOMPLIANT\n          -\
      \ RELATED_LIST_HAS_NO:\n              relationshipName: CA10__AWS_RDS_Instances__r\n\
      \              status: COMPLIANT              \n  - status: COMPLIANT\n    currentStateMessage:\
      \ This AWS RDS Aurora cluster's accessibility is consistent. \n      All RDS\
      \ Aurora Instances within the cluster are private.\n    check:\n      AND:\n\
      \        args:\n          - RELATED_LIST_HAS:\n              relationshipName:\
      \ CA10__AWS_RDS_Instances__r\n              status: COMPLIANT\n          - RELATED_LIST_HAS_NO:\n\
      \              relationshipName: CA10__AWS_RDS_Instances__r\n              status:\
      \ INCOMPLIANT               \notherwise:\n  status: INCOMPLIANT\n  currentStateMessage:\
      \ This AWS RDS Aurora cluster's accessibility is not consistent.\n  remediationMessage:\
      \ Consider modifying the accessibility of all AWS RDS Instances within the cluster\n\
      \    to be either public or private.\nrelatedLists:\n  - relationshipName: CA10__AWS_RDS_Instances__r\n\
      \    importExtracts:\n      - file: /types/CA10__CaAwsDbInstance__c/object.extracts.yaml\n\
      \    conditions:\n      - status: INAPPLICABLE\n        currentStateMessage:\
      \ This Policy applies only to AWS RDS Aurora Instances.\n        check:\n  \
      \        NOT:\n            arg:\n              STARTS_WITH:\n              \
      \  arg:\n                  EXTRACT: CA10__engine__c\n                prefix:\n\
      \                  TEXT: aurora\n      - status: INCOMPLIANT\n        currentStateMessage:\
      \ This AWS RDS Instance is publicly accessible.\n        remediationMessage:\
      \ N/A\n        check:\n          IS_EQUAL:\n            left:\n            \
      \  EXTRACT: CA10__publiclyAccessible__c\n            right:\n              BOOLEAN:\
      \ true \n    otherwise:\n      status: COMPLIANT\n      currentStateMessage:\
      \ This AWS RDS Instance is private."
  - path: /types/CA10__CaAwsDbCluster__c/object.extracts.yaml
    md5Hash: F3726ACA49C05970E0F328FFB5CAB41F
    content: |-
      ---
      extracts:
        - name: CA10__engine__c
          value:
            FIELD:
              path: CA10__engine__c
              undeterminedIf:
                # https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-clusters.html
                # "Engine" attribute represents a non-nullable string.
                isEmpty: DB Engine value cannot be empty. Potential data corruption.
  - path: /types/CA10__CaAwsDbInstance__c/object.extracts.yaml
    md5Hash: FF9B20D94B2A03C8B9A5C755DC5EF3A9
    content: "---\nextracts:\n# Not Nullable. Can't have no access, retrieved via\
      \ rds:DescribeDBInstances\n  - name: CA10__engine__c\n    value:\n      FIELD:\n\
      \        path: CA10__engine__c\n        undeterminedIf:\n          isEmpty:\
      \ \"Corrupted data. DB Instance Engine cannot be empty.\"\n# Not Nullable. Can't\
      \ have no access, retrieved via rds:DescribeDBInstances\n  - name: CA10__endpointPort__c\n\
      \    value:\n      FIELD:\n        path: CA10__endpointPort__c\n        undeterminedIf:\n\
      \          isEmpty: \"Corrupted data. DB Endpoint Port cannot be empty.\"\n\
      # Checkbox. Can't have no access, retrieved via rds:DescribeDBInstances\n  -\
      \ name: CA10__publiclyAccessible__c\n    value:\n      FIELD:\n        path:\
      \ CA10__publiclyAccessible__c\n# Checkbox. Can't have no access, retrieved via\
      \ rds:DescribeDBInstances\n  - name: CA10__storageEncrypted__c\n    value: \n\
      \      FIELD:\n        path: CA10__storageEncrypted__c\n# Checkbox. Can't have\
      \ no access, retrieved via rds:DescribeDBInstances\n  - name: CA10__autoMinorVersionUpgrade__c\n\
      \    value: \n      FIELD:\n        path: CA10__autoMinorVersionUpgrade__c\n\
      # Checkbox. Can't have no access, retrieved via rds:DescribeDBInstances\n  -\
      \ name: CA10__multiAz__c\n    value: \n      FIELD:\n        path: CA10__multiAz__c"
  - path: /ce/ca/aws/rds/aurora-cluster-access-consistency/test-data.json
    md5Hash: 32C9C07967A8FCAD575B495AB19FBB49
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-07-29T06:25:44Z"
              },
              "Id": "test1",
              "CA10__disappearanceTime__c": "2024-07-16T21:32:14Z",
              "CA10__engine__c": "aurora-mysql",
              "CA10__AWS_RDS_Instances__r": [
                  {
                      "Id": "test1_1",
                      "CA10__disappearanceTime__c": "2024-07-15T21:26:41Z",
                      "CA10__engine__c": "aurora-mysql",
                      "CA10__publiclyAccessible__c": false,
                      "CA10__cluster__c": "test1"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "299",
                  "conditionText": "CA10__AWS_RDS_Instances__r.hasNo(COMPLIANT) && CA10__AWS_RDS_Instances__r.hasNo(INCOMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-07-29T06:25:44Z"
              },
              "Id": "test2",
              "CA10__disappearanceTime__c": null,
              "CA10__engine__c": "aurora-mysql",
              "CA10__AWS_RDS_Instances__r": []
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "299",
                  "conditionText": "CA10__AWS_RDS_Instances__r.hasNo(COMPLIANT) && CA10__AWS_RDS_Instances__r.hasNo(INCOMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-07-29T06:25:44Z"
              },
              "Id": "test3",
              "CA10__disappearanceTime__c": null,
              "CA10__engine__c": "aurora-mysql",
              "CA10__AWS_RDS_Instances__r": [
                  {
                      "Id": "test3_1",
                      "CA10__disappearanceTime__c": "2024-07-15T21:26:41Z",
                      "CA10__engine__c": "aurora-mysql",
                      "CA10__publiclyAccessible__c": true,
                      "CA10__cluster__c": "test3"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "499",
                  "conditionText": "CA10__AWS_RDS_Instances__r.has(COMPLIANT) && CA10__AWS_RDS_Instances__r.hasNo(INCOMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-07-29T06:25:44Z"
              },
              "Id": "test4",
              "CA10__disappearanceTime__c": null,
              "CA10__engine__c": "aurora-mysql",
              "CA10__AWS_RDS_Instances__r": [
                  {
                      "Id": "test4_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__engine__c": "aurora-mysql",
                      "CA10__publiclyAccessible__c": false,
                      "CA10__cluster__c": "test4"
                  },
                  {
                      "Id": "test4_2",
                      "CA10__disappearanceTime__c": null,
                      "CA10__engine__c": "aurora-mysql",
                      "CA10__publiclyAccessible__c": false,
                      "CA10__cluster__c": "test4"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "399",
                  "conditionText": "CA10__AWS_RDS_Instances__r.has(INCOMPLIANT) && CA10__AWS_RDS_Instances__r.hasNo(COMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-07-29T06:25:44Z"
              },
              "Id": "test5",
              "CA10__disappearanceTime__c": null,
              "CA10__engine__c": "aurora-mysql",
              "CA10__AWS_RDS_Instances__r": [
                  {
                      "Id": "test5_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__engine__c": "aurora-mysql",
                      "CA10__publiclyAccessible__c": true,
                      "CA10__cluster__c": "test5"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "500",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-07-29T06:25:44Z"
              },
              "Id": "test6",
              "CA10__disappearanceTime__c": null,
              "CA10__engine__c": "aurora-mysql",
              "CA10__AWS_RDS_Instances__r": [
                  {
                      "Id": "test6_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__engine__c": "aurora-mysql",
                      "CA10__publiclyAccessible__c": true,
                      "CA10__cluster__c": "test6"
                  },
                  {
                      "Id": "test6_2",
                      "CA10__disappearanceTime__c": null,
                      "CA10__engine__c": "aurora-mysql",
                      "CA10__publiclyAccessible__c": false,
                      "CA10__cluster__c": "test6"
                  }
              ]
          }
      ]
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" : "INAPPLICABLE",
      "conditionIndex" : "299",
      "conditionText" : "CA10__AWS_RDS_Instances__r.hasNo(COMPLIANT) && CA10__AWS_RDS_Instances__r.hasNo(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "299",
      "conditionText" : "CA10__AWS_RDS_Instances__r.hasNo(COMPLIANT) && CA10__AWS_RDS_Instances__r.hasNo(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "499",
      "conditionText" : "CA10__AWS_RDS_Instances__r.has(COMPLIANT) && CA10__AWS_RDS_Instances__r.hasNo(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test5",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "CA10__AWS_RDS_Instances__r.has(INCOMPLIANT) && CA10__AWS_RDS_Instances__r.hasNo(COMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test6",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "500",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsDbCluster__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__engine__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-07-29T06:25:44Z")
    },
    "Id" : "test1",
    "CA10__disappearanceTime__c" : new Date("2024-07-16T21:32:14Z"),
    "CA10__engine__c" : "aurora-mysql"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-29T06:25:44Z")
    },
    "Id" : "test2",
    "CA10__engine__c" : "aurora-mysql"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-29T06:25:44Z")
    },
    "Id" : "test3",
    "CA10__engine__c" : "aurora-mysql"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-29T06:25:44Z")
    },
    "Id" : "test4",
    "CA10__engine__c" : "aurora-mysql"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-29T06:25:44Z")
    },
    "Id" : "test5",
    "CA10__engine__c" : "aurora-mysql"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-29T06:25:44Z")
    },
    "Id" : "test6",
    "CA10__engine__c" : "aurora-mysql"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsDbInstance__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__engine__c STRING,
      CA10__publiclyAccessible__c BOOLEAN,
      CA10__cluster__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-07-29T06:25:44Z")
    },
    "Id" : "test1_1",
    "CA10__disappearanceTime__c" : new Date("2024-07-15T21:26:41Z"),
    "CA10__engine__c" : "aurora-mysql",
    "CA10__publiclyAccessible__c" : false,
    "CA10__cluster__c" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-29T06:25:44Z")
    },
    "Id" : "test3_1",
    "CA10__disappearanceTime__c" : new Date("2024-07-15T21:26:41Z"),
    "CA10__engine__c" : "aurora-mysql",
    "CA10__publiclyAccessible__c" : true,
    "CA10__cluster__c" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-29T06:25:44Z")
    },
    "Id" : "test4_1",
    "CA10__engine__c" : "aurora-mysql",
    "CA10__publiclyAccessible__c" : false,
    "CA10__cluster__c" : "test4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-29T06:25:44Z")
    },
    "Id" : "test4_2",
    "CA10__engine__c" : "aurora-mysql",
    "CA10__publiclyAccessible__c" : false,
    "CA10__cluster__c" : "test4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-29T06:25:44Z")
    },
    "Id" : "test5_1",
    "CA10__engine__c" : "aurora-mysql",
    "CA10__publiclyAccessible__c" : true,
    "CA10__cluster__c" : "test5"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-29T06:25:44Z")
    },
    "Id" : "test6_1",
    "CA10__engine__c" : "aurora-mysql",
    "CA10__publiclyAccessible__c" : true,
    "CA10__cluster__c" : "test6"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-29T06:25:44Z")
    },
    "Id" : "test6_2",
    "CA10__engine__c" : "aurora-mysql",
    "CA10__publiclyAccessible__c" : false,
    "CA10__cluster__c" : "test6"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsDbCluster__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__engine__c STRING,
          CA10__AWS_RDS_Instances__r ARRAY<STRUCT<
              Id STRING,
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__engine__c STRING,
              CA10__publiclyAccessible__c BOOLEAN,
              CA10__cluster__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 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 [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 fieldChecked4() {
          if (TextLib.isEmpty(obj.CA10__engine__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__engine__c.isEmpty()", currentStateMessage: "DB Engine value cannot be empty. Potential data corruption.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__engine__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Engine [obj.CA10__engine__c]: ' + obj.CA10__engine__c);
      try {
          if (!TextLib.startsWith(extract3.call(extract3), 'aurora')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "not(extract('CA10__engine__c').startsWith('aurora'))", currentStateMessage: "This Policy applies only to AWS RDS Aurora clusters.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      var count_CA10__AWS_RDS_Instances__r_COMPLIANT5 = 0;
      var count_CA10__AWS_RDS_Instances__r_INCOMPLIANT6 = 0;
      if (obj.CA10__AWS_RDS_Instances__r != null) {
          for (var i7 = 0; i7 < obj.CA10__AWS_RDS_Instances__r.length; i7++) {
              if (obj.CA10__AWS_RDS_Instances__r[i7].result.status == 'COMPLIANT') {
                  count_CA10__AWS_RDS_Instances__r_COMPLIANT5 += 1;
              }
              if (obj.CA10__AWS_RDS_Instances__r[i7].result.status == 'INCOMPLIANT') {
                  count_CA10__AWS_RDS_Instances__r_INCOMPLIANT6 += 1;
              }
          }
      }
      // condition[2], conditionIndex:[200..299]
      references1.push('Related list [CA10__AWS_RDS_Instances__r] ' + (count_CA10__AWS_RDS_Instances__r_COMPLIANT5 == 0 ? 'does not have' : 'has') + ' objects in COMPLIANT status');
      if (count_CA10__AWS_RDS_Instances__r_COMPLIANT5 == 0 && count_CA10__AWS_RDS_Instances__r_INCOMPLIANT6 == 0) {
          return {status: 'INAPPLICABLE', conditionIndex: 299, conditionText: "CA10__AWS_RDS_Instances__r.hasNo(COMPLIANT) && CA10__AWS_RDS_Instances__r.hasNo(INCOMPLIANT)", currentStateMessage: "This AWS RDS Aurora cluster has no related AWS RDS Instances.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10__AWS_RDS_Instances__r_INCOMPLIANT6 = 0;
      var count_CA10__AWS_RDS_Instances__r_COMPLIANT5 = 0;
      if (obj.CA10__AWS_RDS_Instances__r != null) {
          for (var i8 = 0; i8 < obj.CA10__AWS_RDS_Instances__r.length; i8++) {
              if (obj.CA10__AWS_RDS_Instances__r[i8].result.status == 'INCOMPLIANT') {
                  count_CA10__AWS_RDS_Instances__r_INCOMPLIANT6 += 1;
              }
              if (obj.CA10__AWS_RDS_Instances__r[i8].result.status == 'COMPLIANT') {
                  count_CA10__AWS_RDS_Instances__r_COMPLIANT5 += 1;
              }
          }
      }
      // condition[3], conditionIndex:[300..399]
      if (count_CA10__AWS_RDS_Instances__r_INCOMPLIANT6 > 0 && count_CA10__AWS_RDS_Instances__r_COMPLIANT5 == 0) {
          return {status: 'COMPLIANT', conditionIndex: 399, conditionText: "CA10__AWS_RDS_Instances__r.has(INCOMPLIANT) && CA10__AWS_RDS_Instances__r.hasNo(COMPLIANT)", currentStateMessage: "This AWS RDS Aurora cluster's accessibility is consistent. All RDS Aurora Instances within the cluster are publicly accessible.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10__AWS_RDS_Instances__r_COMPLIANT5 = 0;
      var count_CA10__AWS_RDS_Instances__r_INCOMPLIANT6 = 0;
      if (obj.CA10__AWS_RDS_Instances__r != null) {
          for (var i9 = 0; i9 < obj.CA10__AWS_RDS_Instances__r.length; i9++) {
              if (obj.CA10__AWS_RDS_Instances__r[i9].result.status == 'COMPLIANT') {
                  count_CA10__AWS_RDS_Instances__r_COMPLIANT5 += 1;
              }
              if (obj.CA10__AWS_RDS_Instances__r[i9].result.status == 'INCOMPLIANT') {
                  count_CA10__AWS_RDS_Instances__r_INCOMPLIANT6 += 1;
              }
          }
      }
      // condition[4], conditionIndex:[400..499]
      if (count_CA10__AWS_RDS_Instances__r_COMPLIANT5 > 0 && count_CA10__AWS_RDS_Instances__r_INCOMPLIANT6 == 0) {
          return {status: 'COMPLIANT', conditionIndex: 499, conditionText: "CA10__AWS_RDS_Instances__r.has(COMPLIANT) && CA10__AWS_RDS_Instances__r.hasNo(INCOMPLIANT)", currentStateMessage: "This AWS RDS Aurora cluster's accessibility is consistent. All RDS Aurora Instances within the cluster are private.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'INCOMPLIANT', conditionIndex: 500, conditionText: "otherwise", currentStateMessage: "This AWS RDS Aurora cluster's accessibility is not consistent.", currentStateReferences: references1.join('\n'), remediation: "Consider modifying the accessibility of all AWS RDS Instances within the cluster to be either public or private.", runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__AWS_RDS_Instances__r(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__engine__c STRING,
          CA10__publiclyAccessible__c BOOLEAN,
          CA10__cluster__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 [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 fieldChecked4() {
          if (TextLib.isEmpty(obj.CA10__engine__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__engine__c.isEmpty()", currentStateMessage: "Corrupted data. DB Instance Engine cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__engine__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Engine [obj.CA10__engine__c]: ' + obj.CA10__engine__c);
      try {
          if (!TextLib.startsWith(extract3.call(extract3), 'aurora')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "not(extract('CA10__engine__c').startsWith('aurora'))", currentStateMessage: "This Policy applies only to AWS RDS Aurora Instances.", 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 extract6() { if (!this.out) { this.out = obj.CA10__publiclyAccessible__c; } return this.out; };
      references1.push('Publicly Accessible [obj.CA10__publiclyAccessible__c]: ' + obj.CA10__publiclyAccessible__c);
      if (extract6.call(extract6) == true) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__publiclyAccessible__c') == true", currentStateMessage: "This AWS RDS Instance is publicly accessible.", currentStateReferences: references1.join('\n'), remediation: "N/A", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "This AWS RDS Instance is private.", 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,
          sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__engine__c AS CA10__engine__c,
          `CA10__AWS_RDS_Instances__r`.arr AS CA10__AWS_RDS_Instances__r,
          process_CA10__CaAwsDbCluster__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__engine__c AS CA10__engine__c,
                  `CA10__AWS_RDS_Instances__r`.arr AS CA10__AWS_RDS_Instances__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsDbCluster__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10__cluster__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__engine__c AS CA10__engine__c,
                      sObject.CA10__publiclyAccessible__c AS CA10__publiclyAccessible__c,
                      sObject.CA10__cluster__c AS CA10__cluster__c,
                      process_CA10__AWS_RDS_Instances__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__engine__c AS CA10__engine__c,
                              sObject.CA10__publiclyAccessible__c AS CA10__publiclyAccessible__c,
                              sObject.CA10__cluster__c AS CA10__cluster__c
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaAwsDbInstance__c()) AS sObject
          GROUP BY sObject.CA10__cluster__c
      ) AS `CA10__AWS_RDS_Instances__r`
          ON sObject.Id = `CA10__AWS_RDS_Instances__r`.CA10__cluster__c
  ) sObject ON sObject.Id = expectedResult.Id;
