---
policy: /ce/ca/aws/redshift/cluster-security-group-unrestricted-port
logic: /ce/ca/aws/redshift/cluster-security-group-unrestricted-port/prod.logic.yaml
executionTime: 2026-02-05T22:32:03.415622935Z
generationMs: 103
executionMs: 1212
rows:
  - id: test1
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__status__c') != 'available'
      actual: extract('CA10__status__c') != 'available'
    runtimeError: {}
  - id: test2
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__endpointPort2__c') != number(5439.0)
      actual: extract('CA10__endpointPort2__c') != number(5439.0)
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 400
      actual: 400
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: CA10__AWS_Redshift_Cluster_VPC_SG_Links__r.has(INCOMPLIANT)
      actual: CA10__AWS_Redshift_Cluster_VPC_SG_Links__r.has(INCOMPLIANT)
    runtimeError: {}
  - id: test5
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: CA10__AWS_Redshift_Cluster_VPC_SG_Links__r.has(INCOMPLIANT)
      actual: CA10__AWS_Redshift_Cluster_VPC_SG_Links__r.has(INCOMPLIANT)
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/redshift/cluster-security-group-unrestricted-port/policy.yaml
    md5Hash: A0BEA68413D24845F458234BC96C7900
    content: |
      ---
      names:
        full: "AWS Redshift Cluster security group allows unrestricted access on the cluster port"
        contextual: "Cluster security group allows unrestricted access on the cluster port"
      description: >
        Identify AWS Redshift clusters associated with VPC security groups that allow inbound
        access from any IP address (0.0.0.0/0 or ::/0) to the Redshift cluster port (TCP 5439).
        Restrict access to trusted CIDR ranges or approved network paths only.
      type: "COMPLIANCE_POLICY"
      categories:
        - "SECURITY"
      frameworkMappings:
        - "/frameworks/cloudaware/resource-security/secure-access"
        - "/frameworks/aws-fsbp-v1.0.0/redshift/15"
      similarPolicies:
        awsSecurityHub:
          - name: "[Redshift.15] Redshift security groups should allow ingress on the cluster port only from restricted origins"
            url: "https://docs.aws.amazon.com/securityhub/latest/userguide/redshift-controls.html#redshift-15"
  - path: /ce/ca/aws/redshift/cluster-security-group-unrestricted-port/prod.logic.yaml
    md5Hash: 4441A17447477953CCDCCBD5CC476792
    content: |
      ---
      inputType: "CA10__CaAwsRedshiftCluster__c"
      importExtracts:
        - file: "/types/CA10__CaAwsRedshiftCluster__c/object.extracts.yaml"
        - file: "/types/CA10__CaAwsSecurityGroupRule2__c/object.extracts.yaml"
      testData:
        - file: "test-data.json"
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "The cluster is not available."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10__status__c"
              right:
                TEXT: "available"
        - status: "INAPPLICABLE"
          currentStateMessage: "This policy only applies to the default port (TCP 5439)."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10__endpointPort2__c"
              right:
                NUMBER: 5439
        - status: "INCOMPLIANT"
          currentStateMessage: "The cluster is associated with a security group that\
            \ allows unrestricted inbound access to the Redshift port (TCP 5439)."
          remediationMessage: "Restrict inbound access to TCP 5439 by removing 0.0.0.0/0\
            \ and ::/0 rules or scoping them to trusted CIDRs only."
          check:
            RELATED_LIST_HAS:
              status: "INCOMPLIANT"
              relationshipName: "CA10__AWS_Redshift_Cluster_VPC_SG_Links__r"
      otherwise:
        status: "COMPLIANT"
        currentStateMessage: "The cluster does not allow unrestricted inbound access\
          \ to the Redshift port (TCP 5439)."
      relatedLists:
        - relationshipName: "CA10__AWS_Redshift_Cluster_VPC_SG_Links__r"
          conditions:
            - status: "INCOMPLIANT"
              currentStateMessage: "This security group allows unrestricted inbound\
                \ access to the Redshift port (TCP 5439)."
              remediationMessage: "Remove or scope down the incompliant inbound rule to trusted CIDRs."
              check:
                RELATED_LIST_HAS:
                  status: "INCOMPLIANT"
                  relationshipName: "CA10__securityGroup__r.CA10__AWS_EC2_Security_Group_Rules1__r"
          otherwise:
            status: "COMPLIANT"
            currentStateMessage: "This security group does not allow unrestricted inbound\
              \ access to the Redshift port."
          relatedLists:
            - relationshipName: "CA10__securityGroup__r.CA10__AWS_EC2_Security_Group_Rules1__r"
              conditions:
                - status: "INAPPLICABLE"
                  currentStateMessage: "This is an outbound security group rule."
                  check:
                    NOT_EQUAL:
                      left:
                        EXTRACT: "CA10__direction__c"
                      right:
                        TEXT: "Inbound"
                - status: "INAPPLICABLE"
                  currentStateMessage: "This is not an IP source based security group rule."
                  check:
                    NOT_EQUAL:
                      left:
                        EXTRACT: "CA10__source__c"
                      right:
                        TEXT: "IP"
                - status: "INAPPLICABLE"
                  currentStateMessage: "This security group rule does not allow unrestricted access."
                  check:
                    AND:
                      args:
                        - NOT_EQUAL:
                            left:
                              EXTRACT: "CA10__sourceIpRange__c"
                            right:
                              TEXT: "0.0.0.0/0"
                        - NOT_EQUAL:
                            left:
                              EXTRACT: "CA10__sourceIpRange__c"
                            right:
                              TEXT: "::/0"
                - status: "INAPPLICABLE"
                  currentStateMessage: "This security group rule protocol is not All or TCP."
                  check:
                    NOT:
                      arg:
                        OR:
                          args:
                            - IS_EQUAL:
                                left:
                                  EXTRACT: "CA10__protocol__c"
                                right:
                                  TEXT: "All"
                            - IS_EQUAL:
                                left:
                                  EXTRACT: "CA10__protocol__c"
                                right:
                                  TEXT: "tcp"
                - status: "INCOMPLIANT"
                  currentStateMessage: "This security group rule allows unrestricted access\
                    \ (0.0.0.0/0 or ::/0) to Redshift on TCP 5439."
                  remediationMessage: "Remove the rule or restrict the source CIDR(s)\
                    \ to trusted networks only."
                  check:
                    AND:
                      args:
                        - LESS_THAN_EQUAL:
                            left:
                              EXTRACT: "CA10__fromPort__c"
                            right:
                              NUMBER: 5439.0
                        - GREATER_THAN_EQUAL:
                            left:
                              EXTRACT: "CA10__toPort__c"
                            right:
                              NUMBER: 5439.0
              otherwise:
                status: "COMPLIANT"
                currentStateMessage: "This security group rule does not allow unrestricted\
                  \ access to TCP 5439."
  - path: /ce/ca/aws/redshift/cluster-security-group-unrestricted-port/test-data.json
    md5Hash: A5E8FD505BE6E4EC940416716D972AD7
    content: |-
      [
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__status__c') != 'available'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-02-02T09:33:27Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "paused",
              "CA10__endpointPort2__c": 5439,
              "Id": "test1",
              "CA10__AWS_Redshift_Cluster_VPC_SG_Links__r": [
                  {
                      "CA10__disappearanceTime__c": null,
                      "CA10__cluster__c": "test1",
                      "Id": "test1_1",
                      "CA10__securityGroup__c": "test1_2",
                      "CA10__securityGroup__r": {
                          "Id": "test1_2",
                          "CA10__AWS_EC2_Security_Group_Rules1__r": [
                              {
                                  "CA10__disappearanceTime__c": null,
                                  "CA10__direction__c": "Inbound",
                                  "CA10__source__c": "Group",
                                  "CA10__sourceIpRange__c": "",
                                  "CA10__protocol__c": "tcp",
                                  "CA10__fromPort__c": 0,
                                  "CA10__toPort__c": 65535,
                                  "CA10__sourceGroup__c": "test1_2",
                                  "Id": "test1_3"
                              }
                          ]
                      }
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "299",
                  "conditionText": "extract('CA10__endpointPort2__c') != number(5439.0)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-02-02T09:33:27Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "available",
              "CA10__endpointPort2__c": 5640,
              "Id": "test2",
              "CA10__AWS_Redshift_Cluster_VPC_SG_Links__r": [
                  {
                      "CA10__disappearanceTime__c": null,
                      "CA10__cluster__c": "test2",
                      "Id": "test2_1",
                      "CA10__securityGroup__c": "test2_2",
                      "CA10__securityGroup__r": {
                          "Id": "test2_2",
                          "CA10__AWS_EC2_Security_Group_Rules1__r": []
                      }
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "400",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-02-02T09:33:27Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "available",
              "CA10__endpointPort2__c": 5439,
              "Id": "test3",
              "CA10__AWS_Redshift_Cluster_VPC_SG_Links__r": [
                  {
                      "CA10__disappearanceTime__c": null,
                      "CA10__cluster__c": "test3",
                      "Id": "test3_1",
                      "CA10__securityGroup__c": "test3_2",
                      "CA10__securityGroup__r": {
                          "Id": "test3_2",
                          "CA10__AWS_EC2_Security_Group_Rules1__r": [
                              {
                                  "CA10__disappearanceTime__c": null,
                                  "CA10__direction__c": "Inbound",
                                  "CA10__source__c": "Group",
                                  "CA10__sourceIpRange__c": "",
                                  "CA10__protocol__c": "tcp",
                                  "CA10__fromPort__c": 0,
                                  "CA10__toPort__c": 65535,
                                  "CA10__sourceGroup__c": "test3_2",
                                  "Id": "test3_3"
                              }
                          ]
                      }
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "399",
                  "conditionText": "CA10__AWS_Redshift_Cluster_VPC_SG_Links__r.has(INCOMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-02-02T09:33:27Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "available",
              "CA10__endpointPort2__c": 5439,
              "Id": "test4",
              "CA10__AWS_Redshift_Cluster_VPC_SG_Links__r": [
                  {
                      "CA10__disappearanceTime__c": null,
                      "CA10__cluster__c": "test4",
                      "Id": "test4_1",
                      "CA10__securityGroup__c": "test4_2",
                      "CA10__securityGroup__r": {
                          "Id": "test4_2",
                          "CA10__AWS_EC2_Security_Group_Rules1__r": [
                              {
                                  "CA10__disappearanceTime__c": null,
                                  "CA10__direction__c": "Inbound",
                                  "CA10__source__c": "IP",
                                  "CA10__sourceIpRange__c": "0.0.0.0/0",
                                  "CA10__protocol__c": "tcp",
                                  "CA10__fromPort__c": 0,
                                  "CA10__toPort__c": 65535,
                                  "CA10__sourceGroup__c": "test4_2",
                                  "Id": "test4_3"
                              }
                          ]
                      }
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "399",
                  "conditionText": "CA10__AWS_Redshift_Cluster_VPC_SG_Links__r.has(INCOMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-02-02T09:33:27Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "available",
              "CA10__endpointPort2__c": 5439,
              "Id": "test5",
              "CA10__AWS_Redshift_Cluster_VPC_SG_Links__r": [
                  {
                      "CA10__disappearanceTime__c": null,
                      "CA10__cluster__c": "test5",
                      "Id": "test5_1",
                      "CA10__securityGroup__c": "test5_2",
                      "CA10__securityGroup__r": {
                          "Id": "test5_2",
                          "CA10__AWS_EC2_Security_Group_Rules1__r": [
                              {
                                  "CA10__disappearanceTime__c": null,
                                  "CA10__direction__c": "Inbound",
                                  "CA10__source__c": "IP",
                                  "CA10__sourceIpRange__c": "0.0.0.0/0",
                                  "CA10__protocol__c": "tcp",
                                  "CA10__fromPort__c": 5439,
                                  "CA10__toPort__c": 5439,
                                  "CA10__sourceGroup__c": "test5_2",
                                  "Id": "test5_3"
                              }
                          ]
                      }
                  }
              ]
          }
      ]
  - path: /types/CA10__CaAwsSecurityGroupRule2__c/object.extracts.yaml
    md5Hash: 58DC1872D7462985D50972C65C61C237
    content: "---\nextracts:\n# Values: IP, Group, PrefixList. Nullable, it can be\
      \ prefix list if empty. Can't have no access, retrieved via ec2:DescribeSecurityGroups\n\
      \  - name: \"CA10__source__c\"\n    value: \n      FIELD:\n        path: \"\
      CA10__source__c\"\n# Values: IPv4, IPv6. Nullable it is not the IP source if\
      \ empty. Can't have no access, retrieved via ec2:DescribeSecurityGroups\n  -\
      \ name: \"CA10__sourceIpVersion__c\"\n    value: \n      FIELD:\n        path:\
      \ \"CA10__sourceIpVersion__c\"\n# Nullable. Can't have no access, retrieved\
      \ via ec2:DescribeSecurityGroups\n  - name: \"CA10__sourceIpRange__c\"\n   \
      \ value: \n      FIELD:\n        path: \"CA10__sourceIpRange__c\"\n# Values:\
      \ Inbound, Outbound. Not nullable. Can't have no access, retrieved via ec2:DescribeSecurityGroups\n\
      \  - name: \"CA10__direction__c\"\n    value: \n      FIELD:\n        path:\
      \ \"CA10__direction__c\"\n        undeterminedIf:\n          isEmpty: \"Corrupted\
      \ data. Rule Action cannot be empty.\"\n# Not nullable. Can't have no access,\
      \ retrieved via ec2:DescribeSecurityGroups\n  - name: \"CA10__protocol__c\"\n\
      \    value: \n      FIELD:\n        path: \"CA10__protocol__c\"\n        undeterminedIf:\n\
      \          isEmpty: \"Corrupted data. Protocol cannot be empty.\"\n# Nullable.\
      \ Can't have no access, retrieved via ec2:DescribeSecurityGroups\n  - name:\
      \ \"CA10__fromPort__c\"\n    value: \n      FIELD:\n        path: \"CA10__fromPort__c\"\
      \n# Nullable. Can't have no access, retrieved via ec2:DescribeSecurityGroups\n\
      \  - name: \"CA10__toPort__c\"\n    value: \n      FIELD:\n        path: \"\
      CA10__toPort__c\"\n"
  - path: /types/CA10__CaAwsRedshiftCluster__c/object.extracts.yaml
    md5Hash: 978033E93A3BC4EEE31B6916039330FF
    content: |
      ---
      extracts:
      # Nullable. Values: available, modifying, creating ...
        - name: "CA10__status__c"
          value:
            FIELD:
              path: "CA10__status__c"
      # Nullable.
        - name: "CA10__createTime__c"
          value:
            FIELD:
              path: "CA10__createTime__c"
      # Nullable.
        - name: "CA10__cpuUtilizationAvg30d__c"
          value:
            FIELD:
              path: "CA10__cpuUtilizationAvg30d__c"
      # Nullable.
        - name: "CA10__diskReadIopsAvg30d__c"
          value:
            FIELD:
              path: "CA10__diskReadIopsAvg30d__c"
      # Nullable.
        - name: "CA10__diskWriteIopsAvg30d__c"
          value:
            FIELD:
              path: "CA10__diskWriteIopsAvg30d__c"
      # Nullable.
        - name: "CA10__logging__c"
          value:
            FIELD:
              path: "CA10__logging__c"
      # Nullable.
        - name: "CA10__automatedSnapshotRetentionPeriod__c"
          value:
            FIELD:
              path: "CA10__automatedSnapshotRetentionPeriod__c"
      # Text.
        - name: "CA10__encryption__c"
          value:
            FIELD:
              path: "CA10__encryption__c"
      # Text.
        - name: "CA10__masterUsername__c"
          value:
            FIELD:
              path: "CA10__masterUsername__c"
      # Text.
        - name: "CA10__versionUpgrade__c"
          value:
            FIELD:
              path: "CA10__versionUpgrade__c"
      # Values: Yes | No. Not nullable. Can't have no access, retrieved via redshift:DescribeClusters
        - name: "CA10__publiclyAccessible__c"
          value:
            FIELD:
              path: "CA10__publiclyAccessible__c"
      # Values: Enabled | Disabled. Not nullable. Can't have no access, retrieved via redshift:DescribeClusters
        - name: "CA10__enhancedVpcRouting2__c"
          value:
            FIELD:
              path: "CA10__enhancedVpcRouting2__c"
      # Number
        - name: "CA10__endpointPort2__c"
          value:
            FIELD:
              path: "CA10__endpointPort2__c"
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" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__status__c') != 'available'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__endpointPort2__c') != number(5439.0)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "400",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "CA10__AWS_Redshift_Cluster_VPC_SG_Links__r.has(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test5",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "CA10__AWS_Redshift_Cluster_VPC_SG_Links__r.has(INCOMPLIANT)",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsRedshiftCluster__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__status__c STRING,
      CA10__endpointPort2__c FLOAT64,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2026-02-02T09:33:27Z")
    },
    "CA10__status__c" : "paused",
    "CA10__endpointPort2__c" : 5439,
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-02-02T09:33:27Z")
    },
    "CA10__status__c" : "available",
    "CA10__endpointPort2__c" : 5640,
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-02-02T09:33:27Z")
    },
    "CA10__status__c" : "available",
    "CA10__endpointPort2__c" : 5439,
    "Id" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-02-02T09:33:27Z")
    },
    "CA10__status__c" : "available",
    "CA10__endpointPort2__c" : 5439,
    "Id" : "test4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-02-02T09:33:27Z")
    },
    "CA10__status__c" : "available",
    "CA10__endpointPort2__c" : 5439,
    "Id" : "test5"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsRedshiftClusterVpcSecurityGroupLink__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__cluster__c STRING,
      Id STRING,
      CA10__securityGroup__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2026-02-02T09:33:27Z")
    },
    "CA10__cluster__c" : "test1",
    "Id" : "test1_1",
    "CA10__securityGroup__c" : "test1_2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-02-02T09:33:27Z")
    },
    "CA10__cluster__c" : "test2",
    "Id" : "test2_1",
    "CA10__securityGroup__c" : "test2_2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-02-02T09:33:27Z")
    },
    "CA10__cluster__c" : "test3",
    "Id" : "test3_1",
    "CA10__securityGroup__c" : "test3_2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-02-02T09:33:27Z")
    },
    "CA10__cluster__c" : "test4",
    "Id" : "test4_1",
    "CA10__securityGroup__c" : "test4_2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-02-02T09:33:27Z")
    },
    "CA10__cluster__c" : "test5",
    "Id" : "test5_1",
    "CA10__securityGroup__c" : "test5_2"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsSecurityGroup__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2026-02-02T09:33:27Z")
    },
    "Id" : "test1_2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-02-02T09:33:27Z")
    },
    "Id" : "test2_2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-02-02T09:33:27Z")
    },
    "Id" : "test3_2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-02-02T09:33:27Z")
    },
    "Id" : "test4_2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-02-02T09:33:27Z")
    },
    "Id" : "test5_2"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsSecurityGroupRule2__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__direction__c STRING,
      CA10__source__c STRING,
      CA10__sourceIpRange__c STRING,
      CA10__protocol__c STRING,
      CA10__fromPort__c FLOAT64,
      CA10__toPort__c FLOAT64,
      CA10__sourceGroup__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2026-02-02T09:33:27Z")
    },
    "CA10__direction__c" : "Inbound",
    "CA10__source__c" : "Group",
    "CA10__sourceIpRange__c" : "",
    "CA10__protocol__c" : "tcp",
    "CA10__fromPort__c" : 0,
    "CA10__toPort__c" : 65535,
    "CA10__sourceGroup__c" : "test1_2",
    "Id" : "test1_3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-02-02T09:33:27Z")
    },
    "CA10__direction__c" : "Inbound",
    "CA10__source__c" : "Group",
    "CA10__sourceIpRange__c" : "",
    "CA10__protocol__c" : "tcp",
    "CA10__fromPort__c" : 0,
    "CA10__toPort__c" : 65535,
    "CA10__sourceGroup__c" : "test3_2",
    "Id" : "test3_3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-02-02T09:33:27Z")
    },
    "CA10__direction__c" : "Inbound",
    "CA10__source__c" : "IP",
    "CA10__sourceIpRange__c" : "0.0.0.0/0",
    "CA10__protocol__c" : "tcp",
    "CA10__fromPort__c" : 0,
    "CA10__toPort__c" : 65535,
    "CA10__sourceGroup__c" : "test4_2",
    "Id" : "test4_3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-02-02T09:33:27Z")
    },
    "CA10__direction__c" : "Inbound",
    "CA10__source__c" : "IP",
    "CA10__sourceIpRange__c" : "0.0.0.0/0",
    "CA10__protocol__c" : "tcp",
    "CA10__fromPort__c" : 5439,
    "CA10__toPort__c" : 5439,
    "CA10__sourceGroup__c" : "test5_2",
    "Id" : "test5_3"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsRedshiftCluster__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__status__c STRING,
          CA10__endpointPort2__c FLOAT64,
          Id STRING,
          CA10__AWS_Redshift_Cluster_VPC_SG_Links__r ARRAY<STRUCT<
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__cluster__c STRING,
              Id STRING,
              CA10__securityGroup__c STRING,
              CA10__securityGroup__r STRUCT<
                  Id STRING,
                  CA10__AWS_EC2_Security_Group_Rules1__r ARRAY<STRUCT<
                      CA10__disappearanceTime__c TIMESTAMP,
                      CA10__direction__c STRING,
                      CA10__source__c STRING,
                      CA10__sourceIpRange__c STRING,
                      CA10__protocol__c STRING,
                      CA10__fromPort__c FLOAT64,
                      CA10__toPort__c FLOAT64,
                      CA10__sourceGroup__c STRING,
                      Id STRING,
                      result STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
                  >>
              >,
              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));
      };
      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), 'available')) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__status__c') != 'available'", currentStateMessage: "The cluster is not available.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10__endpointPort2__c; } return this.out; };
      references1.push('Endpoint Port [obj.CA10__endpointPort2__c]: ' + obj.CA10__endpointPort2__c);
      if (extract6.call(extract6) != 5439.0) {
          return {status: 'INAPPLICABLE', conditionIndex: 299, conditionText: "extract('CA10__endpointPort2__c') != number(5439.0)", currentStateMessage: "This policy only applies to the default port (TCP 5439).", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10__AWS_Redshift_Cluster_VPC_SG_Links__r_INCOMPLIANT8 = 0;
      if (obj.CA10__AWS_Redshift_Cluster_VPC_SG_Links__r != null) {
          for (var i9 = 0; i9 < obj.CA10__AWS_Redshift_Cluster_VPC_SG_Links__r.length; i9++) {
              if (typeof(obj.CA10__AWS_Redshift_Cluster_VPC_SG_Links__r[i9].status) !== 'undefined') {
                  if (obj.CA10__AWS_Redshift_Cluster_VPC_SG_Links__r[i9].status == 'INCOMPLIANT') {
                      count_CA10__AWS_Redshift_Cluster_VPC_SG_Links__r_INCOMPLIANT8 += obj.CA10__AWS_Redshift_Cluster_VPC_SG_Links__r[i9].count;
                  }
              } else  {
                  if (obj.CA10__AWS_Redshift_Cluster_VPC_SG_Links__r[i9].result.status == 'INCOMPLIANT') {
                      count_CA10__AWS_Redshift_Cluster_VPC_SG_Links__r_INCOMPLIANT8 += 1;
                  }
              }
          }
      }
      // condition[3], conditionIndex:[300..399]
      references1.push('Related list [CA10__AWS_Redshift_Cluster_VPC_SG_Links__r] ' + (count_CA10__AWS_Redshift_Cluster_VPC_SG_Links__r_INCOMPLIANT8 > 0 ? 'has' : 'does not have') + ' objects in INCOMPLIANT status');
      if (count_CA10__AWS_Redshift_Cluster_VPC_SG_Links__r_INCOMPLIANT8 > 0) {
          return {status: 'INCOMPLIANT', conditionIndex: 399, conditionText: "CA10__AWS_Redshift_Cluster_VPC_SG_Links__r.has(INCOMPLIANT)", currentStateMessage: "The cluster is associated with a security group that allows unrestricted inbound access to the Redshift port (TCP 5439).", currentStateReferences: references1.join('\n'), remediation: "Restrict inbound access to TCP 5439 by removing 0.0.0.0/0 and ::/0 rules or scoping them to trusted CIDRs only.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "The cluster does not allow unrestricted inbound access to the Redshift port (TCP 5439).", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__AWS_Redshift_Cluster_VPC_SG_Links__r(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__cluster__c STRING,
          Id STRING,
          CA10__securityGroup__c STRING,
          CA10__securityGroup__r STRUCT<
              Id STRING,
              CA10__AWS_EC2_Security_Group_Rules1__r ARRAY<STRUCT<
                  CA10__disappearanceTime__c TIMESTAMP,
                  CA10__direction__c STRING,
                  CA10__source__c STRING,
                  CA10__sourceIpRange__c STRING,
                  CA10__protocol__c STRING,
                  CA10__fromPort__c FLOAT64,
                  CA10__toPort__c FLOAT64,
                  CA10__sourceGroup__c STRING,
                  Id STRING,
                  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 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};
      }
      var count_CA10__securityGroup__r_CA10__AWS_EC2_Security_Group_Rules1__r_INCOMPLIANT2 = 0;
      if (obj.CA10__securityGroup__r.CA10__AWS_EC2_Security_Group_Rules1__r != null) {
          for (var i3 = 0; i3 < obj.CA10__securityGroup__r.CA10__AWS_EC2_Security_Group_Rules1__r.length; i3++) {
              if (typeof(obj.CA10__securityGroup__r.CA10__AWS_EC2_Security_Group_Rules1__r[i3].status) !== 'undefined') {
                  if (obj.CA10__securityGroup__r.CA10__AWS_EC2_Security_Group_Rules1__r[i3].status == 'INCOMPLIANT') {
                      count_CA10__securityGroup__r_CA10__AWS_EC2_Security_Group_Rules1__r_INCOMPLIANT2 += obj.CA10__securityGroup__r.CA10__AWS_EC2_Security_Group_Rules1__r[i3].count;
                  }
              } else  {
                  if (obj.CA10__securityGroup__r.CA10__AWS_EC2_Security_Group_Rules1__r[i3].result.status == 'INCOMPLIANT') {
                      count_CA10__securityGroup__r_CA10__AWS_EC2_Security_Group_Rules1__r_INCOMPLIANT2 += 1;
                  }
              }
          }
      }
      // condition[1], conditionIndex:[100..199]
      references1.push('Related list [CA10__securityGroup__r.CA10__AWS_EC2_Security_Group_Rules1__r] ' + (count_CA10__securityGroup__r_CA10__AWS_EC2_Security_Group_Rules1__r_INCOMPLIANT2 > 0 ? 'has' : 'does not have') + ' objects in INCOMPLIANT status');
      if (count_CA10__securityGroup__r_CA10__AWS_EC2_Security_Group_Rules1__r_INCOMPLIANT2 > 0) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "CA10__securityGroup__r.CA10__AWS_EC2_Security_Group_Rules1__r.has(INCOMPLIANT)", currentStateMessage: "This security group allows unrestricted inbound access to the Redshift port (TCP 5439).", currentStateReferences: references1.join('\n'), remediation: "Remove or scope down the incompliant inbound rule to trusted CIDRs.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "This security group does not allow unrestricted inbound access to the Redshift port.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__AWS_Redshift_Cluster_VPC_SG_Links__r_CA10__securityGroup__r_CA10__AWS_EC2_Security_Group_Rules1__r(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__direction__c STRING,
          CA10__source__c STRING,
          CA10__sourceIpRange__c STRING,
          CA10__protocol__c STRING,
          CA10__fromPort__c FLOAT64,
          CA10__toPort__c FLOAT64,
          CA10__sourceGroup__c STRING,
          Id 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 fieldChecked4() {
          if (TextLib.isEmpty(obj.CA10__direction__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__direction__c.isEmpty()", currentStateMessage: "Corrupted data. Rule Action cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__direction__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Direction [obj.CA10__direction__c]: ' + obj.CA10__direction__c);
      try {
          if (TextLib.notEqual(extract3.call(extract3), 'Inbound')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__direction__c') != 'Inbound'", currentStateMessage: "This is an outbound security group rule.", 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 extract6() { if (!this.out) { this.out = obj.CA10__source__c; } return this.out; };
      references1.push('Source [obj.CA10__source__c]: ' + obj.CA10__source__c);
      if (TextLib.notEqual(extract6.call(extract6), 'IP')) {
          return {status: 'INAPPLICABLE', conditionIndex: 299, conditionText: "extract('CA10__source__c') != 'IP'", currentStateMessage: "This is not an IP source based security group rule.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      function extract9() { if (!this.out) { this.out = obj.CA10__sourceIpRange__c; } return this.out; };
      references1.push('Source IP Range [obj.CA10__sourceIpRange__c]: ' + obj.CA10__sourceIpRange__c);
      if (TextLib.notEqual(extract9.call(extract9), '0.0.0.0/0') && TextLib.notEqual(extract9.call(extract9), '::/0')) {
          return {status: 'INAPPLICABLE', conditionIndex: 399, conditionText: "extract('CA10__sourceIpRange__c') != '0.0.0.0/0' && extract('CA10__sourceIpRange__c') != '::/0'", currentStateMessage: "This security group rule does not allow unrestricted access.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[4], conditionIndex:[400..499]
      function fieldChecked14() {
          if (TextLib.isEmpty(obj.CA10__protocol__c)) {
              throw new Error("UNDETERMINED condition:401", {cause: {status: 'UNDETERMINED', conditionIndex: 401, conditionText: "CA10__protocol__c.isEmpty()", currentStateMessage: "Corrupted data. Protocol cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__protocol__c;
      }
      function extract13() { if (!this.out) { this.out = fieldChecked14(); } return this.out; };
      references1.push('Protocol [obj.CA10__protocol__c]: ' + obj.CA10__protocol__c);
      try {
          if (!(TextLib.equal(extract13.call(extract13), 'All') || TextLib.equal(extract13.call(extract13), 'tcp'))) {
              return {status: 'INAPPLICABLE', conditionIndex: 499, conditionText: "not(extract('CA10__protocol__c') == 'All' || extract('CA10__protocol__c') == 'tcp')", currentStateMessage: "This security group rule protocol is not All or TCP.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[5], conditionIndex:[500..599]
      function extract18() { if (!this.out) { this.out = obj.CA10__fromPort__c; } return this.out; };
      function extract22() { if (!this.out) { this.out = obj.CA10__toPort__c; } return this.out; };
      references1.push('From Port [obj.CA10__fromPort__c]: ' + obj.CA10__fromPort__c);
      references1.push('To Port [obj.CA10__toPort__c]: ' + obj.CA10__toPort__c);
      if ((extract18.call(extract18) != null && 5439.0 != null && extract18.call(extract18) <= 5439.0) && (extract22.call(extract22) != null && 5439.0 != null && extract22.call(extract22) >= 5439.0)) {
          return {status: 'INCOMPLIANT', conditionIndex: 599, conditionText: "extract('CA10__fromPort__c') <= number(5439.0) && extract('CA10__toPort__c') >= number(5439.0)", currentStateMessage: "This security group rule allows unrestricted access (0.0.0.0/0 or ::/0) to Redshift on TCP 5439.", currentStateReferences: references1.join('\n'), remediation: "Remove the rule or restrict the source CIDR(s) to trusted networks only.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 600, conditionText: "otherwise", currentStateMessage: "This security group rule does not allow unrestricted access to TCP 5439.", 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__endpointPort2__c AS CA10__endpointPort2__c,
          sObject.Id AS Id,
          `CA10__AWS_Redshift_Cluster_VPC_SG_Links__r`.arr AS CA10__AWS_Redshift_Cluster_VPC_SG_Links__r,
          process_CA10__CaAwsRedshiftCluster__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__status__c AS CA10__status__c,
                  sObject.CA10__endpointPort2__c AS CA10__endpointPort2__c,
                  sObject.Id AS Id,
                  `CA10__AWS_Redshift_Cluster_VPC_SG_Links__r`.arr AS CA10__AWS_Redshift_Cluster_VPC_SG_Links__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsRedshiftCluster__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10__cluster__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__cluster__c AS CA10__cluster__c,
                      sObject.Id AS Id,
                      sObject.CA10__securityGroup__c AS CA10__securityGroup__c,
                      STRUCT (
                          `CA10__securityGroup__r`.Id AS Id,
                          `CA10__securityGroup__r.CA10__AWS_EC2_Security_Group_Rules1__r`.arr AS CA10__AWS_EC2_Security_Group_Rules1__r
                      ) AS CA10__securityGroup__r,
                      process_CA10__AWS_Redshift_Cluster_VPC_SG_Links__r(
                          STRUCT(
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__cluster__c AS CA10__cluster__c,
                              sObject.Id AS Id,
                              sObject.CA10__securityGroup__c AS CA10__securityGroup__c,
                              STRUCT (
                                  `CA10__securityGroup__r`.Id AS Id,
                                  `CA10__securityGroup__r.CA10__AWS_EC2_Security_Group_Rules1__r`.arr AS CA10__AWS_EC2_Security_Group_Rules1__r
                              ) AS CA10__securityGroup__r
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaAwsRedshiftClusterVpcSecurityGroupLink__c()) AS sObject
          LEFT JOIN UNNEST(mock_CA10__CaAwsSecurityGroup__c()) AS `CA10__securityGroup__r`
              ON sObject.CA10__securityGroup__c = `CA10__securityGroup__r`.Id
          LEFT JOIN (
              SELECT
                  sObject.CA10__sourceGroup__c,
                  ARRAY_AGG(
                      STRUCT(
                          sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                          sObject.CA10__direction__c AS CA10__direction__c,
                          sObject.CA10__source__c AS CA10__source__c,
                          sObject.CA10__sourceIpRange__c AS CA10__sourceIpRange__c,
                          sObject.CA10__protocol__c AS CA10__protocol__c,
                          sObject.CA10__fromPort__c AS CA10__fromPort__c,
                          sObject.CA10__toPort__c AS CA10__toPort__c,
                          sObject.CA10__sourceGroup__c AS CA10__sourceGroup__c,
                          sObject.Id AS Id,
                          process_CA10__AWS_Redshift_Cluster_VPC_SG_Links__r_CA10__securityGroup__r_CA10__AWS_EC2_Security_Group_Rules1__r(
                              STRUCT(
                                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                                  sObject.CA10__direction__c AS CA10__direction__c,
                                  sObject.CA10__source__c AS CA10__source__c,
                                  sObject.CA10__sourceIpRange__c AS CA10__sourceIpRange__c,
                                  sObject.CA10__protocol__c AS CA10__protocol__c,
                                  sObject.CA10__fromPort__c AS CA10__fromPort__c,
                                  sObject.CA10__toPort__c AS CA10__toPort__c,
                                  sObject.CA10__sourceGroup__c AS CA10__sourceGroup__c,
                                  sObject.Id AS Id
                              ),
                              sObject.context.snapshotTime
                          ) as result
                      )
                  ) AS arr
              FROM UNNEST(mock_CA10__CaAwsSecurityGroupRule2__c()) AS sObject
              GROUP BY sObject.CA10__sourceGroup__c
          ) AS `CA10__securityGroup__r.CA10__AWS_EC2_Security_Group_Rules1__r`
              ON `CA10__securityGroup__r`.Id = `CA10__securityGroup__r.CA10__AWS_EC2_Security_Group_Rules1__r`.CA10__sourceGroup__c
          GROUP BY sObject.CA10__cluster__c
      ) AS `CA10__AWS_Redshift_Cluster_VPC_SG_Links__r`
          ON sObject.Id = `CA10__AWS_Redshift_Cluster_VPC_SG_Links__r`.CA10__cluster__c
  ) sObject ON sObject.Id = expectedResult.Id;
