---
policy: /ce/ca/aws/ec2/instance-idle
logic: /ce/ca/aws/ec2/instance-idle/prod.logic.yaml
executionTime: 2025-04-24T23:44:31.296505705Z
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__stateName__c') != 'running'
      actual: extract('CA10__stateName__c') != 'running'
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__currentRunningTime__c') < number(14.0)
      actual: extract('CA10__currentRunningTime__c') < number(14.0)
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: UNDETERMINED
      actual: UNDETERMINED
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: extract('CA10__averageCpuTwoWeeks__c').isEmpty() || extract('CA10__maxCpuTwoWeeks__c').isEmpty()
        || extract('CA10__sumTwoWeekNetworkInMb__c').isEmpty() || extract('CA10__sumTwoWeekNetworkOutMb__c').isEmpty()
      actual: extract('CA10__averageCpuTwoWeeks__c').isEmpty() || extract('CA10__maxCpuTwoWeeks__c').isEmpty()
        || extract('CA10__sumTwoWeekNetworkInMb__c').isEmpty() || extract('CA10__sumTwoWeekNetworkOutMb__c').isEmpty()
    runtimeError: {}
  - id: test5
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 499
      actual: 499
    conditionText:
      expected: extract('CA10__averageCpuTwoWeeks__c') < number(5.0) && extract('CA10__maxCpuTwoWeeks__c')
        < number(15.0) && extract('CA10__sumTwoWeekNetworkInMb__c') < number(100.0)
        && extract('CA10__sumTwoWeekNetworkOutMb__c') < number(100.0)
      actual: extract('CA10__averageCpuTwoWeeks__c') < number(5.0) && extract('CA10__maxCpuTwoWeeks__c')
        < number(15.0) && extract('CA10__sumTwoWeekNetworkInMb__c') < number(100.0)
        && extract('CA10__sumTwoWeekNetworkOutMb__c') < number(100.0)
    runtimeError: {}
  - id: test6
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 500
      actual: 500
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/ec2/instance-idle/policy.yaml
    md5Hash: 25948976F20A4DC63E82F86EF6774D48
    content: "---\nnames:\n  full: AWS EC2 Instance is idle\n  contextual: Instance\
      \ is idle\ndescription: >\n  Identify and address idle Amazon EC2 instances\
      \ to optimize costs by stopping, \n  terminating, or downscaling instances with\
      \ low utilization. Instances are \n  considered idle if their average CPU utilization\
      \ is below 5%, maximum CPU \n  utilization is below 15%, and average network\
      \ I/O is below 100 MB over a 14-day period.\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n\
      \  - \"PERFORMANCE\"\n  - \"COST\"\nframeworkMappings:\n  - \"/frameworks/cloudaware/cost-efficiency-and-optimization/waste-reduction\"\
      \n  - \"/frameworks/cloudaware/resource-performance/workload-efficiency\""
  - path: /ce/ca/aws/ec2/instance-idle/prod.logic.yaml
    md5Hash: 7ABDF6E05E29D6EF41BE533DBFF1FBDD
    content: |-
      ---
      inputType: "CA10__CaAwsInstance__c"
      importExtracts:
        - file: "/types/CA10__CaAwsInstance__c/object.extracts.yaml"
      testData:
        - file: 'test-data.json'
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "The instance is not running."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10__stateName__c"
              right:
                TEXT: "running"
        - status: "INAPPLICABLE"
          currentStateMessage: "The instance has been running for less than 14 days."
          check:
            LESS_THAN:
              left:
                EXTRACT: "CA10__currentRunningTime__c"
              right:
                NUMBER: 14.0
        - status: UNDETERMINED
          currentStateMessage: "There is not enough data in the CMDB to identify if the instance is idle."
          check:
            OR:
              args:
                - IS_EMPTY:
                    arg:
                      EXTRACT: "CA10__averageCpuTwoWeeks__c"
                - IS_EMPTY:
                    arg:
                      EXTRACT: "CA10__maxCpuTwoWeeks__c"
                - IS_EMPTY:
                    arg:
                      EXTRACT: CA10__sumTwoWeekNetworkInMb__c
                - IS_EMPTY:
                    arg:
                      EXTRACT: CA10__sumTwoWeekNetworkOutMb__c
        - status: INCOMPLIANT
          currentStateMessage: "The instance is idle with Average CPU Utilization < 5%,\
            \ Max CPU Utilization < 15%, and Average Network I/O < 100 MB."
          remediationMessage: "Consider stopping, terminating, or rightsizing the instance."
          check:
            AND:
              args:
                - LESS_THAN:
                    left:
                      EXTRACT: CA10__averageCpuTwoWeeks__c
                    right:
                      NUMBER: 5.0
                - LESS_THAN:
                    left:
                      EXTRACT: CA10__maxCpuTwoWeeks__c
                    right:
                      NUMBER: 15.0
                - LESS_THAN:
                    left:
                      EXTRACT: CA10__sumTwoWeekNetworkInMb__c
                    right:
                      NUMBER: 100.0
                - LESS_THAN:
                    left:
                      EXTRACT: CA10__sumTwoWeekNetworkOutMb__c
                    right:
                      NUMBER: 100.0
      otherwise:
        status: "COMPLIANT"
        currentStateMessage: 'The instance is not idle.'
  - path: /ce/ca/aws/ec2/instance-idle/test-data.json
    md5Hash: 7AA1A2BDF5E1BAF659C7592DB8E34665
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-11-20T20:12:30Z"
              },
              "Id": "test1",
              "CA10__disappearanceTime__c": "2024-11-20T17:14:43Z",
              "CA10__stateName__c": "running",
              "CA10__currentRunningTime__c": 100.0,
              "CA10__averageCpuTwoWeeks__c": 1.0,
              "CA10__maxCpuTwoWeeks__c": 10.0,
              "CA10__sumTwoWeekNetworkInMb__c": 10,
              "CA10__sumTwoWeekNetworkOutMb__c": 10
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__stateName__c') != 'running'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-11-20T20:12:30Z"
              },
              "Id": "test2",
              "CA10__disappearanceTime__c": null,
              "CA10__stateName__c": "stopped",
              "CA10__currentRunningTime__c": 100.0,
              "CA10__averageCpuTwoWeeks__c": 1.0,
              "CA10__maxCpuTwoWeeks__c": 10.0,
              "CA10__sumTwoWeekNetworkInMb__c": 10,
              "CA10__sumTwoWeekNetworkOutMb__c": 10
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "299",
                  "conditionText": "extract('CA10__currentRunningTime__c') < number(14.0)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-11-20T20:12:30Z"
              },
              "Id": "test3",
              "CA10__disappearanceTime__c": null,
              "CA10__stateName__c": "running",
              "CA10__currentRunningTime__c": 1.0,
              "CA10__averageCpuTwoWeeks__c": 1.0,
              "CA10__maxCpuTwoWeeks__c": 10.0,
              "CA10__sumTwoWeekNetworkInMb__c": 10,
              "CA10__sumTwoWeekNetworkOutMb__c": 10
          },
          {
              "expectedResult": {
                  "status": "UNDETERMINED",
                  "conditionIndex": "399",
                  "conditionText": "extract('CA10__averageCpuTwoWeeks__c').isEmpty() || extract('CA10__maxCpuTwoWeeks__c').isEmpty() || extract('CA10__sumTwoWeekNetworkInMb__c').isEmpty() || extract('CA10__sumTwoWeekNetworkOutMb__c').isEmpty()",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-11-20T20:12:30Z"
              },
              "Id": "test4",
              "CA10__disappearanceTime__c": null,
              "CA10__stateName__c": "running",
              "CA10__currentRunningTime__c": 100.0,
              "CA10__averageCpuTwoWeeks__c": null,
              "CA10__maxCpuTwoWeeks__c": null,
              "CA10__sumTwoWeekNetworkInMb__c": null,
              "CA10__sumTwoWeekNetworkOutMb__c": null
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "499",
                  "conditionText": "extract('CA10__averageCpuTwoWeeks__c') < number(5.0) && extract('CA10__maxCpuTwoWeeks__c') < number(15.0) && extract('CA10__sumTwoWeekNetworkInMb__c') < number(100.0) && extract('CA10__sumTwoWeekNetworkOutMb__c') < number(100.0)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-11-20T20:12:30Z"
              },
              "Id": "test5",
              "CA10__disappearanceTime__c": null,
              "CA10__stateName__c": "running",
              "CA10__currentRunningTime__c": 100.0,
              "CA10__averageCpuTwoWeeks__c": 1.0,
              "CA10__maxCpuTwoWeeks__c": 10.0,
              "CA10__sumTwoWeekNetworkInMb__c": 10,
              "CA10__sumTwoWeekNetworkOutMb__c": 10
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "500",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-11-20T20:12:30Z"
              },
              "Id": "test6",
              "CA10__disappearanceTime__c": null,
              "CA10__stateName__c": "running",
              "CA10__currentRunningTime__c": 100.0,
              "CA10__averageCpuTwoWeeks__c": 50.0,
              "CA10__maxCpuTwoWeeks__c": 90.0,
              "CA10__sumTwoWeekNetworkInMb__c": 1000,
              "CA10__sumTwoWeekNetworkOutMb__c": 1000
          }
      ]
  - path: /types/CA10__CaAwsInstance__c/object.extracts.yaml
    md5Hash: 802FA80DBDE640AF85A69B42E51E0CCD
    content: "---\nextracts:\n# Values pending, applied. Not nullable. Can't have\
      \ no access, retrieved via ec2:DescribeInstances\n  - name: \"CA10__metadataState__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__metadataState__c\"\n    \
      \    undeterminedIf:\n          isEmpty: \"Corrupted data. EC2 Instances Metadata\
      \ State cannot be empty.\"\n# Values: optional, required. Not nullable. Can't\
      \ have no access, retrieved via ec2:DescribeInstances\n  - name: \"CA10__metadataHttpTokens__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__metadataHttpTokens__c\"\n\
      \        undeterminedIf:\n          isEmpty: \"Corrupted data. EC2 Instances\
      \ Metadata Http Token cannot be empty.\"\n  - name: CA10__iamInstanceProfileArn__c\n\
      \    value:\n      FIELD: \n        path: CA10__iamInstanceProfileArn__c\n#\
      \ Nullable. Can't have no access, retrieved via ec2:DescribeInstances\n  - name:\
      \ \"CA10__publicIpAddress__c\"\n    value: \n      FIELD:\n        path: \"\
      CA10__publicIpAddress__c\"\n# Values: enabled, disabled. Not nullable. Can't\
      \ have no access, retrieved via ec2:DescribeInstances\n  - name: \"CA10__monitoringState__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__monitoringState__c\"\n  \
      \      undeterminedIf:\n          isEmpty: \"Corrupted data. EC2 Instances Detailed\
      \ Monitoring State cannot be empty.\"\n# Values: pending | running | shutting-down\
      \ | terminated | stopping | stopped. Not nullable.\n  - name: \"CA10__stateName__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__stateName__c\"\n        undeterminedIf:\n\
      \          noAccessDelegate:\n            path: \"CA10__stateName__c\"\n   \
      \         currentStateMessage: \"Unable to determine EC2 Instances State Name.\
      \ Possible permission issue with ec2:DescribeInstanceStatus\"\n# Number of Days.\
      \ Nullable. Can't have no access, retrieved via ec2:DescribeInstances\n  - name:\
      \ \"CA10__currentRunningTime__c\"\n    value: \n      FIELD:\n        path:\
      \ \"CA10__currentRunningTime__c\"      \n# Nullable.\n  - name: \"CA10__averageCpuTwoWeeks__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__averageCpuTwoWeeks__c\" \
      \     \n# Nullable.\n  - name: \"CA10__maxCpuTwoWeeks__c\"\n    value: \n  \
      \    FIELD:\n        path: \"CA10__maxCpuTwoWeeks__c\"      \n# Nullable.\n\
      \  - name: \"CA10__sumTwoWeekNetworkOutMb__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10__sumTwoWeekNetworkOutMb__c\"      \n# Nullable.\n  - name:\
      \ \"CA10__sumTwoWeekNetworkInMb__c\"\n    value: \n      FIELD:\n        path:\
      \ \"CA10__sumTwoWeekNetworkInMb__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__stateName__c') != 'running'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__currentRunningTime__c') < number(14.0)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "UNDETERMINED",
      "conditionIndex" : "399",
      "conditionText" : "extract('CA10__averageCpuTwoWeeks__c').isEmpty() || extract('CA10__maxCpuTwoWeeks__c').isEmpty() || extract('CA10__sumTwoWeekNetworkInMb__c').isEmpty() || extract('CA10__sumTwoWeekNetworkOutMb__c').isEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "test5",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "499",
      "conditionText" : "extract('CA10__averageCpuTwoWeeks__c') < number(5.0) && extract('CA10__maxCpuTwoWeeks__c') < number(15.0) && extract('CA10__sumTwoWeekNetworkInMb__c') < number(100.0) && extract('CA10__sumTwoWeekNetworkOutMb__c') < number(100.0)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test6",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "500",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsInstance__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__stateName__c STRING,
      CA10__currentRunningTime__c FLOAT64,
      CA10__averageCpuTwoWeeks__c FLOAT64,
      CA10__maxCpuTwoWeeks__c FLOAT64,
      CA10__sumTwoWeekNetworkInMb__c FLOAT64,
      CA10__sumTwoWeekNetworkOutMb__c FLOAT64,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-11-20T20:12:30Z")
    },
    "Id" : "test1",
    "CA10__disappearanceTime__c" : new Date("2024-11-20T17:14:43Z"),
    "CA10__stateName__c" : "running",
    "CA10__currentRunningTime__c" : 100.0,
    "CA10__averageCpuTwoWeeks__c" : 1.0,
    "CA10__maxCpuTwoWeeks__c" : 10.0,
    "CA10__sumTwoWeekNetworkInMb__c" : 10,
    "CA10__sumTwoWeekNetworkOutMb__c" : 10
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-20T20:12:30Z")
    },
    "Id" : "test2",
    "CA10__stateName__c" : "stopped",
    "CA10__currentRunningTime__c" : 100.0,
    "CA10__averageCpuTwoWeeks__c" : 1.0,
    "CA10__maxCpuTwoWeeks__c" : 10.0,
    "CA10__sumTwoWeekNetworkInMb__c" : 10,
    "CA10__sumTwoWeekNetworkOutMb__c" : 10
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-20T20:12:30Z")
    },
    "Id" : "test3",
    "CA10__stateName__c" : "running",
    "CA10__currentRunningTime__c" : 1.0,
    "CA10__averageCpuTwoWeeks__c" : 1.0,
    "CA10__maxCpuTwoWeeks__c" : 10.0,
    "CA10__sumTwoWeekNetworkInMb__c" : 10,
    "CA10__sumTwoWeekNetworkOutMb__c" : 10
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-20T20:12:30Z")
    },
    "Id" : "test4",
    "CA10__stateName__c" : "running",
    "CA10__currentRunningTime__c" : 100.0,
    "CA10__averageCpuTwoWeeks__c" : null,
    "CA10__maxCpuTwoWeeks__c" : null,
    "CA10__sumTwoWeekNetworkInMb__c" : null,
    "CA10__sumTwoWeekNetworkOutMb__c" : null
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-20T20:12:30Z")
    },
    "Id" : "test5",
    "CA10__stateName__c" : "running",
    "CA10__currentRunningTime__c" : 100.0,
    "CA10__averageCpuTwoWeeks__c" : 1.0,
    "CA10__maxCpuTwoWeeks__c" : 10.0,
    "CA10__sumTwoWeekNetworkInMb__c" : 10,
    "CA10__sumTwoWeekNetworkOutMb__c" : 10
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-20T20:12:30Z")
    },
    "Id" : "test6",
    "CA10__stateName__c" : "running",
    "CA10__currentRunningTime__c" : 100.0,
    "CA10__averageCpuTwoWeeks__c" : 50.0,
    "CA10__maxCpuTwoWeeks__c" : 90.0,
    "CA10__sumTwoWeekNetworkInMb__c" : 1000,
    "CA10__sumTwoWeekNetworkOutMb__c" : 1000
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsInstance__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__stateName__c STRING,
          CA10__currentRunningTime__c FLOAT64,
          CA10__averageCpuTwoWeeks__c FLOAT64,
          CA10__maxCpuTwoWeeks__c FLOAT64,
          CA10__sumTwoWeekNetworkInMb__c FLOAT64,
          CA10__sumTwoWeekNetworkOutMb__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));
          };
      }();
      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 fieldChecked4() {
          if (TextLib.isEmpty(obj.CA10__stateName__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__stateName__c.delegatedTo(CA10__stateName__c).isEmpty()", currentStateMessage: "Unable to determine EC2 Instances State Name. Possible permission issue with ec2:DescribeInstanceStatus", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__stateName__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('State Name [obj.CA10__stateName__c]: ' + obj.CA10__stateName__c);
      try {
          if (TextLib.notEqual(extract3.call(extract3), 'running')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__stateName__c') != 'running'", currentStateMessage: "The instance is not running.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[2], conditionIndex:[200..299]
      function extract7() { if (!this.out) { this.out = obj.CA10__currentRunningTime__c; } return this.out; };
      references1.push('Current Running Time [obj.CA10__currentRunningTime__c]: ' + obj.CA10__currentRunningTime__c);
      if (extract7.call(extract7) != null && 14.0 != null && extract7.call(extract7) < 14.0) {
          return {status: 'INAPPLICABLE', conditionIndex: 299, conditionText: "extract('CA10__currentRunningTime__c') < number(14.0)", currentStateMessage: "The instance has been running for less than 14 days.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      function extract10() { if (!this.out) { this.out = obj.CA10__averageCpuTwoWeeks__c; } return this.out; };
      function extract13() { if (!this.out) { this.out = obj.CA10__maxCpuTwoWeeks__c; } return this.out; };
      function extract16() { if (!this.out) { this.out = obj.CA10__sumTwoWeekNetworkInMb__c; } return this.out; };
      function extract19() { if (!this.out) { this.out = obj.CA10__sumTwoWeekNetworkOutMb__c; } return this.out; };
      references1.push('CloudWatch: CPU, 14-Day [obj.CA10__averageCpuTwoWeeks__c]: ' + obj.CA10__averageCpuTwoWeeks__c);
      references1.push('CloudWatch: CPU Max, 14-Day [obj.CA10__maxCpuTwoWeeks__c]: ' + obj.CA10__maxCpuTwoWeeks__c);
      references1.push('CloudWatch: Network In, MB, 14-Day [obj.CA10__sumTwoWeekNetworkInMb__c]: ' + obj.CA10__sumTwoWeekNetworkInMb__c);
      references1.push('CloudWatch: Network Out, MB, 14-Day [obj.CA10__sumTwoWeekNetworkOutMb__c]: ' + obj.CA10__sumTwoWeekNetworkOutMb__c);
      if (IsEmptyLib.simpleIsEmpty(extract10.call(extract10)) || IsEmptyLib.simpleIsEmpty(extract13.call(extract13)) || IsEmptyLib.simpleIsEmpty(extract16.call(extract16)) || IsEmptyLib.simpleIsEmpty(extract19.call(extract19))) {
          return {status: 'UNDETERMINED', conditionIndex: 399, conditionText: "extract('CA10__averageCpuTwoWeeks__c').isEmpty() || extract('CA10__maxCpuTwoWeeks__c').isEmpty() || extract('CA10__sumTwoWeekNetworkInMb__c').isEmpty() || extract('CA10__sumTwoWeekNetworkOutMb__c').isEmpty()", currentStateMessage: "There is not enough data in the CMDB to identify if the instance is idle.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[4], conditionIndex:[400..499]
      function extract23() { if (!this.out) { this.out = obj.CA10__averageCpuTwoWeeks__c; } return this.out; };
      function extract27() { if (!this.out) { this.out = obj.CA10__maxCpuTwoWeeks__c; } return this.out; };
      function extract31() { if (!this.out) { this.out = obj.CA10__sumTwoWeekNetworkInMb__c; } return this.out; };
      function extract35() { if (!this.out) { this.out = obj.CA10__sumTwoWeekNetworkOutMb__c; } return this.out; };
      if ((extract23.call(extract23) != null && 5.0 != null && extract23.call(extract23) < 5.0) && (extract27.call(extract27) != null && 15.0 != null && extract27.call(extract27) < 15.0) && (extract31.call(extract31) != null && 100.0 != null && extract31.call(extract31) < 100.0) && (extract35.call(extract35) != null && 100.0 != null && extract35.call(extract35) < 100.0)) {
          return {status: 'INCOMPLIANT', conditionIndex: 499, conditionText: "extract('CA10__averageCpuTwoWeeks__c') < number(5.0) && extract('CA10__maxCpuTwoWeeks__c') < number(15.0) && extract('CA10__sumTwoWeekNetworkInMb__c') < number(100.0) && extract('CA10__sumTwoWeekNetworkOutMb__c') < number(100.0)", currentStateMessage: "The instance is idle with Average CPU Utilization < 5%, Max CPU Utilization < 15%, and Average Network I/O < 100 MB.", currentStateReferences: references1.join('\n'), remediation: "Consider stopping, terminating, or rightsizing the instance.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 500, conditionText: "otherwise", currentStateMessage: "The instance 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__stateName__c AS CA10__stateName__c,
          sObject.CA10__currentRunningTime__c AS CA10__currentRunningTime__c,
          sObject.CA10__averageCpuTwoWeeks__c AS CA10__averageCpuTwoWeeks__c,
          sObject.CA10__maxCpuTwoWeeks__c AS CA10__maxCpuTwoWeeks__c,
          sObject.CA10__sumTwoWeekNetworkInMb__c AS CA10__sumTwoWeekNetworkInMb__c,
          sObject.CA10__sumTwoWeekNetworkOutMb__c AS CA10__sumTwoWeekNetworkOutMb__c,
          process_CA10__CaAwsInstance__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__stateName__c AS CA10__stateName__c,
                  sObject.CA10__currentRunningTime__c AS CA10__currentRunningTime__c,
                  sObject.CA10__averageCpuTwoWeeks__c AS CA10__averageCpuTwoWeeks__c,
                  sObject.CA10__maxCpuTwoWeeks__c AS CA10__maxCpuTwoWeeks__c,
                  sObject.CA10__sumTwoWeekNetworkInMb__c AS CA10__sumTwoWeekNetworkInMb__c,
                  sObject.CA10__sumTwoWeekNetworkOutMb__c AS CA10__sumTwoWeekNetworkOutMb__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsInstance__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
