---
policy: /ce/ca/aws/iam/detach-aws-cloudshell-full-access-policy
logic: /ce/ca/aws/iam/detach-aws-cloudshell-full-access-policy/prod.logic.yaml
executionTime: 2025-04-24T23:44:52.905257981Z
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__name__c') != 'AWSCloudShellFullAccess'
      actual: extract('CA10__name__c') != 'AWSCloudShellFullAccess'
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: CA10__AWS_IAM_Role_Policy_Attachments__r.has(INCOMPLIANT)
      actual: CA10__AWS_IAM_Role_Policy_Attachments__r.has(INCOMPLIANT)
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test5
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test6
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/iam/detach-aws-cloudshell-full-access-policy/policy.yaml
    md5Hash: 0D521E78AB0752EF9203C8492679759F
    content: |
      ---
      names:
        full: AWS IAM AWSCloudShellFullAccess Policy is attached
        contextual: AWSCloudShellFullAccess Policy is attached
      description: "AWS CloudShell is a convenient way of running CLI commands against AWS\
        \ services. AWSCloudShellFullAccess managed IAM policy provides full access to CloudShell,\
        \ which allows file upload and download capability between a user's local system\
        \ and the CloudShell environment. Within the CloudShell environment a user has sudo\
        \ permissions, and can access the internet. So it is feasible to install file transfer\
        \ software (for example) and move data from CloudShell to external internet servers."
      type: COMPLIANCE_POLICY
      categories:
        - SECURITY
      frameworkMappings:
        - "/frameworks/cis-aws-v5.0.0/01/21"
        - "/frameworks/cloudaware/identity-and-access-governance/general-access-controls"
  - path: /ce/ca/aws/iam/detach-aws-cloudshell-full-access-policy/prod.logic.yaml
    md5Hash: 260A9C3BD1DA546E1F70D2E4B5523DFE
    content: "---\ninputType: \"CA10__CaAwsIamPolicy__c\"\ntestData:\n  - file: \"\
      test-data.json\"\nimportExtracts:\n  - file: \"/types/CA10__CaAwsIamPolicy__c/object.extracts.yaml\"\
      \nconditions:\n  - status: \"INAPPLICABLE\"\n    currentStateMessage: \"This\
      \ is not a AWSCloudShellFullAccess policy.\" \n    check:\n      NOT_EQUAL:\n\
      \        left:\n          EXTRACT: \"CA10__name__c\"\n        right:\n     \
      \     TEXT: \"AWSCloudShellFullAccess\"\n  - status: \"INCOMPLIANT\"\n    currentStateMessage:\
      \ \"AWSCloudShellFullAccess policy is attached to a role.\"\n    remediationMessage:\
      \ \"Consider detaching the AWSCloudShellFullAccess policy.\"\n    check:\n \
      \     RELATED_LIST_HAS:\n        status: \"INCOMPLIANT\"\n        relationshipName:\
      \ \"CA10__AWS_IAM_Role_Policy_Attachments__r\"\notherwise:\n  status: \"COMPLIANT\"\
      \n  currentStateMessage: \"AWSCloudShellFullAccess policy is not attached.\"\
      \nrelatedLists:\n  - relationshipName: \"CA10__AWS_IAM_Role_Policy_Attachments__r\"\
      \n    conditions:\n      - status: \"INCOMPLIANT\"\n        currentStateMessage:\
      \ \"AWSCloudShellFullAccess policy is attached to a role.\"\n        remediationMessage:\
      \ \"Consider detaching the AWSCloudShellFullAccess policy.\"\n        check:\n\
      \          NOT_EMPTY_LOOKUP: \"CA10__role__r\"\n    otherwise:\n      status:\
      \ \"COMPLIANT\"\n      currentStateMessage: \"AWSCloudShellFullAccess policy\
      \ is not attached.\""
  - path: /types/CA10__CaAwsIamPolicy__c/object.extracts.yaml
    md5Hash: C48327B50CE4EB54B3C6B2B464134BB3
    content: "# yaml-language-server: $schema=../../schema/Extracts.schema.json\n\
      ---\nextracts:\n# Not Nullable. Can't have no Access, retrieved via iam:ListPolicies\n\
      - name: \"CA10__name__c\"\n  value: \n    FIELD:\n      path: \"CA10__name__c\"\
      \n      undeterminedIf:\n        isEmpty: \"Corrupted data. Policy Name cannot\
      \ be empty.\"\n# Checkbox. Can't have no Access, retrieved via iam:ListPolicies\n\
      - name: \"CA10__attachable__c\"\n  value: \n    FIELD:\n      path: \"CA10__attachable__c\"\
      \n- name: \"CA10__attachmentCount__c\"\n  value: \n    FIELD:\n      path: \"\
      CA10__attachmentCount__c\"\n- name: \"CA10__policyDocument__c\"\n  value: \n\
      \    FIELD:\n      path: CA10__policyDocument__c\n      returnType: BYTES\n\
      \      undeterminedIf:\n        noAccessDelegate:\n          path: \"CA10__policyDocument__c\"\
      \n          currentStateMessage: \"Unable to determine the Policy Document.\
      \ Possible permission issue with iam:GetPolicyVersion\"\n- name: \"caJsonFrom_policyDocument__c\"\
      \n  value:\n    JSON_FROM:\n      arg:\n        EXTRACT: \"CA10__policyDocument__c\"\
      \n      undeterminedIf:\n        isInvalid: \"IAM policy document JSON is invalid\"\
      \n# Not Nullable. Can't have no Access, retrieved via iam:ListPolicies\n- name:\
      \ \"CA10__arn__c\"\n  value: \n    FIELD:\n      path: CA10__arn__c\n      undeterminedIf:\n\
      \        isEmpty: \"Corrupted data. Policy ARN cannot be empty.\"\n"
  - path: /ce/ca/aws/iam/detach-aws-cloudshell-full-access-policy/test-data.json
    md5Hash: EC23AD1C2566AEA6DAD8CD6295140BC6
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-07-10T20:44:00Z"
              },
              "Id": "test1",
              "CA10__disappearanceTime__c": "2024-07-10T03:39:54Z",
              "CA10__name__c": "policyName1",
              "CA10__AWS_IAM_Role_Policy_Attachments__r": [
                  {
                      "Id": "test1_1",
                      "CA10__disappearanceTime__c": "2024-07-09T21:50:34Z",
                      "CA10__role__c": "role1",
                      "CA10__roleArn__c": "arn:aws:iam::012345678910:role/roleName1",
                      "CA10__policy__c": "test1",
                      "CA10__role__r": {
                          "Id": "role1",
                          "CA10__disappearanceTime__c": "2024-07-09T21:48:35Z"
                      }
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__name__c') != 'AWSCloudShellFullAccess'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-07-10T20:44:00Z"
              },
              "Id": "test2",
              "CA10__disappearanceTime__c": null,
              "CA10__name__c": "policyName2",
              "CA10__AWS_IAM_Role_Policy_Attachments__r": [
                  {
                      "Id": "test2_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__role__c": "role2",
                      "CA10__roleArn__c": "arn:aws:iam::012345678910:role/roleName2",
                      "CA10__policy__c": "test2",
                      "CA10__role__r": {
                          "Id": "role2",
                          "CA10__disappearanceTime__c": null
                      }
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "CA10__AWS_IAM_Role_Policy_Attachments__r.has(INCOMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-07-10T20:44:00Z"
              },
              "Id": "test3",
              "CA10__disappearanceTime__c": null,
              "CA10__name__c": "AWSCloudShellFullAccess",
              "CA10__AWS_IAM_Role_Policy_Attachments__r": [
                  {
                      "Id": "test3_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__role__c": "role3",
                      "CA10__roleArn__c": "arn:aws:iam::012345678910:role/roleName3",
                      "CA10__policy__c": "test3",
                      "CA10__role__r": {
                          "Id": "role3",
                          "CA10__disappearanceTime__c": null
                      }
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "300",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-07-10T20:44:00Z"
              },
              "Id": "test4",
              "CA10__disappearanceTime__c": null,
              "CA10__name__c": "AWSCloudShellFullAccess",
              "CA10__AWS_IAM_Role_Policy_Attachments__r": [
                  {
                      "Id": "test4_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__role__c": "role4",
                      "CA10__roleArn__c": "arn:aws:iam::012345678910:role/roleName4",
                      "CA10__policy__c": "test4",
                      "CA10__role__r": {
                          "Id": "role4",
                          "CA10__disappearanceTime__c": "2024-07-10T20:44:00Z"
                      }
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "300",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-07-10T20:44:00Z"
              },
              "Id": "test5",
              "CA10__disappearanceTime__c": null,
              "CA10__name__c": "AWSCloudShellFullAccess",
              "CA10__AWS_IAM_Role_Policy_Attachments__r": [
                  {
                      "Id": "test5_1",
                      "CA10__disappearanceTime__c": "2024-07-10T20:44:00Z",
                      "CA10__role__c": null,
                      "CA10__roleArn__c": "arn:aws:iam::012345678910:role/roleName5",
                      "CA10__policy__c": "test5",
                      "CA10__role__r": {
                          "Id": null,
                          "CA10__disappearanceTime__c": "2024-07-10T20:44:00Z"
                      }
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "300",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-07-10T20:44:00Z"
              },
              "Id": "test6",
              "CA10__disappearanceTime__c": null,
              "CA10__name__c": "AWSCloudShellFullAccess",
              "CA10__AWS_IAM_Role_Policy_Attachments__r": []
          }
      ]
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__name__c') != 'AWSCloudShellFullAccess'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "CA10__AWS_IAM_Role_Policy_Attachments__r.has(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test5",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test6",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsIamPolicy__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__name__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "test1",
    "CA10__disappearanceTime__c" : new Date("2024-07-10T03:39:54Z"),
    "CA10__name__c" : "policyName1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "test2",
    "CA10__name__c" : "policyName2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "test3",
    "CA10__name__c" : "AWSCloudShellFullAccess"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "test4",
    "CA10__name__c" : "AWSCloudShellFullAccess"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "test5",
    "CA10__name__c" : "AWSCloudShellFullAccess"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "test6",
    "CA10__name__c" : "AWSCloudShellFullAccess"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsIamRolePolicyAttachment__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__role__c STRING,
      CA10__roleArn__c STRING,
      CA10__policy__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "test1_1",
    "CA10__disappearanceTime__c" : new Date("2024-07-09T21:50:34Z"),
    "CA10__role__c" : "role1",
    "CA10__roleArn__c" : "arn:aws:iam::012345678910:role/roleName1",
    "CA10__policy__c" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "test2_1",
    "CA10__role__c" : "role2",
    "CA10__roleArn__c" : "arn:aws:iam::012345678910:role/roleName2",
    "CA10__policy__c" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "test3_1",
    "CA10__role__c" : "role3",
    "CA10__roleArn__c" : "arn:aws:iam::012345678910:role/roleName3",
    "CA10__policy__c" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "test4_1",
    "CA10__role__c" : "role4",
    "CA10__roleArn__c" : "arn:aws:iam::012345678910:role/roleName4",
    "CA10__policy__c" : "test4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "test5_1",
    "CA10__disappearanceTime__c" : new Date("2024-07-10T20:44:00Z"),
    "CA10__role__c" : null,
    "CA10__roleArn__c" : "arn:aws:iam::012345678910:role/roleName5",
    "CA10__policy__c" : "test5"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsRole__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "role1",
    "CA10__disappearanceTime__c" : new Date("2024-07-09T21:48:35Z")
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "role2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "role3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : "role4",
    "CA10__disappearanceTime__c" : new Date("2024-07-10T20:44:00Z")
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-07-10T20:44:00Z")
    },
    "Id" : null,
    "CA10__disappearanceTime__c" : new Date("2024-07-10T20:44:00Z")
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsIamPolicy__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__name__c STRING,
          CA10__AWS_IAM_Role_Policy_Attachments__r ARRAY<STRUCT<
              Id STRING,
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__role__c STRING,
              CA10__roleArn__c STRING,
              CA10__policy__c STRING,
              CA10__role__r STRUCT<
                  Id STRING,
                  CA10__disappearanceTime__c TIMESTAMP
              >,
              result STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
          >>
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
      var 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 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__name__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__name__c.isEmpty()", currentStateMessage: "Corrupted data. Policy Name cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__name__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Name [obj.CA10__name__c]: ' + obj.CA10__name__c);
      try {
          if (TextLib.notEqual(extract3.call(extract3), 'AWSCloudShellFullAccess')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__name__c') != 'AWSCloudShellFullAccess'", currentStateMessage: "This is not a AWSCloudShellFullAccess policy.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      var count_CA10__AWS_IAM_Role_Policy_Attachments__r_INCOMPLIANT5 = 0;
      if (obj.CA10__AWS_IAM_Role_Policy_Attachments__r != null) {
          for (var i6 = 0; i6 < obj.CA10__AWS_IAM_Role_Policy_Attachments__r.length; i6++) {
              if (obj.CA10__AWS_IAM_Role_Policy_Attachments__r[i6].result.status == 'INCOMPLIANT') {
                  count_CA10__AWS_IAM_Role_Policy_Attachments__r_INCOMPLIANT5 += 1;
              }
          }
      }
      // condition[2], conditionIndex:[200..299]
      references1.push('Related list [CA10__AWS_IAM_Role_Policy_Attachments__r] ' + (count_CA10__AWS_IAM_Role_Policy_Attachments__r_INCOMPLIANT5 > 0 ? 'has' : 'does not have') + ' objects in INCOMPLIANT status');
      if (count_CA10__AWS_IAM_Role_Policy_Attachments__r_INCOMPLIANT5 > 0) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "CA10__AWS_IAM_Role_Policy_Attachments__r.has(INCOMPLIANT)", currentStateMessage: "AWSCloudShellFullAccess policy is attached to a role.", currentStateReferences: references1.join('\n'), remediation: "Consider detaching the AWSCloudShellFullAccess policy.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "AWSCloudShellFullAccess policy is not attached.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__AWS_IAM_Role_Policy_Attachments__r(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__role__c STRING,
          CA10__roleArn__c STRING,
          CA10__policy__c STRING,
          CA10__role__r STRUCT<
              Id STRING,
              CA10__disappearanceTime__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));
          };
      }();
      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]
      if (TextLib.isNotEmpty(obj.CA10__roleArn__c) && TextLib.isNotEmpty(obj.CA10__role__c) && obj.CA10__role__r.CA10__disappearanceTime__c == null) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "notEmptyLookup('CA10__role__r')", currentStateMessage: "AWSCloudShellFullAccess policy is attached to a role.", currentStateReferences: references1.join('\n'), remediation: "Consider detaching the AWSCloudShellFullAccess policy.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "AWSCloudShellFullAccess policy is not attached.", 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__name__c AS CA10__name__c,
          `CA10__AWS_IAM_Role_Policy_Attachments__r`.arr AS CA10__AWS_IAM_Role_Policy_Attachments__r,
          process_CA10__CaAwsIamPolicy__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__name__c AS CA10__name__c,
                  `CA10__AWS_IAM_Role_Policy_Attachments__r`.arr AS CA10__AWS_IAM_Role_Policy_Attachments__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsIamPolicy__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10__policy__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__role__c AS CA10__role__c,
                      sObject.CA10__roleArn__c AS CA10__roleArn__c,
                      sObject.CA10__policy__c AS CA10__policy__c,
                      STRUCT (
                          `CA10__role__r`.Id AS Id,
                          `CA10__role__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c
                      ) AS CA10__role__r,
                      process_CA10__AWS_IAM_Role_Policy_Attachments__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__role__c AS CA10__role__c,
                              sObject.CA10__roleArn__c AS CA10__roleArn__c,
                              sObject.CA10__policy__c AS CA10__policy__c,
                              STRUCT (
                                  `CA10__role__r`.Id AS Id,
                                  `CA10__role__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c
                              ) AS CA10__role__r
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaAwsIamRolePolicyAttachment__c()) AS sObject
          LEFT JOIN UNNEST(mock_CA10__CaAwsRole__c()) AS `CA10__role__r`
              ON sObject.CA10__role__c = `CA10__role__r`.Id
          GROUP BY sObject.CA10__policy__c
      ) AS `CA10__AWS_IAM_Role_Policy_Attachments__r`
          ON sObject.Id = `CA10__AWS_IAM_Role_Policy_Attachments__r`.CA10__policy__c
  ) sObject ON sObject.Id = expectedResult.Id;
