---
policy: /ce/ca/aws/ec2/ebs-volume-underutilized
logic: /ce/ca/aws/ec2/ebs-volume-underutilized/prod.logic.yaml
executionTime: 2025-10-01T12:44:56.225207909Z
generationMs: 81
executionMs: 1159
rows:
  - id: '001'
    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: '002'
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__status__c') != 'in-use'
      actual: extract('CA10__status__c') != 'in-use'
    runtimeError: {}
  - id: '003'
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__createTime__c').withinLastDays(30)
      actual: extract('CA10__createTime__c').withinLastDays(30)
    runtimeError: {}
  - id: '004'
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: extract('CA10__attachmentAttachTime__c').isNotEmpty() && extract('CA10__attachmentAttachTime__c').withinLastDays(30)
      actual: extract('CA10__attachmentAttachTime__c').isNotEmpty() && extract('CA10__attachmentAttachTime__c').withinLastDays(30)
    runtimeError: {}
  - id: '005'
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 499
      actual: 499
    conditionText:
      expected: "not(setOfText(['gp3', 'io1', 'io2']).contains(extract('CA10__volumeType__c')))"
      actual: "not(setOfText(['gp3', 'io1', 'io2']).contains(extract('CA10__volumeType__c')))"
    runtimeError: {}
  - id: '006'
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 599
      actual: 599
    conditionText:
      expected: (extract('CA10__readOpsSum30d__c').isEmpty() && extract('CA10__writeOpsSum30d__c').isEmpty())
        || (extract('CA10__readOpsSum30d__c') == number(0.0) && extract('CA10__writeOpsSum30d__c')
        == number(0.0))
      actual: (extract('CA10__readOpsSum30d__c').isEmpty() && extract('CA10__writeOpsSum30d__c').isEmpty())
        || (extract('CA10__readOpsSum30d__c') == number(0.0) && extract('CA10__writeOpsSum30d__c')
        == number(0.0))
    runtimeError: {}
  - id: '007'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 699
      actual: 699
    conditionText:
      expected: extract('CA10__volumeType__c') == 'gp3' && extract('CA10__iops__c')
        > number(3000.0) && extract('CA10__readOpsSum30d__c') < number(1.944E9) &&
        extract('CA10__writeOpsSum30d__c') < number(1.944E9)
      actual: extract('CA10__volumeType__c') == 'gp3' && extract('CA10__iops__c')
        > number(3000.0) && extract('CA10__readOpsSum30d__c') < number(1.944E9) &&
        extract('CA10__writeOpsSum30d__c') < number(1.944E9)
    runtimeError: {}
  - id: '008'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 799
      actual: 799
    conditionText:
      expected: extract('CA10__volumeType__c') == 'gp3'
      actual: extract('CA10__volumeType__c') == 'gp3'
    runtimeError: {}
  - id: '009'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 899
      actual: 899
    conditionText:
      expected: extract('CA10__sumIopsOneMonth__c') < number(6.48E7)
      actual: extract('CA10__sumIopsOneMonth__c') < number(6.48E7)
    runtimeError: {}
  - id: '010'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 900
      actual: 900
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/ec2/ebs-volume-underutilized/policy.yaml
    md5Hash: 890E930ADCAA006EAD37F2FBC8C099AA
    content: "---\nnames:\n  full: \"AWS EBS Volume is underutilized\"\n  contextual:\
      \ \"EBS Volume is underutilized\"\ndescription: \"Identifies provisioned IOPS\
      \ EBS Volumes (gp3, io1, io2) with low read/write activity over the last 30\
      \ days\"\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n  - \"COST\"\n  - \"PERFORMANCE\"\
      \nframeworkMappings:\n  - \"/frameworks/cloudaware/cost-efficiency-and-optimization/resource-optimization\"\
      \n  - \"/frameworks/cloudaware/resource-performance/workload-efficiency\"  "
  - path: /ce/ca/aws/ec2/ebs-volume-underutilized/prod.logic.yaml
    md5Hash: BC4133702D80ED95D2C00E8655008C45
    content: "---\ninputType: \"CA10__CaAwsVolume__c\"\nimportExtracts:\n  - file:\
      \ \"/types/CA10__CaAwsVolume__c/object.extracts.yaml\"\ntestData:\n  - file:\
      \ 'test-data.json'\nconditions:\n  - status: \"INAPPLICABLE\"\n    currentStateMessage:\
      \ \"The EBS volume is not in-use.\"\n    check:\n      NOT_EQUAL:\n        left:\n\
      \          EXTRACT: \"CA10__status__c\"\n        right:\n          TEXT: \"\
      in-use\"\n  - status: \"INAPPLICABLE\"\n    currentStateMessage: \"The EBS volume\
      \ has been created less than 30 days ago.\"\n    check:\n      IS_WITHIN_LAST_DAYS:\n\
      \        offsetDays: 30\n        arg:\n          EXTRACT: \"CA10__createTime__c\"\
      \n  - status: \"INAPPLICABLE\"\n    currentStateMessage: \"The volume is attached\
      \ for less than 30 days.\"\n    check:\n      AND:\n        args:\n        -\
      \ NOT_EMPTY:\n            arg:\n              EXTRACT: \"CA10__attachmentAttachTime__c\"\
      \n        - IS_WITHIN_LAST_DAYS:\n            offsetDays: 30\n            arg:\n\
      \              EXTRACT: \"CA10__attachmentAttachTime__c\"\n  - status: \"INAPPLICABLE\"\
      \n    currentStateMessage: \"This policy checks only gp3, io1 and io2 volume\
      \ types.\"\n    check:\n      NOT:\n        arg:\n          CONTAINS:\n    \
      \        arg:\n              SET:\n                itemType: TEXT\n        \
      \        items:\n                  - \"gp3\"\n                  - \"io1\"\n\
      \                  - \"io2\"\n            search:\n              EXTRACT: \"\
      CA10__volumeType__c\"\n  - status: \"INAPPLICABLE\"\n    currentStateMessage:\
      \ \"The EBS volume is idle and considered by the 'AWS EBS volume is idle' policy.\"\
      \n    check:\n      OR:\n        args:\n          - AND:\n              args:\n\
      \                - IS_EMPTY:\n                    arg:\n                   \
      \   EXTRACT: \"CA10__readOpsSum30d__c\"\n                - IS_EMPTY:\n     \
      \               arg:\n                      EXTRACT: \"CA10__writeOpsSum30d__c\"\
      \n          - AND:\n              args:\n                - IS_EQUAL:\n     \
      \               left:\n                      EXTRACT: \"CA10__readOpsSum30d__c\"\
      \n                    right:\n                      NUMBER: 0.0\n          \
      \      - IS_EQUAL:\n                    left:\n                      EXTRACT:\
      \ \"CA10__writeOpsSum30d__c\"\n                    right:\n                \
      \      NUMBER: 0.0\n# The gp3 volume has provisioned IOPS above the free baseline\
      \ performance of 3,000 provisioned IOPS\n# Max operations per month for 3,000\
      \ IOPS is 7,776,000,000 (3,000 * 86,400 * 30); 1,944,000,000 is a 1/4 of that\
      \ value.\n# The volume is a good candidate to be downsized to the 3,000 IOPS\
      \ baseline\n  - status: INCOMPLIANT \n    currentStateMessage: \"The EBS Volume's\
      \ read and write operations for the past\\\n      \\ 30 days are less than the\
      \ set threshold of 1,944,000,000 operations per month.\"\n    remediationMessage:\
      \ \"Investigate the possibility to downsize the volume.\"\n    check:\n    \
      \  AND:\n        args:\n          - IS_EQUAL:\n              left:\n       \
      \         EXTRACT: \"CA10__volumeType__c\"\n              right:\n         \
      \       TEXT: \"gp3\"\n          - GREATER_THAN:\n              left:\n    \
      \            EXTRACT: \"CA10__iops__c\"\n              right:\n            \
      \    NUMBER: 3000.0\n          - LESS_THAN:\n              left:\n         \
      \       EXTRACT: \"CA10__readOpsSum30d__c\"\n              right:\n        \
      \        NUMBER: 1944000000.0\n          - LESS_THAN:\n              left:\n\
      \                EXTRACT: \"CA10__writeOpsSum30d__c\"\n              right:\n\
      \                NUMBER: 1944000000.0\n  - status: \"COMPLIANT\"\n    currentStateMessage:\
      \ \"The gp3 EBS Volume is not underutilized.\"\n    check:\n      IS_EQUAL:\n\
      \        left:\n          EXTRACT: \"CA10__volumeType__c\"\n        right:\n\
      \          TEXT: \"gp3\"\n# The io1 or io2 volume's minimum provisioned IOPS\
      \ is 100 IOPS\n# Max operations per month for 100 IOPS IOPS is 259,200,000 (100\
      \ * 86,400 * 30); 64,800,000 is a 1/4 of that value.\n# The volume is a good\
      \ candidate to be downsized.\n  - status: INCOMPLIANT # io1, io2\n    currentStateMessage:\
      \ \"The EBS Volume's sum of read and write operations for the past\\\n     \
      \ \\ 30 days are less than the set threshold of 64,800,000 operations per month.\"\
      \n    remediationMessage: \"Investigate the possibility to downsize the volume.\"\
      \n    check:\n      LESS_THAN:\n        left:\n          EXTRACT: \"CA10__sumIopsOneMonth__c\"\
      \n        right:\n          NUMBER: 64800000.0\notherwise:\n  status: \"COMPLIANT\"\
      \n  currentStateMessage: \"The EBS volume is not underutilized.\""
  - path: /ce/ca/aws/ec2/ebs-volume-underutilized/test-data.json
    md5Hash: 5A55A05F9E97BA20181A5E4320DFA5EC
    content: |
      [
        {
          "expectedResult": {
            "status": "DISAPPEARED",
            "conditionIndex": "99",
            "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-26T09:58:29Z" },
          "Id": "001",
          "CA10__disappearanceTime__c": "2025-09-26T00:12:00Z",
          "CA10__status__c": "in-use",
          "CA10__createTime__c": "2025-09-26T00:02:39Z",
          "CA10__attachmentAttachTime__c": "2025-09-26T00:02:39Z",
          "CA10__volumeType__c": "standard",
          "CA10__readOpsSum30d__c": null,
          "CA10__writeOpsSum30d__c": null,
          "CA10__iops__c": null,
          "CA10__sumIopsOneMonth__c": null
        },
        {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "199",
            "conditionText": "extract('CA10__status__c') != 'in-use'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-26T09:58:29Z" },
          "Id": "002",
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "error",
          "CA10__createTime__c": "2015-12-02T19:55:58Z",
          "CA10__attachmentAttachTime__c": null,
          "CA10__volumeType__c": "gp2",
          "CA10__readOpsSum30d__c": null,
          "CA10__writeOpsSum30d__c": null,
          "CA10__iops__c": 180,
          "CA10__sumIopsOneMonth__c": null
        },
        {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "299",
            "conditionText": "extract('CA10__createTime__c').withinLastDays(30)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-26T09:58:29Z" },
          "Id": "003",
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "in-use",
          "CA10__createTime__c": "2025-09-26T08:29:02Z",
          "CA10__attachmentAttachTime__c": "2025-09-26T08:29:02Z",
          "CA10__volumeType__c": "gp3",
          "CA10__readOpsSum30d__c": null,
          "CA10__writeOpsSum30d__c": null,
          "CA10__iops__c": 3000,
          "CA10__sumIopsOneMonth__c": null
        },
        {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "399",
            "conditionText": "extract('CA10__attachmentAttachTime__c').isNotEmpty() && extract('CA10__attachmentAttachTime__c').withinLastDays(30)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-26T09:58:29Z" },
          "Id": "004",
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "in-use",
          "CA10__createTime__c": "2019-09-18T15:48:09Z",
          "CA10__attachmentAttachTime__c": "2025-08-28T12:37:13Z",
          "CA10__volumeType__c": "gp2",
          "CA10__readOpsSum30d__c": 9526986,
          "CA10__writeOpsSum30d__c": 13737041,
          "CA10__iops__c": 150,
          "CA10__sumIopsOneMonth__c": null
        },
        {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "499",
            "conditionText": "not(setOfText(['gp3', 'io1', 'io2']).contains(extract('CA10__volumeType__c')))",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-26T09:58:29Z" },
          "Id": "005",
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "in-use",
          "CA10__createTime__c": "2020-10-08T12:34:21Z",
          "CA10__attachmentAttachTime__c": null,
          "CA10__volumeType__c": "gp2",
          "CA10__readOpsSum30d__c": null,
          "CA10__writeOpsSum30d__c": null,
          "CA10__iops__c": 120,
          "CA10__sumIopsOneMonth__c": null
        },
        {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "599",
            "conditionText": "(extract('CA10__readOpsSum30d__c').isEmpty() && extract('CA10__writeOpsSum30d__c').isEmpty()) || (extract('CA10__readOpsSum30d__c') == number(0.0) && extract('CA10__writeOpsSum30d__c') == number(0.0))",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-26T09:58:29Z" },
          "Id": "006",
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "in-use",
          "CA10__createTime__c": "2020-01-28T11:55:01Z",
          "CA10__attachmentAttachTime__c": null,
          "CA10__volumeType__c": "gp3",
          "CA10__readOpsSum30d__c": null,
          "CA10__writeOpsSum30d__c": null,
          "CA10__iops__c": 3000,
          "CA10__sumIopsOneMonth__c": null
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "699",
            "conditionText": "extract('CA10__volumeType__c') == 'gp3' && extract('CA10__iops__c') > number(3000.0) && extract('CA10__readOpsSum30d__c') < number(1.944E9) && extract('CA10__writeOpsSum30d__c') < number(1.944E9)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-26T09:58:29Z" },
          "Id": "007",
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "in-use",
          "CA10__createTime__c": "2021-02-15T12:37:18Z",
          "CA10__attachmentAttachTime__c": "2021-02-15T12:38:35Z",
          "CA10__volumeType__c": "gp3",
          "CA10__readOpsSum30d__c": 67365640,
          "CA10__writeOpsSum30d__c": 6558745,
          "CA10__iops__c": 3456,
          "CA10__sumIopsOneMonth__c": null
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "799",
            "conditionText": "extract('CA10__volumeType__c') == 'gp3'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-26T09:58:29Z" },
          "Id": "008",
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "in-use",
          "CA10__createTime__c": "2020-12-15T09:21:03Z",
          "CA10__attachmentAttachTime__c": "2020-12-15T09:21:03Z",
          "CA10__volumeType__c": "gp3",
          "CA10__readOpsSum30d__c": 15114936,
          "CA10__writeOpsSum30d__c": 8372773,
          "CA10__iops__c": 3000,
          "CA10__sumIopsOneMonth__c": null
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "899",
            "conditionText": "extract('CA10__sumIopsOneMonth__c') < number(6.48E7)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-26T09:58:29Z" },
          "Id": "009",
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "in-use",
          "CA10__createTime__c": "2020-12-15T09:21:03Z",
          "CA10__attachmentAttachTime__c": "2020-12-15T09:21:03Z",
          "CA10__volumeType__c": "io1",
          "CA10__readOpsSum30d__c": 15114936,
          "CA10__writeOpsSum30d__c": 8372773,
          "CA10__iops__c": 3000,
          "CA10__sumIopsOneMonth__c": 23487709
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "900",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-26T09:58:29Z" },
          "Id": "010",
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "in-use",
          "CA10__createTime__c": "2020-12-15T09:21:03Z",
          "CA10__attachmentAttachTime__c": "2020-12-15T09:21:03Z",
          "CA10__volumeType__c": "io1",
          "CA10__readOpsSum30d__c": 100000000,
          "CA10__writeOpsSum30d__c": 50000000,
          "CA10__iops__c": 3000,
          "CA10__sumIopsOneMonth__c": 150000000
        }
      ]
  - path: /types/CA10__CaAwsVolume__c/object.extracts.yaml
    md5Hash: D98F19A3E57995D503E82126277DD66A
    content: "# yaml-language-server: $schema=../../schema/Extracts.schema.json\n\
      ---\nextracts:\n# Values: creating | available | in-use | deleting | deleted\
      \ | error. Not nullable. Can't have no access, retrieved via ec2:DescribeVolumes\
      \ \n  - name: CA10__status__c\n    value:\n      FIELD: \n        path: CA10__status__c\n\
      # Checkbox\n  - name: CA10__encrypted__c\n    value:\n      FIELD: \n      \
      \  path: CA10__encrypted__c\n# Date/Time. Nullable\n  - name: CA10__attachmentAttachTime__c\n\
      \    value:\n      FIELD:\n        path: CA10__attachmentAttachTime__c\n# Number.\
      \ Nullable\n  - name: CA10__throughputPercentMax30d__c\n    value:\n      FIELD:\n\
      \        path: CA10__throughputPercentMax30d__c\n# Number. Nullable\n  - name:\
      \ CA10__readOpsSum30d__c\n    value:\n      FIELD:\n        path: CA10__readOpsSum30d__c\n\
      # Number. Nullable\n  - name: CA10__writeOpsSum30d__c\n    value:\n      FIELD:\n\
      \        path: CA10__writeOpsSum30d__c\n# Date/Time. Can't have no access, retrieved\
      \ via ec2:DescribeVolumes\n  - name: CA10__createTime__c\n    value:\n     \
      \ FIELD:\n        path: CA10__createTime__c\n# Number. Nullable\n  - name: CA10__iops__c\n\
      \    value:\n      FIELD:\n        path: CA10__iops__c\n# Number. Nullable\n\
      \  - name: CA10__sumIopsOneMonth__c\n    value:\n      FIELD:\n        path:\
      \ CA10__sumIopsOneMonth__c\n# Text.\n  - name: CA10__volumeType__c\n    value:\n\
      \      FIELD:\n        path: CA10__volumeType__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" : "001",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "002",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__status__c') != 'in-use'",
      "runtimeError" : null
    }
  }, {
    "Id" : "003",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__createTime__c').withinLastDays(30)",
      "runtimeError" : null
    }
  }, {
    "Id" : "004",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "399",
      "conditionText" : "extract('CA10__attachmentAttachTime__c').isNotEmpty() && extract('CA10__attachmentAttachTime__c').withinLastDays(30)",
      "runtimeError" : null
    }
  }, {
    "Id" : "005",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "499",
      "conditionText" : "not(setOfText(['gp3', 'io1', 'io2']).contains(extract('CA10__volumeType__c')))",
      "runtimeError" : null
    }
  }, {
    "Id" : "006",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "599",
      "conditionText" : "(extract('CA10__readOpsSum30d__c').isEmpty() && extract('CA10__writeOpsSum30d__c').isEmpty()) || (extract('CA10__readOpsSum30d__c') == number(0.0) && extract('CA10__writeOpsSum30d__c') == number(0.0))",
      "runtimeError" : null
    }
  }, {
    "Id" : "007",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "699",
      "conditionText" : "extract('CA10__volumeType__c') == 'gp3' && extract('CA10__iops__c') > number(3000.0) && extract('CA10__readOpsSum30d__c') < number(1.944E9) && extract('CA10__writeOpsSum30d__c') < number(1.944E9)",
      "runtimeError" : null
    }
  }, {
    "Id" : "008",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "799",
      "conditionText" : "extract('CA10__volumeType__c') == 'gp3'",
      "runtimeError" : null
    }
  }, {
    "Id" : "009",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "899",
      "conditionText" : "extract('CA10__sumIopsOneMonth__c') < number(6.48E7)",
      "runtimeError" : null
    }
  }, {
    "Id" : "010",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "900",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsVolume__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__status__c STRING,
      CA10__createTime__c TIMESTAMP,
      CA10__attachmentAttachTime__c TIMESTAMP,
      CA10__volumeType__c STRING,
      CA10__readOpsSum30d__c FLOAT64,
      CA10__writeOpsSum30d__c FLOAT64,
      CA10__iops__c FLOAT64,
      CA10__sumIopsOneMonth__c FLOAT64,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-09-26T09:58:29Z")
    },
    "Id" : "001",
    "CA10__disappearanceTime__c" : new Date("2025-09-26T00:12:00Z"),
    "CA10__status__c" : "in-use",
    "CA10__createTime__c" : new Date("2025-09-26T00:02:39Z"),
    "CA10__attachmentAttachTime__c" : new Date("2025-09-26T00:02:39Z"),
    "CA10__volumeType__c" : "standard",
    "CA10__readOpsSum30d__c" : null,
    "CA10__writeOpsSum30d__c" : null,
    "CA10__iops__c" : null,
    "CA10__sumIopsOneMonth__c" : null
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-26T09:58:29Z")
    },
    "Id" : "002",
    "CA10__status__c" : "error",
    "CA10__createTime__c" : new Date("2015-12-02T19:55:58Z"),
    "CA10__volumeType__c" : "gp2",
    "CA10__readOpsSum30d__c" : null,
    "CA10__writeOpsSum30d__c" : null,
    "CA10__iops__c" : 180,
    "CA10__sumIopsOneMonth__c" : null
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-26T09:58:29Z")
    },
    "Id" : "003",
    "CA10__status__c" : "in-use",
    "CA10__createTime__c" : new Date("2025-09-26T08:29:02Z"),
    "CA10__attachmentAttachTime__c" : new Date("2025-09-26T08:29:02Z"),
    "CA10__volumeType__c" : "gp3",
    "CA10__readOpsSum30d__c" : null,
    "CA10__writeOpsSum30d__c" : null,
    "CA10__iops__c" : 3000,
    "CA10__sumIopsOneMonth__c" : null
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-26T09:58:29Z")
    },
    "Id" : "004",
    "CA10__status__c" : "in-use",
    "CA10__createTime__c" : new Date("2019-09-18T15:48:09Z"),
    "CA10__attachmentAttachTime__c" : new Date("2025-08-28T12:37:13Z"),
    "CA10__volumeType__c" : "gp2",
    "CA10__readOpsSum30d__c" : 9526986,
    "CA10__writeOpsSum30d__c" : 13737041,
    "CA10__iops__c" : 150,
    "CA10__sumIopsOneMonth__c" : null
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-26T09:58:29Z")
    },
    "Id" : "005",
    "CA10__status__c" : "in-use",
    "CA10__createTime__c" : new Date("2020-10-08T12:34:21Z"),
    "CA10__volumeType__c" : "gp2",
    "CA10__readOpsSum30d__c" : null,
    "CA10__writeOpsSum30d__c" : null,
    "CA10__iops__c" : 120,
    "CA10__sumIopsOneMonth__c" : null
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-26T09:58:29Z")
    },
    "Id" : "006",
    "CA10__status__c" : "in-use",
    "CA10__createTime__c" : new Date("2020-01-28T11:55:01Z"),
    "CA10__volumeType__c" : "gp3",
    "CA10__readOpsSum30d__c" : null,
    "CA10__writeOpsSum30d__c" : null,
    "CA10__iops__c" : 3000,
    "CA10__sumIopsOneMonth__c" : null
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-26T09:58:29Z")
    },
    "Id" : "007",
    "CA10__status__c" : "in-use",
    "CA10__createTime__c" : new Date("2021-02-15T12:37:18Z"),
    "CA10__attachmentAttachTime__c" : new Date("2021-02-15T12:38:35Z"),
    "CA10__volumeType__c" : "gp3",
    "CA10__readOpsSum30d__c" : 67365640,
    "CA10__writeOpsSum30d__c" : 6558745,
    "CA10__iops__c" : 3456,
    "CA10__sumIopsOneMonth__c" : null
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-26T09:58:29Z")
    },
    "Id" : "008",
    "CA10__status__c" : "in-use",
    "CA10__createTime__c" : new Date("2020-12-15T09:21:03Z"),
    "CA10__attachmentAttachTime__c" : new Date("2020-12-15T09:21:03Z"),
    "CA10__volumeType__c" : "gp3",
    "CA10__readOpsSum30d__c" : 15114936,
    "CA10__writeOpsSum30d__c" : 8372773,
    "CA10__iops__c" : 3000,
    "CA10__sumIopsOneMonth__c" : null
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-26T09:58:29Z")
    },
    "Id" : "009",
    "CA10__status__c" : "in-use",
    "CA10__createTime__c" : new Date("2020-12-15T09:21:03Z"),
    "CA10__attachmentAttachTime__c" : new Date("2020-12-15T09:21:03Z"),
    "CA10__volumeType__c" : "io1",
    "CA10__readOpsSum30d__c" : 15114936,
    "CA10__writeOpsSum30d__c" : 8372773,
    "CA10__iops__c" : 3000,
    "CA10__sumIopsOneMonth__c" : 23487709
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-26T09:58:29Z")
    },
    "Id" : "010",
    "CA10__status__c" : "in-use",
    "CA10__createTime__c" : new Date("2020-12-15T09:21:03Z"),
    "CA10__attachmentAttachTime__c" : new Date("2020-12-15T09:21:03Z"),
    "CA10__volumeType__c" : "io1",
    "CA10__readOpsSum30d__c" : 100000000,
    "CA10__writeOpsSum30d__c" : 50000000,
    "CA10__iops__c" : 3000,
    "CA10__sumIopsOneMonth__c" : 150000000
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsVolume__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__status__c STRING,
          CA10__createTime__c TIMESTAMP,
          CA10__attachmentAttachTime__c TIMESTAMP,
          CA10__volumeType__c STRING,
          CA10__readOpsSum30d__c FLOAT64,
          CA10__writeOpsSum30d__c FLOAT64,
          CA10__iops__c FLOAT64,
          CA10__sumIopsOneMonth__c FLOAT64
      >,
      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 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 CollectionLib = new function () {
          this.parse = function(arg, separator, skipEmpty, skipDuplicates, sort, normalize) {
              if (arg == null) return [];
              let parts = arg.split(separator);
              return this.fromArray(parts, skipEmpty, skipDuplicates, sort, normalize);
          };
          this.fromArray = function(arr, skipEmpty, skipDuplicates, sort, normalize) {
              if (arr == null) return [];
              let result = [];
              let seen = new Set();
              arr.forEach(el => {
                  let normalized = normalize ? TextLib.normalize(el) : BytesLib.normalize(el);
                  if (!skipEmpty || (normalize ? TextLib.isNotEmpty(el) : BytesLib.isNotEmpty(el))) {
                      if (!skipDuplicates || !seen.has(normalized)) {
                          if (skipDuplicates) seen.add(normalized);
                          result.push(normalized);
                      }
                  }
              });
              if (sort) result.sort();
              return result;
          };
          this.equal = function(left, right) {
              left = left == null ? [] : left;
              right = right == null ? [] : right;
              if (left.length !== right.length) return false;
              for (let i = 0; i < left.length; i++) {
                  if (left[i] !== right[i]) return false;
              }
              return true;
          };
          this.notEqual = function(left, right) {
              return !this.equal(left, right);
          };
          this.size = function(collection) {
              return collection == null ? 0 : collection.length;
          };
          this.startsWith = function(collection, search, normalize) {
              if (collection == null || collection.length === 0) return false;
              let normalizedSearch = normalize ? TextLib.normalize(search) : BytesLib.normalize(search);
              return collection[0] === normalizedSearch;
          };
          this.endsWith = function(collection, search, normalize) {
              if (collection == null || collection.length === 0) return false;
              let normalizedSearch = normalize ? TextLib.normalize(search) : BytesLib.normalize(search);
              return collection[collection.length - 1] === normalizedSearch;
          };
          this.contains = function(collection, search, normalize) {
              if (collection == null || collection.length === 0) return false;
              return collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search));
          };
          this.containsAll = function(collection, searchArray, normalize) {
              if (collection == null || collection.length === 0 || searchArray == null || searchArray.length === 0) return false;
              return searchArray.every(search => collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search)));
          };
          this.containsAny = function(collection, searchArray, normalize) {
              if (collection == null || collection.length === 0 || searchArray == null || searchArray.length === 0) return false;
              return searchArray.some(search => collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search)));
          };
      }();
      var BytesLib = new function () {
          this.normalize = function(arg) {
              return arg == null ? '' : arg;
          };
          this.isEmpty = function(arg) {
              return this.normalize(arg) == '';
          };
          this.isNotEmpty = function(arg) {
              return this.normalize(arg) != '';
          };
          this.equal = function(left, right) {
              return this.normalize(left) == this.normalize(right);
          };
          this.notEqual = function(left, right) {
              return this.normalize(left) != this.normalize(right);
          };
          this.startsWith = function(arg, substring) {
              return this.normalize(arg).startsWith(this.normalize(substring));
          };
          this.endsWith = function(arg, substring) {
              return this.normalize(arg).endsWith(this.normalize(substring));
          };
          this.contains = function(arg, substring) {
              return this.normalize(arg).includes(this.normalize(substring));
          };
          this.containsAll = function(arg, substrings) {
              if (substrings == null || substrings.length === 0) return false;
              let normalizedArg = this.normalize(arg);
              return substrings.every(sub => normalizedArg.includes(this.normalize(sub)));
          };
          this.containsAny = function(arg, substrings) {
              if (substrings == null || substrings.length === 0) return false;
              let normalizedArg = this.normalize(arg);
              return substrings.some(sub => normalizedArg.includes(this.normalize(sub)));
          };
      }();
      var 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 extract3() { if (!this.out) { this.out = obj.CA10__status__c; } return this.out; };
      references1.push('Status [obj.CA10__status__c]: ' + obj.CA10__status__c);
      if (TextLib.notEqual(extract3.call(extract3), 'in-use')) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__status__c') != 'in-use'", currentStateMessage: "The EBS volume is not in-use.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10__createTime__c; } return this.out; };
      references1.push('Create Time [obj.CA10__createTime__c]: ' + obj.CA10__createTime__c);
      if (extract6.call(extract6) != null && extract6.call(extract6).getTime() >= todayMinus30Day && extract6.call(extract6).getTime() < todayPlus1Day) {
          return {status: 'INAPPLICABLE', conditionIndex: 299, conditionText: "extract('CA10__createTime__c').withinLastDays(30)", currentStateMessage: "The EBS volume has been created less than 30 days ago.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      function extract10() { if (!this.out) { this.out = obj.CA10__attachmentAttachTime__c; } return this.out; };
      references1.push('Attachment Attach Time [obj.CA10__attachmentAttachTime__c]: ' + obj.CA10__attachmentAttachTime__c);
      if (IsEmptyLib.simpleIsNotEmpty(extract10.call(extract10)) && (extract10.call(extract10) != null && extract10.call(extract10).getTime() >= todayMinus30Day && extract10.call(extract10).getTime() < todayPlus1Day)) {
          return {status: 'INAPPLICABLE', conditionIndex: 399, conditionText: "extract('CA10__attachmentAttachTime__c').isNotEmpty() && extract('CA10__attachmentAttachTime__c').withinLastDays(30)", currentStateMessage: "The volume is attached for less than 30 days.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[4], conditionIndex:[400..499]
      function extract15() { if (!this.out) { this.out = obj.CA10__volumeType__c; } return this.out; };
      references1.push('Volume Type [obj.CA10__volumeType__c]: ' + obj.CA10__volumeType__c);
      if (!CollectionLib.contains(CollectionLib.fromArray(['gp3', 'io1', 'io2'], true, true, true, true), extract15.call(extract15), true)) {
          return {status: 'INAPPLICABLE', conditionIndex: 499, conditionText: "not(setOfText(['gp3', 'io1', 'io2']).contains(extract('CA10__volumeType__c')))", currentStateMessage: "This policy checks only gp3, io1 and io2 volume types.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[5], conditionIndex:[500..599]
      function extract18() { if (!this.out) { this.out = obj.CA10__readOpsSum30d__c; } return this.out; };
      function extract21() { if (!this.out) { this.out = obj.CA10__writeOpsSum30d__c; } return this.out; };
      references1.push('CloudWatch: Read OPS Sum, 30-Day [obj.CA10__readOpsSum30d__c]: ' + obj.CA10__readOpsSum30d__c);
      references1.push('CloudWatch: Write OPS Sum, 30-Day [obj.CA10__writeOpsSum30d__c]: ' + obj.CA10__writeOpsSum30d__c);
      if ((IsEmptyLib.simpleIsEmpty(extract18.call(extract18)) && IsEmptyLib.simpleIsEmpty(extract21.call(extract21))) || (extract18.call(extract18) == 0.0 && extract21.call(extract21) == 0.0)) {
          return {status: 'INAPPLICABLE', conditionIndex: 599, conditionText: "(extract('CA10__readOpsSum30d__c').isEmpty() && extract('CA10__writeOpsSum30d__c').isEmpty()) || (extract('CA10__readOpsSum30d__c') == number(0.0) && extract('CA10__writeOpsSum30d__c') == number(0.0))", currentStateMessage: "The EBS volume is idle and considered by the 'AWS EBS volume is idle' policy.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[6], conditionIndex:[600..699]
      function extract26() { if (!this.out) { this.out = obj.CA10__volumeType__c; } return this.out; };
      function extract30() { if (!this.out) { this.out = obj.CA10__iops__c; } return this.out; };
      function extract34() { if (!this.out) { this.out = obj.CA10__readOpsSum30d__c; } return this.out; };
      function extract38() { if (!this.out) { this.out = obj.CA10__writeOpsSum30d__c; } return this.out; };
      references1.push('IOPS [obj.CA10__iops__c]: ' + obj.CA10__iops__c);
      if (TextLib.equal(extract26.call(extract26), 'gp3') && (extract30.call(extract30) != null && 3000.0 != null && extract30.call(extract30) > 3000.0) && (extract34.call(extract34) != null && 1.944E9 != null && extract34.call(extract34) < 1.944E9) && (extract38.call(extract38) != null && 1.944E9 != null && extract38.call(extract38) < 1.944E9)) {
          return {status: 'INCOMPLIANT', conditionIndex: 699, conditionText: "extract('CA10__volumeType__c') == 'gp3' && extract('CA10__iops__c') > number(3000.0) && extract('CA10__readOpsSum30d__c') < number(1.944E9) && extract('CA10__writeOpsSum30d__c') < number(1.944E9)", currentStateMessage: "The EBS Volume's read and write operations for the past 30 days are less than the set threshold of 1,944,000,000 operations per month.", currentStateReferences: references1.join('\n'), remediation: "Investigate the possibility to downsize the volume.", runtimeError: null};
      }
      // condition[7], conditionIndex:[700..799]
      function extract41() { if (!this.out) { this.out = obj.CA10__volumeType__c; } return this.out; };
      if (TextLib.equal(extract41.call(extract41), 'gp3')) {
          return {status: 'COMPLIANT', conditionIndex: 799, conditionText: "extract('CA10__volumeType__c') == 'gp3'", currentStateMessage: "The gp3 EBS Volume is not underutilized.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[8], conditionIndex:[800..899]
      function extract45() { if (!this.out) { this.out = obj.CA10__sumIopsOneMonth__c; } return this.out; };
      references1.push('CloudWatch: IOPS Sum, 30-Day [obj.CA10__sumIopsOneMonth__c]: ' + obj.CA10__sumIopsOneMonth__c);
      if (extract45.call(extract45) != null && 6.48E7 != null && extract45.call(extract45) < 6.48E7) {
          return {status: 'INCOMPLIANT', conditionIndex: 899, conditionText: "extract('CA10__sumIopsOneMonth__c') < number(6.48E7)", currentStateMessage: "The EBS Volume's sum of read and write operations for the past 30 days are less than the set threshold of 64,800,000 operations per month.", currentStateReferences: references1.join('\n'), remediation: "Investigate the possibility to downsize the volume.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 900, conditionText: "otherwise", currentStateMessage: "The EBS volume is not underutilized.", 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__status__c AS CA10__status__c,
          sObject.CA10__createTime__c AS CA10__createTime__c,
          sObject.CA10__attachmentAttachTime__c AS CA10__attachmentAttachTime__c,
          sObject.CA10__volumeType__c AS CA10__volumeType__c,
          sObject.CA10__readOpsSum30d__c AS CA10__readOpsSum30d__c,
          sObject.CA10__writeOpsSum30d__c AS CA10__writeOpsSum30d__c,
          sObject.CA10__iops__c AS CA10__iops__c,
          sObject.CA10__sumIopsOneMonth__c AS CA10__sumIopsOneMonth__c,
          process_CA10__CaAwsVolume__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__status__c AS CA10__status__c,
                  sObject.CA10__createTime__c AS CA10__createTime__c,
                  sObject.CA10__attachmentAttachTime__c AS CA10__attachmentAttachTime__c,
                  sObject.CA10__volumeType__c AS CA10__volumeType__c,
                  sObject.CA10__readOpsSum30d__c AS CA10__readOpsSum30d__c,
                  sObject.CA10__writeOpsSum30d__c AS CA10__writeOpsSum30d__c,
                  sObject.CA10__iops__c AS CA10__iops__c,
                  sObject.CA10__sumIopsOneMonth__c AS CA10__sumIopsOneMonth__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsVolume__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
