---
policy: /ce/ca/azure/virtual-network/security-group-allows-unrestricted-traffic-to-mssql
logic: /ce/ca/azure/virtual-network/security-group-allows-unrestricted-traffic-to-mssql/prod.logic.yaml
executionTime: 2025-05-10T12:04:31.043111712Z
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: CA10__Azure_Network_Interfaces__r.has(COMPLIANT)
      actual: CA10__Azure_Network_Interfaces__r.has(COMPLIANT)
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r.has(COMPLIANT)
      actual: CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r.has(COMPLIANT)
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: CA10__Azure_Network_Security_Group_Rules__r.has(INCOMPLIANT)
      actual: CA10__Azure_Network_Security_Group_Rules__r.has(INCOMPLIANT)
    runtimeError: {}
  - id: test5
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 400
      actual: 400
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/azure/virtual-network/security-group-allows-unrestricted-traffic-to-mssql/policy.yaml
    md5Hash: C7947B9762D0EA64C7E49BB4CCF53B50
    content: "---\nnames:\n  full: Azure Network Security Group allows public access\
      \ to MSSQL port\n  contextual: Security Group allows public access to MSSQL\
      \ port\ndescription: >\n  Ensure that Azure Network Security Groups are not\
      \ exposed to unrestricted public access \n  on MSSQL ports (1433) and only accessible\
      \ by authorized IP address \n  ranges or internal networks.\ntype: COMPLIANCE_POLICY\n\
      categories:\n  - SECURITY\nframeworkMappings:\n  - \"/frameworks/cloudaware/resource-security/public-and-anonymous-access\"\
      \n\n"
  - path: /ce/ca/azure/virtual-network/security-group-allows-unrestricted-traffic-to-mssql/prod.logic.yaml
    md5Hash: 344D4867F271955F388E2E7256C0034F
    content: "---\ninputType: \"CA10__CaAzureNetworkSecurityGroup__c\"\ntestData:\n\
      \  - file: \"test-data.json\"\nconditions:\n  # This check identifies if the\
      \ NSG is attached to a VM\n  # if it is then the NSG should be evaluated by\
      \ the policy on the VM level \n  - status: \"INAPPLICABLE\"\n    currentStateMessage:\
      \ \"The Network Security Group is evaluated by /ce/ca/azure/virtual-machine/allows-unrestricted-traffic-to-mssql.\"\
      \n    check:\n      RELATED_LIST_HAS:\n        relationshipName: \"CA10__Azure_Network_Interfaces__r\"\
      \n        status: \"COMPLIANT\"\n  # This check identifies if the NSG is attached\
      \ to a VM Scale Set\n  # if it is then the NSG should be evaluated by the policy\
      \ on the VM Scale Set level\n  - status: \"INAPPLICABLE\"\n    currentStateMessage:\
      \ \"The Network Security Group is evaluated by /ce/ca/azure/vm-scale-set/instance-allows-unrestricted-traffic-to-mssql.\"\
      \n    check:\n      RELATED_LIST_HAS:\n        relationshipName: \"CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r\"\
      \n        status: \"COMPLIANT\"\n  - status: \"INCOMPLIANT\"\n    currentStateMessage:\
      \ \"The Network Security Group has a rule that allows MSSQL access from the\
      \ Internet.\"\n    remediationMessage: \"Restrict inbound MSSQL access from\
      \ the Internet.\"\n    check:\n      RELATED_LIST_HAS:\n        relationshipName:\
      \ \"CA10__Azure_Network_Security_Group_Rules__r\"\n        status: \"INCOMPLIANT\"\
      \notherwise:\n  status: \"COMPLIANT\"\n  currentStateMessage: \"The NSG doesn't\
      \ allow MSSQL access from the Internet.\" \nrelatedLists:\n  - relationshipName:\
      \ \"CA10__Azure_Network_Security_Group_Rules__r\"\n    importExtracts:\n   \
      \   - file: \"/types/CA10__CaAzureNetworkSecurityGroupRule__c/object.extracts.yaml\"\
      \n    conditions:\n      - status: \"INAPPLICABLE\"\n        currentStateMessage:\
      \ \"NSG Deny Rule.\"\n        check:\n          NOT_EQUAL:\n            left:\n\
      \              EXTRACT: \"CA10__access__c\"\n            right:\n          \
      \    TEXT: \"Allow\"\n      - status: \"INAPPLICABLE\"\n        currentStateMessage:\
      \ \"NSG Outbound Rule.\"\n        check:\n          NOT_EQUAL:\n           \
      \ left:\n              EXTRACT: \"CA10__direction__c\"\n            right:\n\
      \              TEXT: \"Inbound\"\n      - status: \"INAPPLICABLE\"\n       \
      \ currentStateMessage: \"NSG Rule with the port other than TCP or Any.\"\n \
      \       check:\n        # returns true when protocol is neither TCP nor *\n\
      \          NOT:\n            arg:\n              OR:\n                args:\n\
      \                  - IS_EQUAL:\n                      left:\n              \
      \          EXTRACT: \"CA10__protocol__c\"\n                      right:\n  \
      \                      TEXT: \"TCP\"\n                  - IS_EQUAL:\n      \
      \                left:\n                        EXTRACT: \"CA10__protocol__c\"\
      \n                      right:\n                        TEXT: \"*\"\n      \
      \            - IS_EQUAL:\n                      left:\n                    \
      \    EXTRACT: \"CA10__protocol__c\"\n                      right:\n        \
      \                TEXT: \"null\"\n      - status: \"INAPPLICABLE\"\n        currentStateMessage:\
      \ \"NSG Rule source is not any address.\"\n        check:\n        # returns\
      \ true when source is neither Internet, *, 0.0.0.0, /0, or Any\n          NOT:\n\
      \            arg:\n              OR:\n                args:\n              \
      \    - IS_EQUAL:\n                      left:\n                        EXTRACT:\
      \ \"CA10__sourceAddressPrefix__c\"\n                      right:\n         \
      \               TEXT: \"Internet\"\n                  - IS_EQUAL:\n        \
      \              left:\n                        EXTRACT: \"CA10__sourceAddressPrefix__c\"\
      \n                      right:\n                        TEXT: \"*\"\n      \
      \            - IS_EQUAL:\n                      left:\n                    \
      \    EXTRACT: \"CA10__sourceAddressPrefix__c\"\n                      right:\n\
      \                        TEXT: \"0.0.0.0\"\n                  - CONTAINS:\n\
      \                      arg:\n                        EXTRACT: \"CA10__sourceAddressPrefix__c\"\
      \n                      substring:\n                        TEXT: \"/0\"\n \
      \                 - IS_EQUAL:\n                      left:\n               \
      \         EXTRACT: \"CA10__sourceAddressPrefix__c\"\n                      right:\n\
      \                        TEXT: \"Any\"\n      - status: \"INCOMPLIANT\"\n  \
      \      currentStateMessage: \"NSG Rule with MSSQL access from the Internet.\"\
      \n        remediationMessage: \"Consider restricting internet-level access to\
      \ your Azure resources.\"\n        check:\n          OR:\n            args:\n\
      \              - IS_EQUAL:\n                  left:\n                    EXTRACT:\
      \ \"CA10__destinationPortRange__c\"\n                  right:\n            \
      \        TEXT: \"1433\"\n              - AND:\n                  args:\n   \
      \                 - LESS_THAN_EQUAL:\n                        left:\n      \
      \                    EXTRACT: \"CA10__destinationPortFrom__c\"\n           \
      \             right:\n                          NUMBER: 1433.0\n           \
      \         - GREATER_THAN_EQUAL:\n                        left:\n           \
      \               EXTRACT: \"CA10__destinationPortTo__c\"\n                  \
      \      right:\n                          NUMBER: 1433.0\n    otherwise: \n \
      \     status: \"INAPPLICABLE\"\n      currentStateMessage: \"Unrelated rule.\"\
      \n  - relationshipName: \"CA10__Azure_Network_Interfaces__r\"\n    conditions:\n\
      \      - status: \"COMPLIANT\"\n        currentStateMessage: \"This is a Network\
      \ Interface with a linked VM.\"\n        check:\n          NOT_EMPTY_LOOKUP:\
      \ \"CA10__virtualMachine__r\" \n    otherwise:\n      status: \"INAPPLICABLE\"\
      \n      currentStateMessage: \"This is a Network Interface without a linked\
      \ VM.\"\n  - relationshipName: \"CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r\"\
      \n    conditions:\n      - status: \"COMPLIANT\"\n        currentStateMessage:\
      \ \"This is a Network Interface with a linked VM Scale Set Instance.\"\n   \
      \     check:\n          NOT_EMPTY_LOOKUP: \"CA10Z1__vmScaleSetInstance__r\"\
      \ \n    otherwise:\n      status: \"INAPPLICABLE\"\n      currentStateMessage:\
      \ \"This is a Network Interface without a linked VM Scale Set Instance.\"\n"
  - path: /ce/ca/azure/virtual-network/security-group-allows-unrestricted-traffic-to-mssql/test-data.json
    md5Hash: 5EE58E2ECE3C0BB4EBD6E464ED27E59E
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-04-28T09:57:28Z"
              },
              "Id": "test1",
              "CA10__disappearanceTime__c": "2025-04-23T10:21:35Z",
              "CA10__Azure_Network_Security_Group_Rules__r": [
                  {
                      "Id": "test1_1",
                      "CA10__disappearanceTime__c": "2025-04-23T10:21:35Z",
                      "CA10__access__c": "Allow",
                      "CA10__direction__c": "Inbound",
                      "CA10__protocol__c": "*",
                      "CA10__sourceAddressPrefix__c": "*",
                      "CA10__destinationPortRange__c": "*",
                      "CA10__destinationPortFrom__c": 0,
                      "CA10__destinationPortTo__c": 65535,
                      "CA10__networkSecurityGroup__c": "test1"
                  }
              ],
              "CA10__Azure_Network_Interfaces__r": [],
              "CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r": []
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "CA10__Azure_Network_Interfaces__r.has(COMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-04-28T09:57:28Z"
              },
              "Id": "test2",
              "CA10__disappearanceTime__c": null,
              "CA10__Azure_Network_Security_Group_Rules__r": [
                  {
                      "Id": "test2_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__access__c": "Allow",
                      "CA10__direction__c": "Inbound",
                      "CA10__protocol__c": "*",
                      "CA10__sourceAddressPrefix__c": "Internet",
                      "CA10__destinationPortRange__c": "1433",
                      "CA10__destinationPortFrom__c": 1433,
                      "CA10__destinationPortTo__c": 1433,
                      "CA10__networkSecurityGroup__c": "test2"
                  }
              ],
              "CA10__Azure_Network_Interfaces__r": [
                  {
                      "Id": "test2_2",
                      "CA10__disappearanceTime__c": null,
                      "CA10__virtualMachine__c": "test2_2_1",
                      "CA10__virtualMachineId__c": "virtualMachineId",
                      "CA10__networkSecurityGroup__c": "test2",
                      "CA10__virtualMachine__r": {
                          "Id": "test2_2_1",
                          "CA10__disappearanceTime__c": null
                      }
                  }
              ],
              "CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r": []
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "299",
                  "conditionText": "CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r.has(COMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-04-28T09:57:28Z"
              },
              "Id": "test3",
              "CA10__disappearanceTime__c": null,
              "CA10__Azure_Network_Security_Group_Rules__r": [
                  {
                      "Id": "test3_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__access__c": "Allow",
                      "CA10__direction__c": "Inbound",
                      "CA10__protocol__c": "*",
                      "CA10__sourceAddressPrefix__c": "Internet",
                      "CA10__destinationPortRange__c": "1433",
                      "CA10__destinationPortFrom__c": 1433,
                      "CA10__destinationPortTo__c": 1433,
                      "CA10__networkSecurityGroup__c": "test3"
                  }
              ],
              "CA10__Azure_Network_Interfaces__r": [],
              "CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r": [
                  {
                      "Id": "test3_2",
                      "CA10Z1__disappearanceTime__c": null,
                      "CA10Z1__vmScaleSetInstance__c": "test3_2_1",
                      "CA10Z1__vmScaleSetInstanceId__c": "vmScaleSetInstanceId",
                      "CA10Z1__networkSecurityGroup__c": "test3",
                      "CA10Z1__vmScaleSetInstance__r": {
                          "Id": "test3_2_1",
                          "CA10__disappearanceTime__c": null
                      }
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "399",
                  "conditionText": "CA10__Azure_Network_Security_Group_Rules__r.has(INCOMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-04-28T09:57:28Z"
              },
              "Id": "test4",
              "CA10__disappearanceTime__c": null,
              "CA10__Azure_Network_Security_Group_Rules__r": [
                  {
                      "Id": "test4_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__access__c": "Allow",
                      "CA10__direction__c": "Inbound",
                      "CA10__protocol__c": "Tcp",
                      "CA10__sourceAddressPrefix__c": "0.0.0.0",
                      "CA10__destinationPortRange__c": "0-65535",
                      "CA10__destinationPortFrom__c": 0,
                      "CA10__destinationPortTo__c": 65535,
                      "CA10__networkSecurityGroup__c": "test4"
                  }
              ],
              "CA10__Azure_Network_Interfaces__r": [],
              "CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r": []
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "400",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-04-28T09:57:28Z"
              },
              "Id": "test5",
              "CA10__disappearanceTime__c": null,
              "CA10__Azure_Network_Security_Group_Rules__r": [
                  {
                      "Id": "test5_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__access__c": "Deny",
                      "CA10__direction__c": "Inbound",
                      "CA10__protocol__c": "*",
                      "CA10__sourceAddressPrefix__c": "*",
                      "CA10__destinationPortRange__c": "1433",
                      "CA10__destinationPortFrom__c": 1433,
                      "CA10__destinationPortTo__c": 1433,
                      "CA10__networkSecurityGroup__c": "test5"
                  }
              ],
              "CA10__Azure_Network_Interfaces__r": [],
              "CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r": []
          }
      ]
  - path: /types/CA10__CaAzureNetworkSecurityGroupRule__c/object.extracts.yaml
    md5Hash: A60C817EFBC8F066D6D082898E8597BC
    content: "---\nextracts:\n# Values: Allow, Deny. Not Nullable. Can't have no access,\
      \ retrieved via Microsoft.Network/networkSecurityGroups\n  - name: \"CA10__access__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__access__c\"\n        undeterminedIf:\n\
      \          isEmpty: \"Corrupted data. NSG Rule Access cannot be empty.\"\n#\
      \ Number. Can't have no access, retrieved via Microsoft.Network/networkSecurityGroups\n\
      \  - name: \"CA10__destinationPortFrom__c\"\n    value: \n      FIELD:\n   \
      \     path: \"CA10__destinationPortFrom__c\"\n# Number. Can't have no access,\
      \ retrieved via Microsoft.Network/networkSecurityGroups\n  - name: \"CA10__destinationPortTo__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__destinationPortTo__c\"\n\
      # Not Nullable. Can't have no access, retrieved via Microsoft.Network/networkSecurityGroups\n\
      \  - name: \"CA10__destinationPortRange__c\"\n    value: \n      FIELD:\n  \
      \      path: \"CA10__destinationPortRange__c\"\n        undeterminedIf:\n  \
      \        isEmpty: \"Corrupted data. NSG Rule Destination Port Range cannot be\
      \ empty.\"\n# Values: Inbound, Outbound. Not Nullable. Can't have no access,\
      \ retrieved via Microsoft.Network/networkSecurityGroups\n  - name: \"CA10__direction__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__direction__c\"\n        undeterminedIf:\n\
      \          isEmpty: \"Corrupted data. NSG Rule Direction cannot be empty.\"\n\
      # Not Nullable. Can't have no access, retrieved via Microsoft.Network/networkSecurityGroups\n\
      \  - name: \"CA10__protocol__c\"\n    value: \n      FIELD:\n        path: \"\
      CA10__protocol__c\"\n        undeterminedIf:\n          isEmpty: \"Corrupted\
      \ data. NSG Rule Protocol cannot be empty.\"\n# Nullable. Can't have no access,\
      \ retrieved via Microsoft.Network/networkSecurityGroups\n  - name: \"CA10__sourceAddressPrefix__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__sourceAddressPrefix__c\"\n\
      # Nullable. Can't have no access, retrieved via Microsoft.Network/networkSecurityGroups\n\
      \  - name: \"CA10__sourceAddressPrefixes__c\"\n    value: \n      FIELD:\n \
      \       path: \"CA10__sourceAddressPrefixes__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" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "CA10__Azure_Network_Interfaces__r.has(COMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "299",
      "conditionText" : "CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r.has(COMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "CA10__Azure_Network_Security_Group_Rules__r.has(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test5",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "400",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAzureNetworkSecurityGroup__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-04-28T09:57:28Z")
    },
    "Id" : "test1",
    "CA10__disappearanceTime__c" : new Date("2025-04-23T10:21:35Z")
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-04-28T09:57:28Z")
    },
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-04-28T09:57:28Z")
    },
    "Id" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-04-28T09:57:28Z")
    },
    "Id" : "test4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-04-28T09:57:28Z")
    },
    "Id" : "test5"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAzureNetworkSecurityGroupRule__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__access__c STRING,
      CA10__direction__c STRING,
      CA10__protocol__c STRING,
      CA10__sourceAddressPrefix__c STRING,
      CA10__destinationPortRange__c STRING,
      CA10__destinationPortFrom__c FLOAT64,
      CA10__destinationPortTo__c FLOAT64,
      CA10__networkSecurityGroup__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-04-28T09:57:28Z")
    },
    "Id" : "test1_1",
    "CA10__disappearanceTime__c" : new Date("2025-04-23T10:21:35Z"),
    "CA10__access__c" : "Allow",
    "CA10__direction__c" : "Inbound",
    "CA10__protocol__c" : "*",
    "CA10__sourceAddressPrefix__c" : "*",
    "CA10__destinationPortRange__c" : "*",
    "CA10__destinationPortFrom__c" : 0,
    "CA10__destinationPortTo__c" : 65535,
    "CA10__networkSecurityGroup__c" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-04-28T09:57:28Z")
    },
    "Id" : "test2_1",
    "CA10__access__c" : "Allow",
    "CA10__direction__c" : "Inbound",
    "CA10__protocol__c" : "*",
    "CA10__sourceAddressPrefix__c" : "Internet",
    "CA10__destinationPortRange__c" : "1433",
    "CA10__destinationPortFrom__c" : 1433,
    "CA10__destinationPortTo__c" : 1433,
    "CA10__networkSecurityGroup__c" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-04-28T09:57:28Z")
    },
    "Id" : "test3_1",
    "CA10__access__c" : "Allow",
    "CA10__direction__c" : "Inbound",
    "CA10__protocol__c" : "*",
    "CA10__sourceAddressPrefix__c" : "Internet",
    "CA10__destinationPortRange__c" : "1433",
    "CA10__destinationPortFrom__c" : 1433,
    "CA10__destinationPortTo__c" : 1433,
    "CA10__networkSecurityGroup__c" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-04-28T09:57:28Z")
    },
    "Id" : "test4_1",
    "CA10__access__c" : "Allow",
    "CA10__direction__c" : "Inbound",
    "CA10__protocol__c" : "Tcp",
    "CA10__sourceAddressPrefix__c" : "0.0.0.0",
    "CA10__destinationPortRange__c" : "0-65535",
    "CA10__destinationPortFrom__c" : 0,
    "CA10__destinationPortTo__c" : 65535,
    "CA10__networkSecurityGroup__c" : "test4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-04-28T09:57:28Z")
    },
    "Id" : "test5_1",
    "CA10__access__c" : "Deny",
    "CA10__direction__c" : "Inbound",
    "CA10__protocol__c" : "*",
    "CA10__sourceAddressPrefix__c" : "*",
    "CA10__destinationPortRange__c" : "1433",
    "CA10__destinationPortFrom__c" : 1433,
    "CA10__destinationPortTo__c" : 1433,
    "CA10__networkSecurityGroup__c" : "test5"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAzureNetworkInterface__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__virtualMachine__c STRING,
      CA10__virtualMachineId__c STRING,
      CA10__networkSecurityGroup__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-04-28T09:57:28Z")
    },
    "Id" : "test2_2",
    "CA10__virtualMachine__c" : "test2_2_1",
    "CA10__virtualMachineId__c" : "virtualMachineId",
    "CA10__networkSecurityGroup__c" : "test2"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAzureVirtualMachine__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-04-28T09:57:28Z")
    },
    "Id" : "test2_2_1"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10Z1__CaAzureVmScaleSetInstanceNetworkInt__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10Z1__disappearanceTime__c TIMESTAMP,
      CA10Z1__vmScaleSetInstance__c STRING,
      CA10Z1__vmScaleSetInstanceId__c STRING,
      CA10Z1__networkSecurityGroup__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-04-28T09:57:28Z")
    },
    "Id" : "test3_2",
    "CA10Z1__vmScaleSetInstance__c" : "test3_2_1",
    "CA10Z1__vmScaleSetInstanceId__c" : "vmScaleSetInstanceId",
    "CA10Z1__networkSecurityGroup__c" : "test3"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAzureVmScaleSetInstance__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-04-28T09:57:28Z")
    },
    "Id" : "test3_2_1"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAzureNetworkSecurityGroup__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__Azure_Network_Security_Group_Rules__r ARRAY<STRUCT<
              Id STRING,
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__access__c STRING,
              CA10__direction__c STRING,
              CA10__protocol__c STRING,
              CA10__sourceAddressPrefix__c STRING,
              CA10__destinationPortRange__c STRING,
              CA10__destinationPortFrom__c FLOAT64,
              CA10__destinationPortTo__c FLOAT64,
              CA10__networkSecurityGroup__c STRING,
              result STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
          >>,
          CA10__Azure_Network_Interfaces__r ARRAY<STRUCT<
              Id STRING,
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__virtualMachine__c STRING,
              CA10__virtualMachineId__c STRING,
              CA10__networkSecurityGroup__c STRING,
              CA10__virtualMachine__r STRUCT<
                  Id STRING,
                  CA10__disappearanceTime__c TIMESTAMP
              >,
              result STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
          >>,
          CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r ARRAY<STRUCT<
              Id STRING,
              CA10Z1__disappearanceTime__c TIMESTAMP,
              CA10Z1__vmScaleSetInstance__c STRING,
              CA10Z1__vmScaleSetInstanceId__c STRING,
              CA10Z1__networkSecurityGroup__c STRING,
              CA10Z1__vmScaleSetInstance__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 references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From Azure [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__Azure_Network_Interfaces__r_COMPLIANT2 = 0;
      if (obj.CA10__Azure_Network_Interfaces__r != null) {
          for (var i3 = 0; i3 < obj.CA10__Azure_Network_Interfaces__r.length; i3++) {
              if (obj.CA10__Azure_Network_Interfaces__r[i3].result.status == 'COMPLIANT') {
                  count_CA10__Azure_Network_Interfaces__r_COMPLIANT2 += 1;
              }
          }
      }
      // condition[1], conditionIndex:[100..199]
      references1.push('Related list [CA10__Azure_Network_Interfaces__r] ' + (count_CA10__Azure_Network_Interfaces__r_COMPLIANT2 > 0 ? 'has' : 'does not have') + ' objects in COMPLIANT status');
      if (count_CA10__Azure_Network_Interfaces__r_COMPLIANT2 > 0) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "CA10__Azure_Network_Interfaces__r.has(COMPLIANT)", currentStateMessage: "The Network Security Group is evaluated by /ce/ca/azure/virtual-machine/allows-unrestricted-traffic-to-mssql.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r_COMPLIANT4 = 0;
      if (obj.CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r != null) {
          for (var i5 = 0; i5 < obj.CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r.length; i5++) {
              if (obj.CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r[i5].result.status == 'COMPLIANT') {
                  count_CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r_COMPLIANT4 += 1;
              }
          }
      }
      // condition[2], conditionIndex:[200..299]
      references1.push('Related list [CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r] ' + (count_CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r_COMPLIANT4 > 0 ? 'has' : 'does not have') + ' objects in COMPLIANT status');
      if (count_CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r_COMPLIANT4 > 0) {
          return {status: 'INAPPLICABLE', conditionIndex: 299, conditionText: "CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r.has(COMPLIANT)", currentStateMessage: "The Network Security Group is evaluated by /ce/ca/azure/vm-scale-set/instance-allows-unrestricted-traffic-to-mssql.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10__Azure_Network_Security_Group_Rules__r_INCOMPLIANT6 = 0;
      if (obj.CA10__Azure_Network_Security_Group_Rules__r != null) {
          for (var i7 = 0; i7 < obj.CA10__Azure_Network_Security_Group_Rules__r.length; i7++) {
              if (obj.CA10__Azure_Network_Security_Group_Rules__r[i7].result.status == 'INCOMPLIANT') {
                  count_CA10__Azure_Network_Security_Group_Rules__r_INCOMPLIANT6 += 1;
              }
          }
      }
      // condition[3], conditionIndex:[300..399]
      references1.push('Related list [CA10__Azure_Network_Security_Group_Rules__r] ' + (count_CA10__Azure_Network_Security_Group_Rules__r_INCOMPLIANT6 > 0 ? 'has' : 'does not have') + ' objects in INCOMPLIANT status');
      if (count_CA10__Azure_Network_Security_Group_Rules__r_INCOMPLIANT6 > 0) {
          return {status: 'INCOMPLIANT', conditionIndex: 399, conditionText: "CA10__Azure_Network_Security_Group_Rules__r.has(INCOMPLIANT)", currentStateMessage: "The Network Security Group has a rule that allows MSSQL access from the Internet.", currentStateReferences: references1.join('\n'), remediation: "Restrict inbound MSSQL access from the Internet.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "The NSG doesn't allow MSSQL access from the Internet.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__Azure_Network_Security_Group_Rules__r(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__access__c STRING,
          CA10__direction__c STRING,
          CA10__protocol__c STRING,
          CA10__sourceAddressPrefix__c STRING,
          CA10__destinationPortRange__c STRING,
          CA10__destinationPortFrom__c FLOAT64,
          CA10__destinationPortTo__c FLOAT64,
          CA10__networkSecurityGroup__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));
          };
      }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From Azure [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__access__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__access__c.isEmpty()", currentStateMessage: "Corrupted data. NSG Rule Access cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__access__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Access [obj.CA10__access__c]: ' + obj.CA10__access__c);
      try {
          if (TextLib.notEqual(extract3.call(extract3), 'Allow')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__access__c') != 'Allow'", currentStateMessage: "NSG Deny 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 fieldChecked7() {
          if (TextLib.isEmpty(obj.CA10__direction__c)) {
              throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "CA10__direction__c.isEmpty()", currentStateMessage: "Corrupted data. NSG Rule Direction cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__direction__c;
      }
      function extract6() { if (!this.out) { this.out = fieldChecked7(); } return this.out; };
      references1.push('Direction [obj.CA10__direction__c]: ' + obj.CA10__direction__c);
      try {
          if (TextLib.notEqual(extract6.call(extract6), 'Inbound')) {
              return {status: 'INAPPLICABLE', conditionIndex: 299, conditionText: "extract('CA10__direction__c') != 'Inbound'", currentStateMessage: "NSG Outbound Rule.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[3], conditionIndex:[300..399]
      function fieldChecked10() {
          if (TextLib.isEmpty(obj.CA10__protocol__c)) {
              throw new Error("UNDETERMINED condition:301", {cause: {status: 'UNDETERMINED', conditionIndex: 301, conditionText: "CA10__protocol__c.isEmpty()", currentStateMessage: "Corrupted data. NSG Rule Protocol cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__protocol__c;
      }
      function extract9() { if (!this.out) { this.out = fieldChecked10(); } return this.out; };
      references1.push('Protocol [obj.CA10__protocol__c]: ' + obj.CA10__protocol__c);
      try {
          if (!(TextLib.equal(extract9.call(extract9), 'TCP') || TextLib.equal(extract9.call(extract9), '*') || TextLib.equal(extract9.call(extract9), 'null'))) {
              return {status: 'INAPPLICABLE', conditionIndex: 399, conditionText: "not(extract('CA10__protocol__c') == 'TCP' || extract('CA10__protocol__c') == '*' || extract('CA10__protocol__c') == 'null')", currentStateMessage: "NSG Rule with the port other than TCP or Any.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[4], conditionIndex:[400..499]
      function extract14() { if (!this.out) { this.out = obj.CA10__sourceAddressPrefix__c; } return this.out; };
      references1.push('Source Address Prefix [obj.CA10__sourceAddressPrefix__c]: ' + obj.CA10__sourceAddressPrefix__c);
      if (!(TextLib.equal(extract14.call(extract14), 'Internet') || TextLib.equal(extract14.call(extract14), '*') || TextLib.equal(extract14.call(extract14), '0.0.0.0') || TextLib.contains(extract14.call(extract14), '/0') || TextLib.equal(extract14.call(extract14), 'Any'))) {
          return {status: 'INAPPLICABLE', conditionIndex: 499, conditionText: "not(extract('CA10__sourceAddressPrefix__c') == 'Internet' || extract('CA10__sourceAddressPrefix__c') == '*' || extract('CA10__sourceAddressPrefix__c') == '0.0.0.0' || extract('CA10__sourceAddressPrefix__c').contains('/0') || extract('CA10__sourceAddressPrefix__c') == 'Any')", currentStateMessage: "NSG Rule source is not any address.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[5], conditionIndex:[500..599]
      function fieldChecked22() {
          if (TextLib.isEmpty(obj.CA10__destinationPortRange__c)) {
              throw new Error("UNDETERMINED condition:501", {cause: {status: 'UNDETERMINED', conditionIndex: 501, conditionText: "CA10__destinationPortRange__c.isEmpty()", currentStateMessage: "Corrupted data. NSG Rule Destination Port Range cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__destinationPortRange__c;
      }
      function extract21() { if (!this.out) { this.out = fieldChecked22(); } return this.out; };
      function extract25() { if (!this.out) { this.out = obj.CA10__destinationPortFrom__c; } return this.out; };
      function extract29() { if (!this.out) { this.out = obj.CA10__destinationPortTo__c; } return this.out; };
      references1.push('Destination Port Range [obj.CA10__destinationPortRange__c]: ' + obj.CA10__destinationPortRange__c);
      references1.push('Destination Port From [obj.CA10__destinationPortFrom__c]: ' + obj.CA10__destinationPortFrom__c);
      references1.push('Destination Port To [obj.CA10__destinationPortTo__c]: ' + obj.CA10__destinationPortTo__c);
      try {
          if (TextLib.equal(extract21.call(extract21), '1433') || ((extract25.call(extract25) != null && 1433.0 != null && extract25.call(extract25) <= 1433.0) && (extract29.call(extract29) != null && 1433.0 != null && extract29.call(extract29) >= 1433.0))) {
              return {status: 'INCOMPLIANT', conditionIndex: 599, conditionText: "extract('CA10__destinationPortRange__c') == '1433' || (extract('CA10__destinationPortFrom__c') <= number(1433.0) && extract('CA10__destinationPortTo__c') >= number(1433.0))", currentStateMessage: "NSG Rule with MSSQL access from the Internet.", currentStateReferences: references1.join('\n'), remediation: "Consider restricting internet-level access to your Azure resources.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'INAPPLICABLE', conditionIndex: 600, conditionText: "otherwise", currentStateMessage: "Unrelated rule.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r(
      obj STRUCT<
          Id STRING,
          CA10Z1__disappearanceTime__c TIMESTAMP,
          CA10Z1__vmScaleSetInstance__c STRING,
          CA10Z1__vmScaleSetInstanceId__c STRING,
          CA10Z1__networkSecurityGroup__c STRING,
          CA10Z1__vmScaleSetInstance__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 Azure [CA10Z1__disappearanceTime__c]: ' + obj.CA10Z1__disappearanceTime__c);
      if (obj.CA10Z1__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10Z1__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.CA10Z1__vmScaleSetInstanceId__c) && TextLib.isNotEmpty(obj.CA10Z1__vmScaleSetInstance__c) && obj.CA10Z1__vmScaleSetInstance__r.CA10__disappearanceTime__c == null) {
          return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "notEmptyLookup('CA10Z1__vmScaleSetInstance__r')", currentStateMessage: "This is a Network Interface with a linked VM Scale Set Instance.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'INAPPLICABLE', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "This is a Network Interface without a linked VM Scale Set Instance.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__Azure_Network_Interfaces__r(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__virtualMachine__c STRING,
          CA10__virtualMachineId__c STRING,
          CA10__networkSecurityGroup__c STRING,
          CA10__virtualMachine__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 Azure [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__virtualMachineId__c) && TextLib.isNotEmpty(obj.CA10__virtualMachine__c) && obj.CA10__virtualMachine__r.CA10__disappearanceTime__c == null) {
          return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "notEmptyLookup('CA10__virtualMachine__r')", currentStateMessage: "This is a Network Interface with a linked VM.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'INAPPLICABLE', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "This is a Network Interface without a linked VM.", 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,
          `CA10__Azure_Network_Security_Group_Rules__r`.arr AS CA10__Azure_Network_Security_Group_Rules__r,
          `CA10__Azure_Network_Interfaces__r`.arr AS CA10__Azure_Network_Interfaces__r,
          `CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r`.arr AS CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r,
          process_CA10__CaAzureNetworkSecurityGroup__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  `CA10__Azure_Network_Security_Group_Rules__r`.arr AS CA10__Azure_Network_Security_Group_Rules__r,
                  `CA10__Azure_Network_Interfaces__r`.arr AS CA10__Azure_Network_Interfaces__r,
                  `CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r`.arr AS CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAzureNetworkSecurityGroup__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10__networkSecurityGroup__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__access__c AS CA10__access__c,
                      sObject.CA10__direction__c AS CA10__direction__c,
                      sObject.CA10__protocol__c AS CA10__protocol__c,
                      sObject.CA10__sourceAddressPrefix__c AS CA10__sourceAddressPrefix__c,
                      sObject.CA10__destinationPortRange__c AS CA10__destinationPortRange__c,
                      sObject.CA10__destinationPortFrom__c AS CA10__destinationPortFrom__c,
                      sObject.CA10__destinationPortTo__c AS CA10__destinationPortTo__c,
                      sObject.CA10__networkSecurityGroup__c AS CA10__networkSecurityGroup__c,
                      process_CA10__Azure_Network_Security_Group_Rules__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__access__c AS CA10__access__c,
                              sObject.CA10__direction__c AS CA10__direction__c,
                              sObject.CA10__protocol__c AS CA10__protocol__c,
                              sObject.CA10__sourceAddressPrefix__c AS CA10__sourceAddressPrefix__c,
                              sObject.CA10__destinationPortRange__c AS CA10__destinationPortRange__c,
                              sObject.CA10__destinationPortFrom__c AS CA10__destinationPortFrom__c,
                              sObject.CA10__destinationPortTo__c AS CA10__destinationPortTo__c,
                              sObject.CA10__networkSecurityGroup__c AS CA10__networkSecurityGroup__c
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaAzureNetworkSecurityGroupRule__c()) AS sObject
          GROUP BY sObject.CA10__networkSecurityGroup__c
      ) AS `CA10__Azure_Network_Security_Group_Rules__r`
          ON sObject.Id = `CA10__Azure_Network_Security_Group_Rules__r`.CA10__networkSecurityGroup__c
      LEFT JOIN (
          SELECT
              sObject.CA10__networkSecurityGroup__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__virtualMachine__c AS CA10__virtualMachine__c,
                      sObject.CA10__virtualMachineId__c AS CA10__virtualMachineId__c,
                      sObject.CA10__networkSecurityGroup__c AS CA10__networkSecurityGroup__c,
                      STRUCT (
                          `CA10__virtualMachine__r`.Id AS Id,
                          `CA10__virtualMachine__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c
                      ) AS CA10__virtualMachine__r,
                      process_CA10__Azure_Network_Interfaces__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__virtualMachine__c AS CA10__virtualMachine__c,
                              sObject.CA10__virtualMachineId__c AS CA10__virtualMachineId__c,
                              sObject.CA10__networkSecurityGroup__c AS CA10__networkSecurityGroup__c,
                              STRUCT (
                                  `CA10__virtualMachine__r`.Id AS Id,
                                  `CA10__virtualMachine__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c
                              ) AS CA10__virtualMachine__r
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaAzureNetworkInterface__c()) AS sObject
          LEFT JOIN UNNEST(mock_CA10__CaAzureVirtualMachine__c()) AS `CA10__virtualMachine__r`
              ON sObject.CA10__virtualMachine__c = `CA10__virtualMachine__r`.Id
          GROUP BY sObject.CA10__networkSecurityGroup__c
      ) AS `CA10__Azure_Network_Interfaces__r`
          ON sObject.Id = `CA10__Azure_Network_Interfaces__r`.CA10__networkSecurityGroup__c
      LEFT JOIN (
          SELECT
              sObject.CA10Z1__networkSecurityGroup__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.CA10Z1__disappearanceTime__c AS CA10Z1__disappearanceTime__c,
                      sObject.CA10Z1__vmScaleSetInstance__c AS CA10Z1__vmScaleSetInstance__c,
                      sObject.CA10Z1__vmScaleSetInstanceId__c AS CA10Z1__vmScaleSetInstanceId__c,
                      sObject.CA10Z1__networkSecurityGroup__c AS CA10Z1__networkSecurityGroup__c,
                      STRUCT (
                          `CA10Z1__vmScaleSetInstance__r`.Id AS Id,
                          `CA10Z1__vmScaleSetInstance__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c
                      ) AS CA10Z1__vmScaleSetInstance__r,
                      process_CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.CA10Z1__disappearanceTime__c AS CA10Z1__disappearanceTime__c,
                              sObject.CA10Z1__vmScaleSetInstance__c AS CA10Z1__vmScaleSetInstance__c,
                              sObject.CA10Z1__vmScaleSetInstanceId__c AS CA10Z1__vmScaleSetInstanceId__c,
                              sObject.CA10Z1__networkSecurityGroup__c AS CA10Z1__networkSecurityGroup__c,
                              STRUCT (
                                  `CA10Z1__vmScaleSetInstance__r`.Id AS Id,
                                  `CA10Z1__vmScaleSetInstance__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c
                              ) AS CA10Z1__vmScaleSetInstance__r
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10Z1__CaAzureVmScaleSetInstanceNetworkInt__c()) AS sObject
          LEFT JOIN UNNEST(mock_CA10__CaAzureVmScaleSetInstance__c()) AS `CA10Z1__vmScaleSetInstance__r`
              ON sObject.CA10Z1__vmScaleSetInstance__c = `CA10Z1__vmScaleSetInstance__r`.Id
          GROUP BY sObject.CA10Z1__networkSecurityGroup__c
      ) AS `CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r`
          ON sObject.Id = `CA10Z1__Azure_VM_Scale_Set_Instance_Network_Ints__r`.CA10Z1__networkSecurityGroup__c
  ) sObject ON sObject.Id = expectedResult.Id;
