---
policy: /ce/ca/google/sql/instance-backup
logic: /ce/ca/google/sql/instance-backup/prod.logic.yaml
executionTime: 2025-10-01T12:50:55.188424776Z
generationMs: 60
executionMs: 677
rows:
  - id: a8ED7
    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: a8E479
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__instanceType__c') == 'READ_REPLICA_INSTANCE'
      actual: extract('CA10__instanceType__c') == 'READ_REPLICA_INSTANCE'
    runtimeError: {}
  - id: a8E47
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__backupEnabled__c') == true && extract('CA10__backupStartTime__c').isNotEmpty()
      actual: extract('CA10__backupEnabled__c') == true && extract('CA10__backupStartTime__c').isNotEmpty()
    runtimeError: {}
  - id: a8ED77
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: a8E477
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/google/sql/instance-backup/policy.yaml
    md5Hash: 5574044F1AF67F40C9C15C52E7B98208
    content: "---\nnames: \n  full: \"Google Cloud SQL Instance Automated Backups\
      \ are not configured\"\n  contextual: \"Instance Automated Backups are not configured\"\
      \ndescription: \"It is recommended to have all SQL database instances set to\
      \ enable automated backups.\"\ntype: COMPLIANCE_POLICY\ncategories:\n  - \"\
      RELIABILITY\"\nframeworkMappings:\n  - /frameworks/cis-gcp-v3.0.0/06/07\n  -\
      \ /frameworks/cloudaware/resource-reliability/system-configuration\n  - /frameworks/nist-sp-800-53-r4/cp/09\n\
      \  - /frameworks/nist-sp-800-53-r5/cp/10\n  - /frameworks/nist-sp-800-53-r5/cp/09\n\
      \  - /frameworks/iso-iec-27001-2013/12/03/01\n  - /frameworks/iso-iec-27001-2022/08/13\n\
      \  - /frameworks/nist-csf-v1.1/pr-ip/04\nsimilarPolicies:\n  cloudConformity:\n\
      \    - url: \"https://www.trendmicro.com/cloudoneconformity-staging/knowledge-base/gcp/CloudSQL/enable-automated-backups.html\"\
      \n      name: \"Enable Automated Backups for Cloud SQL Database Instances\"\n"
  - path: /ce/ca/google/sql/instance-backup/prod.logic.yaml
    md5Hash: E93BE1007D3A97AE9D19F7807D547CF8
    content: |-
      ---

      inputType: "CA10__CaGoogleSqlInstance__c"
      testData:
        - file: test-data.json
      importExtracts:
        - file: /types/CA10__CaGoogleSqlInstance__c/object.extracts.yaml
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "GCP does not provide Automated Backups for read-replica instances."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__instanceType__c"
              right:
                TEXT: "READ_REPLICA_INSTANCE"
        - status: "COMPLIANT"
          currentStateMessage: "SQL instance automated backups are configured."
          check:
            AND:
              args:
                - IS_EQUAL:
                    left:
                      EXTRACT: "CA10__backupEnabled__c"
                    right:
                      BOOLEAN: true
                - NOT_EMPTY:
                    arg:
                      EXTRACT: CA10__backupStartTime__c
      otherwise:
        status: "INCOMPLIANT"
        currentStateMessage: "Automated backups disabled for the Cloud SQL database instance."
        remediationMessage: "Enable Automated backups for Cloud SQL database instance."
  - path: /ce/ca/google/sql/instance-backup/test-data.json
    md5Hash: 11D429AF5CA5FC83866E8FB964640319
    content: |
      [
        {
          "expectedResult": {
            "status": "DISAPPEARED",
            "conditionIndex": "99",
            "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-05T21:37:59Z" },
          "Id": "a8ED7",
          "CA10__disappearanceTime__c": "2023-12-06T13:34:16Z",
          "CA10__instanceType__c": "CLOUD_SQL_INSTANCE",
          "CA10__backupEnabled__c": true,
          "CA10__backupStartTime__c": "23:00"
        },
        {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "199",
            "conditionText": "extract('CA10__instanceType__c') == 'READ_REPLICA_INSTANCE'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-05T21:37:59Z" },
          "Id": "a8E479",
          "CA10__disappearanceTime__c": null,
          "CA10__instanceType__c": "READ_REPLICA_INSTANCE",
          "CA10__backupEnabled__c": true,
          "CA10__backupStartTime__c": "09:00"
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "299",
            "conditionText": "extract('CA10__backupEnabled__c') == true && extract('CA10__backupStartTime__c').isNotEmpty()",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-05T21:37:59Z" },
          "Id": "a8E47",
          "CA10__disappearanceTime__c": null,
          "CA10__instanceType__c": "CLOUD_SQL_INSTANCE",
          "CA10__backupEnabled__c": true,
          "CA10__backupStartTime__c": "09:00"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "300",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-05T21:37:59Z" },
          "Id": "a8ED77",
          "CA10__disappearanceTime__c": null,
          "CA10__instanceType__c": "CLOUD_SQL_INSTANCE",
          "CA10__backupEnabled__c": false,
          "CA10__backupStartTime__c": "00:00"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "300",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-05T21:37:59Z" },
          "Id": "a8E477",
          "CA10__disappearanceTime__c": null,
          "CA10__instanceType__c": "CLOUD_SQL_INSTANCE",
          "CA10__backupEnabled__c": true,
          "CA10__backupStartTime__c": ""
        }
      ]
  - path: /types/CA10__CaGoogleSqlInstance__c/object.extracts.yaml
    md5Hash: 8DD86EFB2FFA06BD1E9BC0452FF2EC8A
    content: "---\nextracts:\n  - name: \"CA10__databaseVersion__c\"\n    value: \n\
      \      FIELD:\n        path: \"CA10__databaseVersion__c\"\n        undeterminedIf:\n\
      \          isEmpty:  \"Database version should not be empty\"\n  - name: \"\
      CA10__ipv4Enabled__c\"\n    value: \n      FIELD:\n        path: \"CA10__ipv4Enabled__c\"\
      \n        undeterminedIf:\n          isEmpty:  \"Ipv4Enabled should not be empty\"\
      \n  - name: \"caJsonFrom__databaseFlagsJson__c\"\n    value: \n      JSON_FROM:\n\
      \        arg:\n          FIELD:\n            path: CA10__databaseFlagsJson__c\n\
      \            returnType: BYTES\n        undeterminedIf:\n          isInvalid:\
      \ \"Database Flags JSON is invalid.\"\n          isEmpty: \"Database Flags JSON\
      \ is empty.\"\n  - name: \"caJsonText__databaseFlagsSkipShowDatabaseFlagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'skip_show_database'].value[] |\
      \ [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n  - name: \"caJsonText__databaseFlagsLocalInfileFlagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'local_infile'].value[] | [0])\"\
      \n        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return text type.\"\
      \n  - name: \"caJsonText__databaseFlagsLogErrorVerbosityFlagValue__c\"\n   \
      \ value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression:  \"to_string([?name == 'log_error_verbosity'].value[]\
      \ | [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n  - name: \"caJsonText__databaseFlagsLogConnectionsFlagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'log_connections'].value[] | [0])\"\
      \n        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return text type.\"\
      \n  - name: \"caJsonText__databaseFlagsLogDisconnectionsFlagValue__c\"\n   \
      \ value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression:  \"to_string([?name == 'log_disconnections'].value[] |\
      \ [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n  - name: \"caJsonText__databaseFlagsLogStatementFlagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'log_statement'].value[] | [0])\"\
      \n        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return text type.\"\
      \n  - name: \"caJsonText__databaseFlagsLogMinMessagesFlagValue__c\"\n    value:\
      \ \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'log_min_messages'].value[] | [0])\"\
      \n        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return text type.\"\
      \n  - name: \"caJsonText__databaseFlagsLogMinErrorStatementFlagValue__c\"\n\
      \    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'log_min_error_statement'].value[]\
      \ | [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n  - name: \"caJsonText__databaseFlagsLogMinDurationStatementFlagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'log_min_duration_statement'].value[]\
      \ | [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n  - name: \"caJsonText__databaseFlagsCloudsqlEnablePgauditFlagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'cloudsql.enable_pgaudit'].value[]\
      \ | [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n  - name: \"caJsonText__databaseFlagsExternalScriptsEnabledFlagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'external scripts enabled'].value[]\
      \ | [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n  - name: \"caJsonText__databaseFlagsCrossDbOwnershipChainingFlagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'cross db ownership chaining'].value[]\
      \ | [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n\n  - name: \"caJsonText__databaseFlagsUserConnectionsFlagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'user connections'].value[] | [0])\"\
      \n        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return text type.\"\
      \n\n  - name: \"caJsonText__databaseFlagsUserOptionsFlagValue__c\"\n    value:\
      \ \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'user options'].value[] | [0])\"\
      \n        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return text type.\"\
      \n  - name: \"caJsonText__databaseFlagsRemoteAccessFlagValue__c\"\n    value:\
      \ \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'remote access'].value[] | [0])\"\
      \n        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return text type.\"\
      \n  - name: \"caJsonText__databaseFlags3625FlagValue__c\"\n    value: \n   \
      \   JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == '3625'].value[] | [0])\"\n     \
      \   undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return text type.\"\
      \n  - name: \"caJsonText__databaseFlagsContainedDatabaseAuthenticationFlagValue__c\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__databaseFlagsJson__c\"\
      \n        expression: \"to_string([?name == 'contained database authentication'].value[]\
      \ | [0])\"\n        undeterminedIf:\n          evaluationError: \"The JSON query\
      \ has failed.\"\n          resultTypeMismatch: \"The JSON query did not return\
      \ text type.\"\n  - name: \"CA10__authorizedNetworksJson__c\"\n    value: \n\
      \      FIELD:\n        path: \"CA10__authorizedNetworksJson__c\"\n        returnType:\
      \ BYTES\n  - name: \"caJsonFrom__authorizedNetworksJson__c\"\n    value: \n\
      \      JSON_FROM:\n        arg: \n          EXTRACT: \"CA10__authorizedNetworksJson__c\"\
      \n        undeterminedIf:\n          isInvalid: \"Authorized Networks JSON is\
      \ invalid.\"  \n  - name: \"caJsonText__authorizedNetworksJsonValue__c\"\n \
      \   value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__authorizedNetworksJson__c\"\
      \n        expression: \"to_string([].value)\"\n        undeterminedIf:\n   \
      \       evaluationError: \"The JSON query was failed.\"\n          resultTypeMismatch:\
      \ \"The JSON query did not return a text.\"\n  - name: \"CA10__instanceType__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__instanceType__c\"\n     \
      \   undeterminedIf:\n          isEmpty: \"Instance type should not be empty\"\
      \n  - name: \"CA10__backendType__c\"\n    value: \n      FIELD:\n        path:\
      \ \"CA10__backendType__c\"\n        undeterminedIf:\n          isEmpty: \"Backend\
      \ type should not be empty\"\n  - name: \"CA10__backupEnabled__c\"\n    value:\
      \ \n      FIELD:\n        path: \"CA10__backupEnabled__c\"\n        undeterminedIf:\n\
      \          isEmpty: \"Backup enabled should not be empty\"\n  - name: \"CA10__backupStartTime__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__backupStartTime__c\"\n  -\
      \ name: \"CA10__sslMode__c\"\n    value: \n      FIELD:\n        path: \"CA10__sslMode__c\"\
      \n  - name: \"CA10__createTime__c\"\n    value: \n      FIELD:\n        path:\
      \ \"CA10__createTime__c\"\n  - name: \"CA10__state__c\"\n    value: \n     \
      \ FIELD:\n        path: \"CA10__state__c\"\n  - name: \"CA10__cpuUtilizationAvg30Day__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__cpuUtilizationAvg30Day__c\"\
      \n  - name: \"CA10__memoryUtilizationAvg30Day__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10__memoryUtilizationAvg30Day__c\"\n  - name: \"CA10__diskReadIoOpsRate30Day__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__diskReadIoOpsRate30Day__c\"\
      \n  - name: \"CA10__diskWriteIoOpsRate30Day__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10__diskWriteIoOpsRate30Day__c\"\n  - name: \"CA10__cloudSqlConnectionsAvg30Day__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__cloudSqlConnectionsAvg30Day__c\"\
      \n# Text\n  - name: \"CA10__regionName__c\"\n    value: \n      FIELD:\n   \
      \     path: \"CA10__regionName__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" : "a8ED7",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "a8E479",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__instanceType__c') == 'READ_REPLICA_INSTANCE'",
      "runtimeError" : null
    }
  }, {
    "Id" : "a8E47",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__backupEnabled__c') == true && extract('CA10__backupStartTime__c').isNotEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "a8ED77",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "a8E477",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleSqlInstance__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__instanceType__c STRING,
      CA10__backupEnabled__c BOOLEAN,
      CA10__backupStartTime__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-09-05T21:37:59Z")
    },
    "Id" : "a8ED7",
    "CA10__disappearanceTime__c" : new Date("2023-12-06T13:34:16Z"),
    "CA10__instanceType__c" : "CLOUD_SQL_INSTANCE",
    "CA10__backupEnabled__c" : true,
    "CA10__backupStartTime__c" : "23:00"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-09-05T21:37:59Z")
    },
    "Id" : "a8E479",
    "CA10__instanceType__c" : "READ_REPLICA_INSTANCE",
    "CA10__backupEnabled__c" : true,
    "CA10__backupStartTime__c" : "09:00"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-09-05T21:37:59Z")
    },
    "Id" : "a8E47",
    "CA10__instanceType__c" : "CLOUD_SQL_INSTANCE",
    "CA10__backupEnabled__c" : true,
    "CA10__backupStartTime__c" : "09:00"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-09-05T21:37:59Z")
    },
    "Id" : "a8ED77",
    "CA10__instanceType__c" : "CLOUD_SQL_INSTANCE",
    "CA10__backupEnabled__c" : false,
    "CA10__backupStartTime__c" : "00:00"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-09-05T21:37:59Z")
    },
    "Id" : "a8E477",
    "CA10__instanceType__c" : "CLOUD_SQL_INSTANCE",
    "CA10__backupEnabled__c" : true,
    "CA10__backupStartTime__c" : ""
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaGoogleSqlInstance__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__instanceType__c STRING,
          CA10__backupEnabled__c BOOLEAN,
          CA10__backupStartTime__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));
          };
          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 IsEmptyLib = new function () {
          this.simpleIsEmpty = function(arg) {
              return arg == null;
          };
          this.simpleIsNotEmpty = function(arg) {
              return arg != null;
          };
      }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From Google [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__instanceType__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__instanceType__c.isEmpty()", currentStateMessage: "Instance type should not be empty", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__instanceType__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Instance Type [obj.CA10__instanceType__c]: ' + obj.CA10__instanceType__c);
      try {
          if (TextLib.equal(extract3.call(extract3), 'READ_REPLICA_INSTANCE')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__instanceType__c') == 'READ_REPLICA_INSTANCE'", currentStateMessage: "GCP does not provide Automated Backups for read-replica 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 fieldChecked7() {
          if (IsEmptyLib.simpleIsEmpty(obj.CA10__backupEnabled__c)) {
              throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "CA10__backupEnabled__c.isEmpty()", currentStateMessage: "Backup enabled should not be empty", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__backupEnabled__c;
      }
      function extract6() { if (!this.out) { this.out = fieldChecked7(); } return this.out; };
      function extract9() { if (!this.out) { this.out = obj.CA10__backupStartTime__c; } return this.out; };
      references1.push('Backup Enabled [obj.CA10__backupEnabled__c]: ' + obj.CA10__backupEnabled__c);
      references1.push('Backup Start Time [obj.CA10__backupStartTime__c]: ' + obj.CA10__backupStartTime__c);
      try {
          if (extract6.call(extract6) == true && TextLib.isNotEmpty(extract9.call(extract9))) {
              return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__backupEnabled__c') == true && extract('CA10__backupStartTime__c').isNotEmpty()", currentStateMessage: "SQL instance automated backups are configured.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'INCOMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "Automated backups disabled for the Cloud SQL database instance.", currentStateReferences: references1.join('\n'), remediation: "Enable Automated backups for Cloud SQL database instance.", 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__instanceType__c AS CA10__instanceType__c,
          sObject.CA10__backupEnabled__c AS CA10__backupEnabled__c,
          sObject.CA10__backupStartTime__c AS CA10__backupStartTime__c,
          process_CA10__CaGoogleSqlInstance__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__instanceType__c AS CA10__instanceType__c,
                  sObject.CA10__backupEnabled__c AS CA10__backupEnabled__c,
                  sObject.CA10__backupStartTime__c AS CA10__backupStartTime__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaGoogleSqlInstance__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
