---
policy: /ce/ca/aws/ec2/ebs-volume-cmk-encryption
logic: /ce/ca/aws/ec2/ebs-volume-cmk-encryption/prod.logic.yaml
executionTime: 2025-12-27T12:01:47.513902911Z
generationMs: 112
executionMs: 1145
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: not(extract('CA10__encrypted__c'))
      actual: not(extract('CA10__encrypted__c'))
    runtimeError: {}
  - id: '004'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: isEmptyLookup('CA10__kmsKey__r')
      actual: isEmptyLookup('CA10__kmsKey__r')
    runtimeError: {}
  - id: '005'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 499
      actual: 499
    conditionText:
      expected: extract('CA10__kmsKey__r.CA10__manager__c') != 'CUSTOMER'
      actual: extract('CA10__kmsKey__r.CA10__manager__c') != 'CUSTOMER'
    runtimeError: {}
  - id: '006'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 599
      actual: 599
    conditionText:
      expected: extract('CA10__encrypted__c') == true && extract('CA10__kmsKey__r.CA10__manager__c')
        == 'CUSTOMER'
      actual: extract('CA10__encrypted__c') == true && extract('CA10__kmsKey__r.CA10__manager__c')
        == 'CUSTOMER'
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/ec2/ebs-volume-cmk-encryption/policy.yaml
    md5Hash: 7E78E433E128D19C27D64F674C759DEC
    content: "---\nnames:\n  full: \"AWS EBS Attached Volume is not encrypted with\
      \ KMS CMK\"\n  contextual: \"EBS Attached Volume is not encrypted with KMS CMK\"\
      \ndescription: >\n  Ensure that your EBS volumes are using KMS customer-managed\
      \ keys instead of \n  AWS managed-keys (default key used for volume encryption)\
      \ in order to have more \n  granular control over your data encryption and decryption\
      \ process. Once implemented, \n  the KMS customer-managed keys will be used\
      \ to encrypt and decrypt EBS data at rest, \n  volume snapshots and disk I/O.\n\
      type: \"COMPLIANCE_POLICY\"\ncategories:\n  - \"SECURITY\"\nframeworkMappings:\n\
      \  - \"/frameworks/cloudaware/resource-security/data-encryption\"\n  - \"/frameworks/aws-fsbp-v1.0.0/ec2/03\"\
      \n  - \"/frameworks/aws-well-architected/sec/08/01\"\nsimilarPolicies:\n  awsSecurityHub:\n\
      \    - name: \"[EC2.3] Attached Amazon EBS volumes should be encrypted at-rest\"\
      \n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/ec2-controls.html#ec2-3\"\
      \n  cloudConformity:\n    - url: \"https://www.trendmicro.com/cloudoneconformity/knowledge-base/aws/EBS/ebs-encrypted-with-kms-customer-master-keys.html\"\
      \n      name: EBS Encrypted With KMS Customer Master Keys"
  - path: /ce/ca/aws/ec2/ebs-volume-cmk-encryption/prod.logic.yaml
    md5Hash: B50ACD42DD77637117706336F1FEA298
    content: |
      inputType: "CA10__CaAwsVolume__c"
      testData:
        - file: "test-data.json"
      importExtracts:
        - file: "/types/CA10__CaAwsVolume__c/object.extracts.yaml"
        - file: "/types/CA10__CaAwsKmsKey__c/object.extracts.yaml"
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "This policy only applies to attached EBS volumes. This volume is not attached."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10__status__c"
              right:
                TEXT: "in-use"
        - status: "INAPPLICABLE"
          currentStateMessage: "The EBS volume is not encrypted. This is addressed in 'ebs-volume-encryption' policy"
          check:
            NOT:
              arg:
                EXTRACT: "CA10__encrypted__c"
        - status: "INCOMPLIANT"
          currentStateMessage: "The attached EBS volume is not encrypted using a KMS key."
          remediationMessage: "Enable KMS customer-managed key encryption for the volume."
          check:
            IS_EMPTY_LOOKUP: CA10__kmsKey__r
        - status: "INCOMPLIANT"
          currentStateMessage: "The attached EBS volume is not encrypted using a KMS customer-managed keys."
          remediationMessage: "Enable KMS customer-managed keys encryption for the volume."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10__kmsKey__r.CA10__manager__c"
              right:
                TEXT: 'CUSTOMER'
        - status: "COMPLIANT"
          currentStateMessage: "The attached EBS volume is encrypted using a KMS customer-managed key."
          check:
            AND:
              args:
                - IS_EQUAL:
                    left:
                      EXTRACT: "CA10__encrypted__c"
                    right:
                      BOOLEAN: true
                - IS_EQUAL:
                    left:
                      EXTRACT: "CA10__kmsKey__r.CA10__manager__c"
                    right:
                      TEXT: 'CUSTOMER'
      otherwise:
        status: "UNDETERMINED"
        currentStateMessage: "Unexpected values in the field."
  - path: /ce/ca/aws/ec2/ebs-volume-cmk-encryption/test-data.json
    md5Hash: 10DA11C3D8E13162A2D7E6F8496118BF
    content: |
      [
        {
          "expectedResult": {
            "status": "DISAPPEARED",
            "conditionIndex": "99",
            "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-12-02T19:54:10Z" },
          "CA10__disappearanceTime__c": "2025-12-02T17:47:56Z",
          "CA10__status__c": "in-use",
          "CA10__encrypted__c": false,
          "CA10__kmsKey__c": "",
          "CA10__kmsKeyArn__c": "",
          "Id": "001",
          "CA10__kmsKey__r": {
            "Id": null,
            "CA10__disappearanceTime__c": null,
            "CA10__manager__c": null
          }
        },
        {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "199",
            "conditionText": "extract('CA10__status__c') != 'in-use'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-12-02T19:54:10Z" },
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "deleting",
          "CA10__encrypted__c": true,
          "CA10__kmsKey__c": "kk002",
          "CA10__kmsKeyArn__c": "arn:aws:kms:eu-west-1:XXX:key/XXX19",
          "Id": "002",
          "CA10__kmsKey__r": {
            "Id": "kk002",
            "CA10__disappearanceTime__c": null,
            "CA10__manager__c": "AWS"
          }
        },
        {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "299",
            "conditionText": "not(extract('CA10__encrypted__c'))",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-12-02T19:54:10Z" },
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "in-use",
          "CA10__encrypted__c": false,
          "CA10__kmsKey__c": "",
          "CA10__kmsKeyArn__c": "",
          "Id": "003",
          "CA10__kmsKey__r": {
            "Id": null,
            "CA10__disappearanceTime__c": null,
            "CA10__manager__c": null
          }
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "399",
            "conditionText": "isEmptyLookup('CA10__kmsKey__r')",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-12-02T19:54:10Z" },
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "in-use",
          "CA10__encrypted__c": true,
          "CA10__kmsKey__c": "",
          "CA10__kmsKeyArn__c": "",
          "Id": "004",
          "CA10__kmsKey__r": {
            "Id": null,
            "CA10__disappearanceTime__c": null,
            "CA10__manager__c": null
          }
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "499",
            "conditionText": "extract('CA10__kmsKey__r.CA10__manager__c') != 'CUSTOMER'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-12-02T19:54:10Z" },
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "in-use",
          "CA10__encrypted__c": true,
          "CA10__kmsKey__c": "kk005",
          "CA10__kmsKeyArn__c": "arn:aws:kms:ca-central-1:XXX4:key/xxxx55",
          "Id": "005",
          "CA10__kmsKey__r": {
            "Id": "kk005",
            "CA10__disappearanceTime__c": null,
            "CA10__manager__c": "AWS"
          }
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "599",
            "conditionText": "extract('CA10__encrypted__c') == true && extract('CA10__kmsKey__r.CA10__manager__c') == 'CUSTOMER'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-12-02T19:54:10Z" },
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "in-use",
          "CA10__encrypted__c": true,
          "CA10__kmsKey__c": "kk006",
          "CA10__kmsKeyArn__c": "arn:aws:kms:eu-west-1:xxx6:key/9xxx76",
          "Id": "006",
          "CA10__kmsKey__r": {
            "Id": "kk006",
            "CA10__disappearanceTime__c": null,
            "CA10__manager__c": "CUSTOMER"
          }
        }
      ]
  - path: /types/CA10__CaAwsKmsKey__c/object.extracts.yaml
    md5Hash: EC6D0EFD0BFEAB3447A84529724D4AFE
    content: "---\nextracts:\n# Values: Creating, Enabled, Disabled, PendingDeletion,\
      \ PendingImport, PendingReplicaDeletion, Unavailable, Updating. Not nullable.\n\
      \  - name: \"CA10__state__c\"\n    value: \n      FIELD:\n        path: \"CA10__state__c\"\
      \n        undeterminedIf:\n          noAccessDelegate: \n            path: \"\
      CA10__state__c\"\n            currentStateMessage: \"Unable to determine Key\
      \ state. Possible permission issue with kms:DescribeKey.\"\n          isEmpty:\
      \ \"KMS Key state is not populated yet.\"\n# Values: RSA_2048, RSA_3072, RSA_4096,\
      \ ECC_NIST_P256, ECC_NIST_P384, ECC_NIST_P521, ECC_SECG_P256K1, SYMMETRIC_DEFAULT,\
      \ HMAC_224, HMAC_256, HMAC_384, HMAC_512, SM2\n# Not nullable\n  - name: \"\
      CA10__keySpec__c\"\n    value: \n      FIELD:\n        path: \"CA10__keySpec__c\"\
      \n        undeterminedIf:\n          noAccessDelegate: \n            path: \"\
      CA10__keySpec__c\"\n            currentStateMessage: \"Unable to determine Key\
      \ state. Possible permission issue with kms:DescribeKey.\"\n          isEmpty:\
      \ \"KMS Key state is not populated yet.\"\n# Checkbox.\n  - name: \"CA10__rotationEnabled__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__rotationEnabled__c\"\n  \
      \      undeterminedIf:\n          noAccessDelegate:\n            path: \"CA10__rotationEnabled__c\"\
      \n            currentStateMessage: \"Unable to determine Key Rotation status.\
      \ Possible permission issue with kms:GetKeyRotationStatus.\"\n# Nullable.\n\
      \  - name: \"CA10__deletionDate__c\"\n    value: \n      FIELD:\n        path:\
      \ \"CA10__deletionDate__c\"\n# Values: AWS | Customer. Not Nullable.\n  - name:\
      \ \"CA10__manager__c\"\n    value: \n      FIELD:\n        path: \"CA10__manager__c\"\
      \n        undeterminedIf:\n          noAccessDelegate: \n            path: \"\
      CA10__manager__c\"\n            currentStateMessage: \"Unable to determine Key\
      \ Manager. Possible permission issue with kms:DescribeKey.\"\n"
  - 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" : "not(extract('CA10__encrypted__c'))",
      "runtimeError" : null
    }
  }, {
    "Id" : "004",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "isEmptyLookup('CA10__kmsKey__r')",
      "runtimeError" : null
    }
  }, {
    "Id" : "005",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "499",
      "conditionText" : "extract('CA10__kmsKey__r.CA10__manager__c') != 'CUSTOMER'",
      "runtimeError" : null
    }
  }, {
    "Id" : "006",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "599",
      "conditionText" : "extract('CA10__encrypted__c') == true && extract('CA10__kmsKey__r.CA10__manager__c') == 'CUSTOMER'",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsVolume__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__status__c STRING,
      CA10__encrypted__c BOOLEAN,
      CA10__kmsKey__c STRING,
      CA10__kmsKeyArn__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-12-02T19:54:10Z")
    },
    "CA10__disappearanceTime__c" : new Date("2025-12-02T17:47:56Z"),
    "CA10__status__c" : "in-use",
    "CA10__encrypted__c" : false,
    "CA10__kmsKey__c" : "",
    "CA10__kmsKeyArn__c" : "",
    "Id" : "001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-12-02T19:54:10Z")
    },
    "CA10__status__c" : "deleting",
    "CA10__encrypted__c" : true,
    "CA10__kmsKey__c" : "kk002",
    "CA10__kmsKeyArn__c" : "arn:aws:kms:eu-west-1:XXX:key/XXX19",
    "Id" : "002"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-12-02T19:54:10Z")
    },
    "CA10__status__c" : "in-use",
    "CA10__encrypted__c" : false,
    "CA10__kmsKey__c" : "",
    "CA10__kmsKeyArn__c" : "",
    "Id" : "003"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-12-02T19:54:10Z")
    },
    "CA10__status__c" : "in-use",
    "CA10__encrypted__c" : true,
    "CA10__kmsKey__c" : "",
    "CA10__kmsKeyArn__c" : "",
    "Id" : "004"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-12-02T19:54:10Z")
    },
    "CA10__status__c" : "in-use",
    "CA10__encrypted__c" : true,
    "CA10__kmsKey__c" : "kk005",
    "CA10__kmsKeyArn__c" : "arn:aws:kms:ca-central-1:XXX4:key/xxxx55",
    "Id" : "005"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-12-02T19:54:10Z")
    },
    "CA10__status__c" : "in-use",
    "CA10__encrypted__c" : true,
    "CA10__kmsKey__c" : "kk006",
    "CA10__kmsKeyArn__c" : "arn:aws:kms:eu-west-1:xxx6:key/9xxx76",
    "Id" : "006"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsKmsKey__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__manager__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-12-02T19:54:10Z")
    },
    "Id" : null,
    "CA10__manager__c" : null
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-12-02T19:54:10Z")
    },
    "Id" : "kk002",
    "CA10__manager__c" : "AWS"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-12-02T19:54:10Z")
    },
    "Id" : "kk005",
    "CA10__manager__c" : "AWS"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-12-02T19:54:10Z")
    },
    "Id" : "kk006",
    "CA10__manager__c" : "CUSTOMER"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsVolume__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__status__c STRING,
          CA10__encrypted__c BOOLEAN,
          CA10__kmsKey__c STRING,
          CA10__kmsKeyArn__c STRING,
          Id STRING,
          CA10__kmsKey__r STRUCT<
              Id STRING,
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__manager__c STRING
          >
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
  var TextLib = new function () {
      this.normalize = function(arg) {
          return arg == null ? '' : arg.replace(/\s+/g, ' ').trim().toLowerCase();
      };
      this.isEmpty = function(arg) {
          return this.normalize(arg) == '';
      };
      this.isNotEmpty = function(arg) {
          return this.normalize(arg) != '';
      };
      this.equal = function(left, right) {
          return this.normalize(left) == this.normalize(right);
      };
      this.notEqual = function(left, right) {
          return this.normalize(left) != this.normalize(right);
      };
      this.startsWith = function(arg, substring) {
          return this.normalize(arg).startsWith(this.normalize(substring));
      };
      this.endsWith = function(arg, substring) {
          return this.normalize(arg).endsWith(this.normalize(substring));
      };
      this.contains = function(arg, substring) {
          return this.normalize(arg).includes(this.normalize(substring));
      };
      this.containsAll = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.every(sub => normalizedArg.includes(this.normalize(sub)));
      };
      this.containsAny = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.some(sub => normalizedArg.includes(this.normalize(sub)));
      };
  }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From 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: "This policy only applies to attached EBS volumes. This volume is not attached.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10__encrypted__c; } return this.out; };
      references1.push('Encrypted [obj.CA10__encrypted__c]: ' + obj.CA10__encrypted__c);
      if (!extract6.call(extract6)) {
          return {status: 'INAPPLICABLE', conditionIndex: 299, conditionText: "not(extract('CA10__encrypted__c'))", currentStateMessage: "The EBS volume is not encrypted. This is addressed in 'ebs-volume-encryption' policy", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      if (TextLib.isEmpty(obj.CA10__kmsKeyArn__c) || TextLib.isEmpty(obj.CA10__kmsKey__c) || obj.CA10__kmsKey__r.CA10__disappearanceTime__c != null) {
          return {status: 'INCOMPLIANT', conditionIndex: 399, conditionText: "isEmptyLookup('CA10__kmsKey__r')", currentStateMessage: "The attached EBS volume is not encrypted using a KMS key.", currentStateReferences: references1.join('\n'), remediation: "Enable KMS customer-managed key encryption for the volume.", runtimeError: null};
      }
      // condition[4], conditionIndex:[400..499]
      function extractChecked8() {
          if (TextLib.isEmpty(obj.CA10__kmsKeyArn__c)) {
              throw new Error("UNDETERMINED condition:401", {cause: {status: 'UNDETERMINED', conditionIndex: 401, conditionText: "extractCheck(obj.CA10__kmsKeyArn__c)", currentStateMessage: "Related object via CA10__kmsKeyArn__c has empty ID", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (TextLib.isEmpty(obj.CA10__kmsKey__c)) {
              throw new Error("UNDETERMINED condition:402", {cause: {status: 'UNDETERMINED', conditionIndex: 402, conditionText: "extractCheck(obj.CA10__kmsKey__c)", currentStateMessage: "Related object via CA10__kmsKey__c is not present", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (obj.CA10__kmsKey__r.CA10__disappearanceTime__c != null) {
              throw new Error("UNDETERMINED condition:403", {cause: {status: 'UNDETERMINED', conditionIndex: 403, conditionText: "extractCheck(obj.CA10__kmsKey__r.CA10__disappearanceTime__c)", currentStateMessage: "Related object via CA10__kmsKey__c is present, but deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return extract9.call(extract9);
      }
      function fieldChecked10() {
          if (TextLib.isEmpty(obj.CA10__kmsKey__r.CA10__manager__c)) {
              throw new Error("UNDETERMINED condition:404", {cause: {status: 'UNDETERMINED', conditionIndex: 404, conditionText: "CA10__manager__c.delegatedTo(CA10__manager__c).isEmpty()", currentStateMessage: "Unable to determine Key Manager. Possible permission issue with kms:DescribeKey.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__kmsKey__r.CA10__manager__c;
      }
      function extract9() { if (!this.out) { this.out = fieldChecked10(); } return this.out; };
      references1.push('Manager [obj.CA10__kmsKey__r.CA10__manager__c]: ' + obj.CA10__kmsKey__r.CA10__manager__c);
      try {
          if (TextLib.notEqual(extractChecked8(), 'CUSTOMER')) {
              return {status: 'INCOMPLIANT', conditionIndex: 499, conditionText: "extract('CA10__kmsKey__r.CA10__manager__c') != 'CUSTOMER'", currentStateMessage: "The attached EBS volume is not encrypted using a KMS customer-managed keys.", currentStateReferences: references1.join('\n'), remediation: "Enable KMS customer-managed keys encryption for the volume.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[5], conditionIndex:[500..599]
      function extract12() { if (!this.out) { this.out = obj.CA10__encrypted__c; } return this.out; };
      function extractChecked14() {
          if (TextLib.isEmpty(obj.CA10__kmsKeyArn__c)) {
              throw new Error("UNDETERMINED condition:501", {cause: {status: 'UNDETERMINED', conditionIndex: 501, conditionText: "extractCheck(obj.CA10__kmsKeyArn__c)", currentStateMessage: "Related object via CA10__kmsKeyArn__c has empty ID", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (TextLib.isEmpty(obj.CA10__kmsKey__c)) {
              throw new Error("UNDETERMINED condition:502", {cause: {status: 'UNDETERMINED', conditionIndex: 502, conditionText: "extractCheck(obj.CA10__kmsKey__c)", currentStateMessage: "Related object via CA10__kmsKey__c is not present", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (obj.CA10__kmsKey__r.CA10__disappearanceTime__c != null) {
              throw new Error("UNDETERMINED condition:503", {cause: {status: 'UNDETERMINED', conditionIndex: 503, conditionText: "extractCheck(obj.CA10__kmsKey__r.CA10__disappearanceTime__c)", currentStateMessage: "Related object via CA10__kmsKey__c is present, but deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return extract15.call(extract15);
      }
      function fieldChecked16() {
          if (TextLib.isEmpty(obj.CA10__kmsKey__r.CA10__manager__c)) {
              throw new Error("UNDETERMINED condition:504", {cause: {status: 'UNDETERMINED', conditionIndex: 504, conditionText: "CA10__manager__c.delegatedTo(CA10__manager__c).isEmpty()", currentStateMessage: "Unable to determine Key Manager. Possible permission issue with kms:DescribeKey.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__kmsKey__r.CA10__manager__c;
      }
      function extract15() { if (!this.out) { this.out = fieldChecked16(); } return this.out; };
      try {
          if (extract12.call(extract12) == true && TextLib.equal(extractChecked14(), 'CUSTOMER')) {
              return {status: 'COMPLIANT', conditionIndex: 599, conditionText: "extract('CA10__encrypted__c') == true && extract('CA10__kmsKey__r.CA10__manager__c') == 'CUSTOMER'", currentStateMessage: "The attached EBS volume is encrypted using a KMS customer-managed key.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'UNDETERMINED', conditionIndex: 600, conditionText: "otherwise", currentStateMessage: "Unexpected values in the field.", 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.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__status__c AS CA10__status__c,
          sObject.CA10__encrypted__c AS CA10__encrypted__c,
          sObject.CA10__kmsKey__c AS CA10__kmsKey__c,
          sObject.CA10__kmsKeyArn__c AS CA10__kmsKeyArn__c,
          sObject.Id AS Id,
          STRUCT (
              `CA10__kmsKey__r`.Id AS Id,
              `CA10__kmsKey__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
              `CA10__kmsKey__r`.CA10__manager__c AS CA10__manager__c
          ) AS CA10__kmsKey__r,
          process_CA10__CaAwsVolume__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__status__c AS CA10__status__c,
                  sObject.CA10__encrypted__c AS CA10__encrypted__c,
                  sObject.CA10__kmsKey__c AS CA10__kmsKey__c,
                  sObject.CA10__kmsKeyArn__c AS CA10__kmsKeyArn__c,
                  sObject.Id AS Id,
                  STRUCT (
                      `CA10__kmsKey__r`.Id AS Id,
                      `CA10__kmsKey__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      `CA10__kmsKey__r`.CA10__manager__c AS CA10__manager__c
                  ) AS CA10__kmsKey__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsVolume__c()) AS sObject
      LEFT JOIN UNNEST(mock_CA10__CaAwsKmsKey__c()) AS `CA10__kmsKey__r`
          ON sObject.CA10__kmsKey__c = `CA10__kmsKey__r`.Id
  ) sObject ON sObject.Id = expectedResult.Id;
