---
policy: /ce/ca/google/compute-engine/disk-idle
logic: /ce/ca/google/compute-engine/disk-idle/prod.logic.yaml
executionTime: 2025-10-01T12:50:03.715038458Z
generationMs: 58
executionMs: 902
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: 199
      actual: 199
    conditionText:
      expected: extract('CA10__creationDate__c').withinLastDays(30)
      actual: extract('CA10__creationDate__c').withinLastDays(30)
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__lastAttach__c').isEmpty()
      actual: extract('CA10__lastAttach__c').isEmpty()
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: CA10__Google_GCE_Attached_Disks__r.has(INAPPLICABLE)
      actual: CA10__Google_GCE_Attached_Disks__r.has(INAPPLICABLE)
    runtimeError: {}
  - id: test5
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 499
      actual: 499
    conditionText:
      expected: CA10__Google_GCE_Attached_Disks__r.has(COMPLIANT)
      actual: CA10__Google_GCE_Attached_Disks__r.has(COMPLIANT)
    runtimeError: {}
  - id: test6
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 599
      actual: 599
    conditionText:
      expected: extract('CA10__lastDetach__c').isEmpty()
      actual: extract('CA10__lastDetach__c').isEmpty()
    runtimeError: {}
  - id: test7
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 699
      actual: 699
    conditionText:
      expected: extract('CA10__lastDetach__c').withinLastDays(30)
      actual: extract('CA10__lastDetach__c').withinLastDays(30)
    runtimeError: {}
  - id: test8
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 799
      actual: 799
    conditionText:
      expected: extract('CA10__lastDetach__c').beyondLastDays(30)
      actual: extract('CA10__lastDetach__c').beyondLastDays(30)
    runtimeError: {}
usedFiles:
  - path: /ce/ca/google/compute-engine/disk-idle/policy.yaml
    md5Hash: D6C0B14ABE4F1ACEFB50566BC5A16858
    content: |-
      ---
      names:
        full: Google GCE Disk is idle
        contextual: Disk is idle
      description: Identify persistent GCE Disks that haven't been attached to a GCE\
        \ Instance for more than 30 days.
      type: "COMPLIANCE_POLICY"
      categories:
        - "COST"
      frameworkMappings:
        - "/frameworks/cloudaware/cost-efficiency-and-optimization/waste-reduction"
  - path: /ce/ca/google/compute-engine/disk-idle/prod.logic.yaml
    md5Hash: 1071D65A2A3862710621592FFBD09BF4
    content: |
      ---
      inputType: "CA10__CaGoogleGceDisk__c"
      importExtracts:
        - file: "/types/CA10__CaGoogleGceDisk__c/object.extracts.yaml"
      testData:
        - file: 'test-data.json'
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "The Disk has been created less than 30 days ago."
          check:
            IS_WITHIN_LAST_DAYS:
              offsetDays: 30
              arg:
                EXTRACT: "CA10__creationDate__c"
        - status: "INCOMPLIANT"
          currentStateMessage: "The Disk hasn't been attached to a VM since creation."
          check:
            IS_EMPTY:
              arg:
                EXTRACT: "CA10__lastAttach__c"
        - status: "INAPPLICABLE"
          currentStateMessage: "The Disk is not persistent."
          check:
            RELATED_LIST_HAS:
              status: "INAPPLICABLE"
              relationshipName: "CA10__Google_GCE_Attached_Disks__r"
        - status: "COMPLIANT"
          currentStateMessage: "The Disk is attached to a VM."
          check:
            RELATED_LIST_HAS:
              status: "COMPLIANT"
              relationshipName: "CA10__Google_GCE_Attached_Disks__r"
        - status: "COMPLIANT"
          currentStateMessage: "The Disk is attached to a VM."
          check:
            IS_EMPTY:
              arg:
                EXTRACT: "CA10__lastDetach__c"
        - status: "COMPLIANT"
          currentStateMessage: "The Disk was detached within the last 30 days."
          check:
            IS_WITHIN_LAST_DAYS:
              offsetDays: 30
              arg:
                EXTRACT: "CA10__lastDetach__c"
        - status: "INCOMPLIANT"
          currentStateMessage: "The Disk was detached more than 30 days ago."
          check:
            IS_BEYOND_LAST_DAYS:
              offsetDays: 30
              arg:
                EXTRACT: "CA10__lastDetach__c"
      otherwise:
        status: "UNDETERMINED"
        currentStateMessage: "Unexpected values in the fields."
      relatedLists:
        - relationshipName: "CA10__Google_GCE_Attached_Disks__r"
          importExtracts:
            - file: "/types/CA10__CaGoogleGceAttachedDisk__c/object.extracts.yaml"
          conditions:
            - status: "INAPPLICABLE"
              currentStateMessage: "The Disk is not persistent."
              check:
                NOT_EQUAL:
                  left:
                    EXTRACT: "CA10__type__c"
                  right:
                    TEXT: "PERSISTENT"
          otherwise:
            status: "COMPLIANT"
            currentStateMessage: "The Disk is attached to a VM."
  - path: /ce/ca/google/compute-engine/disk-idle/test-data.json
    md5Hash: 5B19765F909ACAF7AD6494B7303A5AC5
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-09-21T23:29:57Z"
              },
              "Id": "test1",
              "CA10__disappearanceTime__c": "2025-09-12T15:57:37Z",
              "CA10__creationDate__c": "2025-09-12T05:15:44Z",
              "CA10__lastAttach__c": "2025-09-12T05:15:45Z",
              "CA10__lastDetach__c": null,
              "CA10__Google_GCE_Attached_Disks__r": [
                  {
                      "Id": "test1_1",
                      "CA10__disappearanceTime__c": "2025-09-12T15:50:23Z",
                      "CA10__type__c": "PERSISTENT",
                      "CA10__gceDisk__c": "test1"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__creationDate__c').withinLastDays(30)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-09-21T23:29:57Z"
              },
              "Id": "test2",
              "CA10__disappearanceTime__c": null,
              "CA10__creationDate__c": "2025-08-25T18:14:56Z",
              "CA10__lastAttach__c": "2025-08-25T18:14:57Z",
              "CA10__lastDetach__c": null,
              "CA10__Google_GCE_Attached_Disks__r": [
                  {
                      "Id": "test2_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__type__c": "PERSISTENT",
                      "CA10__gceDisk__c": "test2"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "extract('CA10__lastAttach__c').isEmpty()",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-09-21T23:29:57Z"
              },
              "Id": "test3",
              "CA10__disappearanceTime__c": null,
              "CA10__creationDate__c": "2024-08-25T18:14:56Z",
              "CA10__lastAttach__c": null,
              "CA10__lastDetach__c": null,
              "CA10__Google_GCE_Attached_Disks__r": [
                  {
                      "Id": "test3_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__type__c": "PERSISTENT",
                      "CA10__gceDisk__c": "test3"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "399",
                  "conditionText": "CA10__Google_GCE_Attached_Disks__r.has(INAPPLICABLE)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-09-21T23:29:57Z"
              },
              "Id": "test4",
              "CA10__disappearanceTime__c": null,
              "CA10__creationDate__c": "2024-08-25T18:14:56Z",
              "CA10__lastAttach__c": "2024-08-25T18:14:56Z",
              "CA10__lastDetach__c": null,
              "CA10__Google_GCE_Attached_Disks__r": [
                  {
                      "Id": "test4_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__type__c": "SCRATCH",
                      "CA10__gceDisk__c": "test4"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "499",
                  "conditionText": "CA10__Google_GCE_Attached_Disks__r.has(COMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-09-21T23:29:57Z"
              },
              "Id": "test5",
              "CA10__disappearanceTime__c": null,
              "CA10__creationDate__c": "2024-03-23T00:01:51Z",
              "CA10__lastAttach__c": "2024-03-23T00:13:09Z",
              "CA10__lastDetach__c": null,
              "CA10__Google_GCE_Attached_Disks__r": [
                  {
                      "Id": "test5_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__type__c": "PERSISTENT",
                      "CA10__gceDisk__c": "test5"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "599",
                  "conditionText": "extract('CA10__lastDetach__c').isEmpty()",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-09-21T23:29:57Z"
              },
              "Id": "test6",
              "CA10__disappearanceTime__c": null,
              "CA10__creationDate__c": "2024-03-23T00:01:51Z",
              "CA10__lastAttach__c": "2024-03-23T00:13:09Z",
              "CA10__lastDetach__c": null,
              "CA10__Google_GCE_Attached_Disks__r": []
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "699",
                  "conditionText": "extract('CA10__lastDetach__c').withinLastDays(30)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-09-21T23:29:57Z"
              },
              "Id": "test7",
              "CA10__disappearanceTime__c": null,
              "CA10__creationDate__c": "2025-03-17T13:03:10Z",
              "CA10__lastAttach__c": "2025-09-19T07:57:10Z",
              "CA10__lastDetach__c": "2025-09-19T07:57:20Z",
              "CA10__Google_GCE_Attached_Disks__r": []
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "799",
                  "conditionText": "extract('CA10__lastDetach__c').beyondLastDays(30)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-09-21T23:29:57Z"
              },
              "Id": "test8",
              "CA10__disappearanceTime__c": null,
              "CA10__creationDate__c": "2025-06-25T19:42:49Z",
              "CA10__lastAttach__c": "2025-06-25T19:42:54Z",
              "CA10__lastDetach__c": "2025-06-25T19:57:27Z",
              "CA10__Google_GCE_Attached_Disks__r": []
          }
      ]
  - path: /types/CA10__CaGoogleGceAttachedDisk__c/object.extracts.yaml
    md5Hash: C407407BDFFAF78A79682CE4D7011F10
    content: "---\nextracts:\n  - name: \"CA10__type__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10__type__c\""
  - path: /types/CA10__CaGoogleGceDisk__c/object.extracts.yaml
    md5Hash: F5FBF499DD82D232510DAAB4BE3A5BE9
    content: "---\nextracts:\n  - name: \"CA10__diskEncryptionKeySha256__c\"\n   \
      \ value: \n      FIELD:\n        path: \"CA10__diskEncryptionKeySha256__c\"\n\
      # Not nullable. Can't have no access, retrieved via compute.disks.aggregatedList\n\
      \  - name: \"CA10__creationDate__c\"\n    value: \n      FIELD:\n        path:\
      \ \"CA10__creationDate__c\"\n# Nullable. Can't have no access, retrieved via\
      \ compute.disks.aggregatedList\n  - name: \"CA10__lastAttach__c\"\n    value:\
      \ \n      FIELD:\n        path: \"CA10__lastAttach__c\"\n# Nullable. Can't have\
      \ no access, retrieved via compute.disks.aggregatedList\n  - name: \"CA10__lastDetach__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__lastDetach__c\"\n"
script: |-
  CREATE TEMP FUNCTION mock_ExpectedResult()
  RETURNS ARRAY<STRUCT<
          Id STRING,
          expectedResult STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, runtimeError STRING>
      >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "Id" : "test1",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__creationDate__c').withinLastDays(30)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__lastAttach__c').isEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "399",
      "conditionText" : "CA10__Google_GCE_Attached_Disks__r.has(INAPPLICABLE)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test5",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "499",
      "conditionText" : "CA10__Google_GCE_Attached_Disks__r.has(COMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test6",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "599",
      "conditionText" : "extract('CA10__lastDetach__c').isEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "test7",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "699",
      "conditionText" : "extract('CA10__lastDetach__c').withinLastDays(30)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test8",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "799",
      "conditionText" : "extract('CA10__lastDetach__c').beyondLastDays(30)",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleGceDisk__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__creationDate__c TIMESTAMP,
      CA10__lastAttach__c TIMESTAMP,
      CA10__lastDetach__c TIMESTAMP,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-09-21T23:29:57Z")
    },
    "Id" : "test1",
    "CA10__disappearanceTime__c" : new Date("2025-09-12T15:57:37Z"),
    "CA10__creationDate__c" : new Date("2025-09-12T05:15:44Z"),
    "CA10__lastAttach__c" : new Date("2025-09-12T05:15:45Z")
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-21T23:29:57Z")
    },
    "Id" : "test2",
    "CA10__creationDate__c" : new Date("2025-08-25T18:14:56Z"),
    "CA10__lastAttach__c" : new Date("2025-08-25T18:14:57Z")
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-21T23:29:57Z")
    },
    "Id" : "test3",
    "CA10__creationDate__c" : new Date("2024-08-25T18:14:56Z")
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-21T23:29:57Z")
    },
    "Id" : "test4",
    "CA10__creationDate__c" : new Date("2024-08-25T18:14:56Z"),
    "CA10__lastAttach__c" : new Date("2024-08-25T18:14:56Z")
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-21T23:29:57Z")
    },
    "Id" : "test5",
    "CA10__creationDate__c" : new Date("2024-03-23T00:01:51Z"),
    "CA10__lastAttach__c" : new Date("2024-03-23T00:13:09Z")
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-21T23:29:57Z")
    },
    "Id" : "test6",
    "CA10__creationDate__c" : new Date("2024-03-23T00:01:51Z"),
    "CA10__lastAttach__c" : new Date("2024-03-23T00:13:09Z")
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-21T23:29:57Z")
    },
    "Id" : "test7",
    "CA10__creationDate__c" : new Date("2025-03-17T13:03:10Z"),
    "CA10__lastAttach__c" : new Date("2025-09-19T07:57:10Z"),
    "CA10__lastDetach__c" : new Date("2025-09-19T07:57:20Z")
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-21T23:29:57Z")
    },
    "Id" : "test8",
    "CA10__creationDate__c" : new Date("2025-06-25T19:42:49Z"),
    "CA10__lastAttach__c" : new Date("2025-06-25T19:42:54Z"),
    "CA10__lastDetach__c" : new Date("2025-06-25T19:57:27Z")
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleGceAttachedDisk__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__type__c STRING,
      CA10__gceDisk__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-09-21T23:29:57Z")
    },
    "Id" : "test1_1",
    "CA10__disappearanceTime__c" : new Date("2025-09-12T15:50:23Z"),
    "CA10__type__c" : "PERSISTENT",
    "CA10__gceDisk__c" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-21T23:29:57Z")
    },
    "Id" : "test2_1",
    "CA10__type__c" : "PERSISTENT",
    "CA10__gceDisk__c" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-21T23:29:57Z")
    },
    "Id" : "test3_1",
    "CA10__type__c" : "PERSISTENT",
    "CA10__gceDisk__c" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-21T23:29:57Z")
    },
    "Id" : "test4_1",
    "CA10__type__c" : "SCRATCH",
    "CA10__gceDisk__c" : "test4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-21T23:29:57Z")
    },
    "Id" : "test5_1",
    "CA10__type__c" : "PERSISTENT",
    "CA10__gceDisk__c" : "test5"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaGoogleGceDisk__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__creationDate__c TIMESTAMP,
          CA10__lastAttach__c TIMESTAMP,
          CA10__lastDetach__c TIMESTAMP,
          CA10__Google_GCE_Attached_Disks__r ARRAY<STRUCT<
              Id STRING,
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__type__c STRING,
              CA10__gceDisk__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 todayMinus30Day = new Date(snapshotTime.toISOString().substr(0,10)+'T00:00:00.000Z').getTime() + (-30 * 86400000);
      var todayPlus1Day = new Date(snapshotTime.toISOString().substr(0,10)+'T00:00:00.000Z').getTime() + (1 * 86400000);
      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 extract3() { if (!this.out) { this.out = obj.CA10__creationDate__c; } return this.out; };
      references1.push('Creation Date [obj.CA10__creationDate__c]: ' + obj.CA10__creationDate__c);
      if (extract3.call(extract3) != null && extract3.call(extract3).getTime() >= todayMinus30Day && extract3.call(extract3).getTime() < todayPlus1Day) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__creationDate__c').withinLastDays(30)", currentStateMessage: "The Disk has been created less than 30 days ago.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract7() { if (!this.out) { this.out = obj.CA10__lastAttach__c; } return this.out; };
      references1.push('Last Attach [obj.CA10__lastAttach__c]: ' + obj.CA10__lastAttach__c);
      if (IsEmptyLib.simpleIsEmpty(extract7.call(extract7))) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__lastAttach__c').isEmpty()", currentStateMessage: "The Disk hasn't been attached to a VM since creation.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10__Google_GCE_Attached_Disks__r_INAPPLICABLE9 = 0;
      if (obj.CA10__Google_GCE_Attached_Disks__r != null) {
          for (var i10 = 0; i10 < obj.CA10__Google_GCE_Attached_Disks__r.length; i10++) {
              if (obj.CA10__Google_GCE_Attached_Disks__r[i10].result.status == 'INAPPLICABLE') {
                  count_CA10__Google_GCE_Attached_Disks__r_INAPPLICABLE9 += 1;
              }
          }
      }
      // condition[3], conditionIndex:[300..399]
      references1.push('Related list [CA10__Google_GCE_Attached_Disks__r] ' + (count_CA10__Google_GCE_Attached_Disks__r_INAPPLICABLE9 > 0 ? 'has' : 'does not have') + ' objects in INAPPLICABLE status');
      if (count_CA10__Google_GCE_Attached_Disks__r_INAPPLICABLE9 > 0) {
          return {status: 'INAPPLICABLE', conditionIndex: 399, conditionText: "CA10__Google_GCE_Attached_Disks__r.has(INAPPLICABLE)", currentStateMessage: "The Disk is not persistent.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10__Google_GCE_Attached_Disks__r_COMPLIANT11 = 0;
      if (obj.CA10__Google_GCE_Attached_Disks__r != null) {
          for (var i12 = 0; i12 < obj.CA10__Google_GCE_Attached_Disks__r.length; i12++) {
              if (obj.CA10__Google_GCE_Attached_Disks__r[i12].result.status == 'COMPLIANT') {
                  count_CA10__Google_GCE_Attached_Disks__r_COMPLIANT11 += 1;
              }
          }
      }
      // condition[4], conditionIndex:[400..499]
      if (count_CA10__Google_GCE_Attached_Disks__r_COMPLIANT11 > 0) {
          return {status: 'COMPLIANT', conditionIndex: 499, conditionText: "CA10__Google_GCE_Attached_Disks__r.has(COMPLIANT)", currentStateMessage: "The Disk is attached to a VM.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[5], conditionIndex:[500..599]
      function extract14() { if (!this.out) { this.out = obj.CA10__lastDetach__c; } return this.out; };
      references1.push('Last Detach [obj.CA10__lastDetach__c]: ' + obj.CA10__lastDetach__c);
      if (IsEmptyLib.simpleIsEmpty(extract14.call(extract14))) {
          return {status: 'COMPLIANT', conditionIndex: 599, conditionText: "extract('CA10__lastDetach__c').isEmpty()", currentStateMessage: "The Disk is attached to a VM.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[6], conditionIndex:[600..699]
      function extract17() { if (!this.out) { this.out = obj.CA10__lastDetach__c; } return this.out; };
      if (extract17.call(extract17) != null && extract17.call(extract17).getTime() >= todayMinus30Day && extract17.call(extract17).getTime() < todayPlus1Day) {
          return {status: 'COMPLIANT', conditionIndex: 699, conditionText: "extract('CA10__lastDetach__c').withinLastDays(30)", currentStateMessage: "The Disk was detached within the last 30 days.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[7], conditionIndex:[700..799]
      function extract21() { if (!this.out) { this.out = obj.CA10__lastDetach__c; } return this.out; };
      if (extract21.call(extract21) != null && extract21.call(extract21).getTime() < todayMinus30Day) {
          return {status: 'INCOMPLIANT', conditionIndex: 799, conditionText: "extract('CA10__lastDetach__c').beyondLastDays(30)", currentStateMessage: "The Disk was detached more than 30 days ago.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'UNDETERMINED', conditionIndex: 800, conditionText: "otherwise", currentStateMessage: "Unexpected values in the fields.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__Google_GCE_Attached_Disks__r(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__type__c STRING,
          CA10__gceDisk__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 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 extract3() { if (!this.out) { this.out = obj.CA10__type__c; } return this.out; };
      references1.push('Type [obj.CA10__type__c]: ' + obj.CA10__type__c);
      if (TextLib.notEqual(extract3.call(extract3), 'PERSISTENT')) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__type__c') != 'PERSISTENT'", currentStateMessage: "The Disk is not persistent.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "The Disk is attached to a VM.", 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__creationDate__c AS CA10__creationDate__c,
          sObject.CA10__lastAttach__c AS CA10__lastAttach__c,
          sObject.CA10__lastDetach__c AS CA10__lastDetach__c,
          `CA10__Google_GCE_Attached_Disks__r`.arr AS CA10__Google_GCE_Attached_Disks__r,
          process_CA10__CaGoogleGceDisk__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__creationDate__c AS CA10__creationDate__c,
                  sObject.CA10__lastAttach__c AS CA10__lastAttach__c,
                  sObject.CA10__lastDetach__c AS CA10__lastDetach__c,
                  `CA10__Google_GCE_Attached_Disks__r`.arr AS CA10__Google_GCE_Attached_Disks__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaGoogleGceDisk__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10__gceDisk__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__type__c AS CA10__type__c,
                      sObject.CA10__gceDisk__c AS CA10__gceDisk__c,
                      process_CA10__Google_GCE_Attached_Disks__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__type__c AS CA10__type__c,
                              sObject.CA10__gceDisk__c AS CA10__gceDisk__c
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaGoogleGceAttachedDisk__c()) AS sObject
          GROUP BY sObject.CA10__gceDisk__c
      ) AS `CA10__Google_GCE_Attached_Disks__r`
          ON sObject.Id = `CA10__Google_GCE_Attached_Disks__r`.CA10__gceDisk__c
  ) sObject ON sObject.Id = expectedResult.Id;
