---
policy: /ce/ca/aws/ec2/ebs-volume-idle
logic: /ce/ca/aws/ec2/ebs-volume-idle/prod.logic.yaml
executionTime: 2025-10-01T12:44:54.941306871Z
generationMs: 56
executionMs: 605
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') != 'available' && extract('CA10__status__c')
        != 'in-use'
      actual: extract('CA10__status__c') != 'available' && 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: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: extract('CA10__status__c') == 'available' && extract('CA10__readOpsSum30d__c').isEmpty()
        && extract('CA10__writeOpsSum30d__c').isEmpty()
      actual: extract('CA10__status__c') == 'available' && extract('CA10__readOpsSum30d__c').isEmpty()
        && extract('CA10__writeOpsSum30d__c').isEmpty()
    runtimeError: {}
  - id: '005'
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 499
      actual: 499
    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: '006'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 599
      actual: 599
    conditionText:
      expected: extract('CA10__status__c') == 'in-use' && extract('CA10__readOpsSum30d__c').isEmpty()
        && extract('CA10__writeOpsSum30d__c').isEmpty()
      actual: extract('CA10__status__c') == 'in-use' && extract('CA10__readOpsSum30d__c').isEmpty()
        && extract('CA10__writeOpsSum30d__c').isEmpty()
    runtimeError: {}
  - id: '007'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 699
      actual: 699
    conditionText:
      expected: extract('CA10__status__c') == 'in-use' && extract('CA10__readOpsSum30d__c')
        == number(0.0) && extract('CA10__writeOpsSum30d__c') == number(0.0)
      actual: extract('CA10__status__c') == 'in-use' && extract('CA10__readOpsSum30d__c')
        == number(0.0) && extract('CA10__writeOpsSum30d__c') == number(0.0)
    runtimeError: {}
  - id: '008'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 700
      actual: 700
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: '009'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 700
      actual: 700
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/ec2/ebs-volume-idle/policy.yaml
    md5Hash: C8569F45BC0DB58031F8C89413C122A8
    content: "---\nnames:\n  full: AWS EBS Volume is idle\n  contextual: EBS Volume\
      \ is idle\ndescription: \"This policy flags AWS EBS Volumes that are either\
      \ unattached for\\ \n  \\ more than 30 days or attached but show no read/write\
      \ operations for the past 30 days.\"\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n\
      \  - \"COST\"\nframeworkMappings:\n  - \"/frameworks/cloudaware/cost-efficiency-and-optimization/waste-reduction\""
  - path: /ce/ca/aws/ec2/ebs-volume-idle/prod.logic.yaml
    md5Hash: 2AB5D74C0F8174B875A53FA6D6FB23D6
    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 in a transient or error state.\"\n    check:\n      AND:\
      \ \n        args:\n          - NOT_EQUAL:\n              left:\n           \
      \     EXTRACT: \"CA10__status__c\"\n              right:\n                TEXT:\
      \ \"available\"\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: \"INCOMPLIANT\"\n    currentStateMessage: \"The EBS volume is\
      \ unattached and has no I/O metrics for the past 30 days.\"\n    remediationMessage:\
      \ \"Consider creating a final snapshot of the volume for archival purposes and\
      \ then deleting it.\"\n    check:\n      AND:\n        args:\n          - IS_EQUAL:\n\
      \              left:\n                EXTRACT: \"CA10__status__c\"\n       \
      \       right:\n                TEXT: \"available\"\n          - IS_EMPTY:\n\
      \              arg:\n                EXTRACT: \"CA10__readOpsSum30d__c\"\n \
      \         - IS_EMPTY:\n              arg:\n                EXTRACT: \"CA10__writeOpsSum30d__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: INCOMPLIANT\n\
      \    currentStateMessage: \"The EBS volume is attached but has no read and write\
      \ operations for the past 30 days.\"\n    remediationMessage: \"The volume is\
      \ attached to an instance that has been stopped for over 30 days.\\\n      \\\
      \ Consider detaching it, creating a snapshot for archival, and then deleting\
      \ the volume.\"\n    check:\n      AND:\n        args:\n          - IS_EQUAL:\n\
      \              left:\n                EXTRACT: \"CA10__status__c\"\n       \
      \       right:\n                TEXT: \"in-use\"\n          - IS_EMPTY:\n  \
      \            arg:\n                EXTRACT: \"CA10__readOpsSum30d__c\"\n   \
      \       - IS_EMPTY:\n              arg:\n                EXTRACT: \"CA10__writeOpsSum30d__c\"\
      \n  - status: INCOMPLIANT\n    currentStateMessage: \"The EBS volume is attached\
      \ but has had zero read and write operations for the past 30 days.\"\n    remediationMessage:\
      \ \"Investigate why the volume is attached but unused.\\\n      \\ Consider\
      \ detaching it, creating a snapshot for archival, and then deleting the volume.\"\
      \n    check:\n      AND:\n        args:\n          - IS_EQUAL:\n           \
      \   left:\n                EXTRACT: \"CA10__status__c\"\n              right:\n\
      \                TEXT: \"in-use\"\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\notherwise:\n  status: \"COMPLIANT\"\n  currentStateMessage:\
      \ \"The EBS volume is not idle.\""
  - path: /ce/ca/aws/ec2/ebs-volume-idle/test-data.json
    md5Hash: 1E217B2E4E72B6CBB2A03DF27BB0344F
    content: |-
      [
        {
          "expectedResult": {
            "status": "DISAPPEARED",
            "conditionIndex": "99",
            "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
            "runtimeError": null
          },
          "context": {
            "snapshotTime": "2025-09-03T23:10:29Z"
          },
          "Id": "001",
          "CA10__disappearanceTime__c": "2025-09-01T14:43:54Z",
          "CA10__status__c": "in-use",
          "CA10__createTime__c": "2023-04-07T07:41:09Z",
          "CA10__readOpsSum30d__c": null,
          "CA10__writeOpsSum30d__c": null,
          "CA10__attachmentAttachTime__c": "2023-04-07T07:41:09Z"
        },
        {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "199",
            "conditionText": "extract('CA10__status__c') != 'available' && extract('CA10__status__c') != 'in-use'",
            "runtimeError": null
          },
          "context": {
            "snapshotTime": "2025-09-03T23:10:29Z"
          },
          "Id": "002",
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "error",
          "CA10__createTime__c": "2025-08-04T00:25:55Z",
          "CA10__readOpsSum30d__c": null,
          "CA10__writeOpsSum30d__c": null,
          "CA10__attachmentAttachTime__c": null
        },
        {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "299",
            "conditionText": "extract('CA10__createTime__c').withinLastDays(30)",
            "runtimeError": null
          },
          "context": {
            "snapshotTime": "2025-09-03T23:10:29Z"
          },
          "Id": "003",
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "in-use",
          "CA10__createTime__c": "2025-09-01T23:10:29Z",
          "CA10__readOpsSum30d__c": 10,
          "CA10__writeOpsSum30d__c": 10,
          "CA10__attachmentAttachTime__c": "2025-09-01T23:10:29Z"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "399",
            "conditionText": "extract('CA10__status__c') == 'available' && extract('CA10__readOpsSum30d__c').isEmpty() && extract('CA10__writeOpsSum30d__c').isEmpty()",
            "runtimeError": null
          },
          "context": {
            "snapshotTime": "2025-09-03T23:10:29Z"
          },
          "Id": "004",
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "available",
          "CA10__createTime__c": "2018-01-04T18:48:41Z",
          "CA10__readOpsSum30d__c": null,
          "CA10__writeOpsSum30d__c": null,
          "CA10__attachmentAttachTime__c": null
        },
        {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "499",
            "conditionText": "extract('CA10__attachmentAttachTime__c').isNotEmpty() && extract('CA10__attachmentAttachTime__c').withinLastDays(30)",
            "runtimeError": null
          },
          "context": {
            "snapshotTime": "2025-09-03T23:10:29Z"
          },
          "Id": "005",
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "in-use",
          "CA10__createTime__c": "2024-09-03T23:10:29Z",
          "CA10__readOpsSum30d__c": 10,
          "CA10__writeOpsSum30d__c": 10,
          "CA10__attachmentAttachTime__c": "2025-09-01T23:10:29Z"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "599",
            "conditionText": "extract('CA10__status__c') == 'in-use' && extract('CA10__readOpsSum30d__c').isEmpty() && extract('CA10__writeOpsSum30d__c').isEmpty()",
            "runtimeError": null
          },
          "context": {
            "snapshotTime": "2025-09-03T23:10:29Z"
          },
          "Id": "006",
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "in-use",
          "CA10__createTime__c": "2024-09-03T23:10:29Z",
          "CA10__readOpsSum30d__c": null,
          "CA10__writeOpsSum30d__c": null,
          "CA10__attachmentAttachTime__c": "2024-09-03T23:10:29Z"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "699",
            "conditionText": "extract('CA10__status__c') == 'in-use' && extract('CA10__readOpsSum30d__c') == number(0.0) && extract('CA10__writeOpsSum30d__c') == number(0.0)",
            "runtimeError": null
          },
          "context": {
            "snapshotTime": "2025-09-03T23:10:29Z"
          },
          "Id": "007",
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "in-use",
          "CA10__createTime__c": "2024-09-03T23:10:29Z",
          "CA10__readOpsSum30d__c": 0,
          "CA10__writeOpsSum30d__c": 0,
          "CA10__attachmentAttachTime__c": "2024-09-03T23:10:29Z"
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "700",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": {
            "snapshotTime": "2025-09-03T23:10:29Z"
          },
          "Id": "008",
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "in-use",
          "CA10__createTime__c": "2024-09-03T23:10:29Z",
          "CA10__readOpsSum30d__c": 10,
          "CA10__writeOpsSum30d__c": 10,
          "CA10__attachmentAttachTime__c": "2024-09-03T23:10:29Z"
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "700",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": {
            "snapshotTime": "2025-09-03T23:10:29Z"
          },
          "Id": "009",
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "available",
          "CA10__createTime__c": "2024-09-03T23:10:29Z",
          "CA10__readOpsSum30d__c": 10,
          "CA10__writeOpsSum30d__c": 10,
          "CA10__attachmentAttachTime__c": "2024-09-03T23:10:29Z"
        }
      ]
  - 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') != 'available' && 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" : "INCOMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "extract('CA10__status__c') == 'available' && extract('CA10__readOpsSum30d__c').isEmpty() && extract('CA10__writeOpsSum30d__c').isEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "005",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "499",
      "conditionText" : "extract('CA10__attachmentAttachTime__c').isNotEmpty() && extract('CA10__attachmentAttachTime__c').withinLastDays(30)",
      "runtimeError" : null
    }
  }, {
    "Id" : "006",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "599",
      "conditionText" : "extract('CA10__status__c') == 'in-use' && extract('CA10__readOpsSum30d__c').isEmpty() && extract('CA10__writeOpsSum30d__c').isEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "007",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "699",
      "conditionText" : "extract('CA10__status__c') == 'in-use' && extract('CA10__readOpsSum30d__c') == number(0.0) && extract('CA10__writeOpsSum30d__c') == number(0.0)",
      "runtimeError" : null
    }
  }, {
    "Id" : "008",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "700",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "009",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "700",
      "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__readOpsSum30d__c FLOAT64,
      CA10__writeOpsSum30d__c FLOAT64,
      CA10__attachmentAttachTime__c TIMESTAMP,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-09-03T23:10:29Z")
    },
    "Id" : "001",
    "CA10__disappearanceTime__c" : new Date("2025-09-01T14:43:54Z"),
    "CA10__status__c" : "in-use",
    "CA10__createTime__c" : new Date("2023-04-07T07:41:09Z"),
    "CA10__readOpsSum30d__c" : null,
    "CA10__writeOpsSum30d__c" : null,
    "CA10__attachmentAttachTime__c" : new Date("2023-04-07T07:41:09Z")
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-03T23:10:29Z")
    },
    "Id" : "002",
    "CA10__status__c" : "error",
    "CA10__createTime__c" : new Date("2025-08-04T00:25:55Z"),
    "CA10__readOpsSum30d__c" : null,
    "CA10__writeOpsSum30d__c" : null
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-03T23:10:29Z")
    },
    "Id" : "003",
    "CA10__status__c" : "in-use",
    "CA10__createTime__c" : new Date("2025-09-01T23:10:29Z"),
    "CA10__readOpsSum30d__c" : 10,
    "CA10__writeOpsSum30d__c" : 10,
    "CA10__attachmentAttachTime__c" : new Date("2025-09-01T23:10:29Z")
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-03T23:10:29Z")
    },
    "Id" : "004",
    "CA10__status__c" : "available",
    "CA10__createTime__c" : new Date("2018-01-04T18:48:41Z"),
    "CA10__readOpsSum30d__c" : null,
    "CA10__writeOpsSum30d__c" : null
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-03T23:10:29Z")
    },
    "Id" : "005",
    "CA10__status__c" : "in-use",
    "CA10__createTime__c" : new Date("2024-09-03T23:10:29Z"),
    "CA10__readOpsSum30d__c" : 10,
    "CA10__writeOpsSum30d__c" : 10,
    "CA10__attachmentAttachTime__c" : new Date("2025-09-01T23:10:29Z")
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-03T23:10:29Z")
    },
    "Id" : "006",
    "CA10__status__c" : "in-use",
    "CA10__createTime__c" : new Date("2024-09-03T23:10:29Z"),
    "CA10__readOpsSum30d__c" : null,
    "CA10__writeOpsSum30d__c" : null,
    "CA10__attachmentAttachTime__c" : new Date("2024-09-03T23:10:29Z")
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-03T23:10:29Z")
    },
    "Id" : "007",
    "CA10__status__c" : "in-use",
    "CA10__createTime__c" : new Date("2024-09-03T23:10:29Z"),
    "CA10__readOpsSum30d__c" : 0,
    "CA10__writeOpsSum30d__c" : 0,
    "CA10__attachmentAttachTime__c" : new Date("2024-09-03T23:10:29Z")
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-03T23:10:29Z")
    },
    "Id" : "008",
    "CA10__status__c" : "in-use",
    "CA10__createTime__c" : new Date("2024-09-03T23:10:29Z"),
    "CA10__readOpsSum30d__c" : 10,
    "CA10__writeOpsSum30d__c" : 10,
    "CA10__attachmentAttachTime__c" : new Date("2024-09-03T23:10:29Z")
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-03T23:10:29Z")
    },
    "Id" : "009",
    "CA10__status__c" : "available",
    "CA10__createTime__c" : new Date("2024-09-03T23:10:29Z"),
    "CA10__readOpsSum30d__c" : 10,
    "CA10__writeOpsSum30d__c" : 10,
    "CA10__attachmentAttachTime__c" : new Date("2024-09-03T23:10:29Z")
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsVolume__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__status__c STRING,
          CA10__createTime__c TIMESTAMP,
          CA10__readOpsSum30d__c FLOAT64,
          CA10__writeOpsSum30d__c FLOAT64,
          CA10__attachmentAttachTime__c TIMESTAMP
      >,
      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 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), 'available') && TextLib.notEqual(extract3.call(extract3), 'in-use')) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__status__c') != 'available' && extract('CA10__status__c') != 'in-use'", currentStateMessage: "The EBS volume is in a transient or error state.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract7() { 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 (extract7.call(extract7) != null && extract7.call(extract7).getTime() >= todayMinus30Day && extract7.call(extract7).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 extract11() { if (!this.out) { this.out = obj.CA10__status__c; } return this.out; };
      function extract14() { if (!this.out) { this.out = obj.CA10__readOpsSum30d__c; } return this.out; };
      function extract17() { 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 (TextLib.equal(extract11.call(extract11), 'available') && IsEmptyLib.simpleIsEmpty(extract14.call(extract14)) && IsEmptyLib.simpleIsEmpty(extract17.call(extract17))) {
          return {status: 'INCOMPLIANT', conditionIndex: 399, conditionText: "extract('CA10__status__c') == 'available' && extract('CA10__readOpsSum30d__c').isEmpty() && extract('CA10__writeOpsSum30d__c').isEmpty()", currentStateMessage: "The EBS volume is unattached and has no I/O metrics for the past 30 days.", currentStateReferences: references1.join('\n'), remediation: "Consider creating a final snapshot of the volume for archival purposes and then deleting it.", runtimeError: null};
      }
      // condition[4], conditionIndex:[400..499]
      function extract20() { 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(extract20.call(extract20)) && (extract20.call(extract20) != null && extract20.call(extract20).getTime() >= todayMinus30Day && extract20.call(extract20).getTime() < todayPlus1Day)) {
          return {status: 'INAPPLICABLE', conditionIndex: 499, 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[5], conditionIndex:[500..599]
      function extract25() { if (!this.out) { this.out = obj.CA10__status__c; } return this.out; };
      function extract28() { if (!this.out) { this.out = obj.CA10__readOpsSum30d__c; } return this.out; };
      function extract31() { if (!this.out) { this.out = obj.CA10__writeOpsSum30d__c; } return this.out; };
      if (TextLib.equal(extract25.call(extract25), 'in-use') && IsEmptyLib.simpleIsEmpty(extract28.call(extract28)) && IsEmptyLib.simpleIsEmpty(extract31.call(extract31))) {
          return {status: 'INCOMPLIANT', conditionIndex: 599, conditionText: "extract('CA10__status__c') == 'in-use' && extract('CA10__readOpsSum30d__c').isEmpty() && extract('CA10__writeOpsSum30d__c').isEmpty()", currentStateMessage: "The EBS volume is attached but has no read and write operations for the past 30 days.", currentStateReferences: references1.join('\n'), remediation: "The volume is attached to an instance that has been stopped for over 30 days. Consider detaching it, creating a snapshot for archival, and then deleting the volume.", runtimeError: null};
      }
      // condition[6], conditionIndex:[600..699]
      function extract34() { if (!this.out) { this.out = obj.CA10__status__c; } return this.out; };
      function extract37() { if (!this.out) { this.out = obj.CA10__readOpsSum30d__c; } return this.out; };
      function extract40() { if (!this.out) { this.out = obj.CA10__writeOpsSum30d__c; } return this.out; };
      if (TextLib.equal(extract34.call(extract34), 'in-use') && extract37.call(extract37) == 0.0 && extract40.call(extract40) == 0.0) {
          return {status: 'INCOMPLIANT', conditionIndex: 699, conditionText: "extract('CA10__status__c') == 'in-use' && extract('CA10__readOpsSum30d__c') == number(0.0) && extract('CA10__writeOpsSum30d__c') == number(0.0)", currentStateMessage: "The EBS volume is attached but has had zero read and write operations for the past 30 days.", currentStateReferences: references1.join('\n'), remediation: "Investigate why the volume is attached but unused. Consider detaching it, creating a snapshot for archival, and then deleting the volume.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 700, conditionText: "otherwise", currentStateMessage: "The EBS volume is not idle.", 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__readOpsSum30d__c AS CA10__readOpsSum30d__c,
          sObject.CA10__writeOpsSum30d__c AS CA10__writeOpsSum30d__c,
          sObject.CA10__attachmentAttachTime__c AS CA10__attachmentAttachTime__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__readOpsSum30d__c AS CA10__readOpsSum30d__c,
                  sObject.CA10__writeOpsSum30d__c AS CA10__writeOpsSum30d__c,
                  sObject.CA10__attachmentAttachTime__c AS CA10__attachmentAttachTime__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsVolume__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
