---
policy: /ce/ca/aws/vpc/vpn-connection-tunnels-not-up
logic: /ce/ca/aws/vpc/vpn-connection-tunnels-not-up/prod.logic.yaml
executionTime: 2025-09-02T01:30:56.865592414Z
generationMs: 60
executionMs: 745
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: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: CA10__vgwTelemetries__r.count(COMPLIANT) == number(1.0)
      actual: CA10__vgwTelemetries__r.count(COMPLIANT) == number(1.0)
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 499
      actual: 499
    conditionText:
      expected: CA10__vgwTelemetries__r.count(COMPLIANT) == number(0.0)
      actual: CA10__vgwTelemetries__r.count(COMPLIANT) == number(0.0)
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__state__c') != 'available'
      actual: extract('CA10__state__c') != 'available'
    runtimeError: {}
  - id: test5
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: CA10__vgwTelemetries__r.count(COMPLIANT) == number(1.0)
      actual: CA10__vgwTelemetries__r.count(COMPLIANT) == number(1.0)
    runtimeError: {}
  - id: test6
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: CA10__vgwTelemetries__r.count(COMPLIANT) >= number(2.0)
      actual: CA10__vgwTelemetries__r.count(COMPLIANT) >= number(2.0)
    runtimeError: {}
  - id: test7
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: CA10__vgwTelemetries__r.count(COMPLIANT) >= number(2.0)
      actual: CA10__vgwTelemetries__r.count(COMPLIANT) >= number(2.0)
    runtimeError: {}
  - id: test8
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: CA10__vgwTelemetries__r.count(COMPLIANT) >= number(2.0)
      actual: CA10__vgwTelemetries__r.count(COMPLIANT) >= number(2.0)
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/vpc/vpn-connection-tunnels-not-up/policy.yaml
    md5Hash: 78673DB9BF369DEE3CC49BE12CD9E9F9
    content: "---\nnames:\n  full: AWS VPC VPN Connection does not have both Tunnels\
      \ up\n  contextual: VPN Connection does not have both Tunnels up\ndescription:\
      \ >\n  Ensure both tunnels for an AWS Site-to-Site VPN Connection are in the\
      \ UP state. \n  AWS provides two tunnels for each VPN connection to ensure high\
      \ availability \n  and redundancy. If one tunnel is down, the VPN connection\
      \ becomes a single point \n  of failure, risking connectivity loss during maintenance\
      \ or an unexpected failure of the active tunnel.\ntype: COMPLIANCE_POLICY\n\
      categories:\n  - RELIABILITY\nframeworkMappings:\n  - \"/frameworks/cloudaware/resource-reliability/system-configuration\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/ec2/20\"\nsimilarPolicies:\n  awsSecurityHub:\n\
      \    - name: \"[EC2.20] Both VPN tunnels for an AWS Site-to-Site VPN connection\
      \ should be up\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/ec2-controls.html#ec2-20\"\
      \n"
  - path: /ce/ca/aws/vpc/vpn-connection-tunnels-not-up/prod.logic.yaml
    md5Hash: A10ACC9098B3E12714CDB49B33BE49B0
    content: |-
      ---
      inputType: "CA10__CaAwsVpnConnection__c"
      testData:
        - file: "./test-data.json"
      importExtracts:
        - file: "/types/CA10__CaAwsVpnConnection__c/object.extracts.yaml"
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "The VPN Connection is not available."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10__state__c"
              right:
                TEXT: "available"
        - status: "COMPLIANT"
          currentStateMessage: "Both VPN Connection tunnels are in the UP state."
          check:
            GREATER_THAN_EQUAL:
              left:
                RELATED_LIST_COUNT:
                  status: "COMPLIANT"
                  relationshipName: "CA10__vgwTelemetries__r"
              right:
                NUMBER: 2
        - status: "INCOMPLIANT"
          currentStateMessage: "One VPN Connection tunnel is not in the UP state."
          remediationMessage: "This is often caused by a misconfiguration on the customer gateway device."
          check:
            IS_EQUAL:
              left:
                RELATED_LIST_COUNT:
                  status: "COMPLIANT"
                  relationshipName: "CA10__vgwTelemetries__r"
              right:
                NUMBER: 1
        - status: "INCOMPLIANT"
          currentStateMessage: "None of the VPN Connection tunnels are in the UP state."
          remediationMessage: "This is often caused by a misconfiguration on the customer gateway device."
          check:
            IS_EQUAL:
              left:
                RELATED_LIST_COUNT:
                  status: "COMPLIANT"
                  relationshipName: "CA10__vgwTelemetries__r"
              right:
                NUMBER: 0
      otherwise:
        status: "UNDETERMINED"
        currentStateMessage: "Unexpected values in the fields."
      relatedLists:
        - relationshipName: "CA10__vgwTelemetries__r"
          importExtracts:
            - file: "/types/CA10__CaAwsVgwTelemetry__c/object.extracts.yaml"
          conditions:
            - status: "COMPLIANT"
              currentStateMessage: "The tunnel is UP."
              check:
                IS_EQUAL:
                  left:
                    EXTRACT: "CA10__status__c"
                  right:
                    TEXT: "UP"
          otherwise:
            status: "INCOMPLIANT"
            currentStateMessage: "The tunnel is DOWN."
  - path: /ce/ca/aws/vpc/vpn-connection-tunnels-not-up/test-data.json
    md5Hash: 700BC3417F0513EF493321B905A9BD46
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-08-31T15:18:03Z"
              },
              "Id": "test1",
              "CA10__disappearanceTime__c": "2025-08-31T15:18:03Z",
              "CA10__state__c": "available",
              "CA10__vgwTelemetries__r": [
                  {
                      "Id": "test1_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__status__c": "UP",
                      "CA10__vpnConnection__c": "test1"
                  },
                  {
                      "Id": "test1_2",
                      "CA10__disappearanceTime__c": null,
                      "CA10__status__c": "UP",
                      "CA10__vpnConnection__c": "test1"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "399",
                  "conditionText": "CA10__vgwTelemetries__r.count(COMPLIANT) == number(1.0)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-08-31T15:18:03Z"
              },
              "Id": "test2",
              "CA10__disappearanceTime__c": null,
              "CA10__state__c": "available",
              "CA10__vgwTelemetries__r": [
                  {
                      "Id": "test2_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__status__c": "DOWN",
                      "CA10__vpnConnection__c": "test2"
                  },
                  {
                      "Id": "test2_2",
                      "CA10__disappearanceTime__c": null,
                      "CA10__status__c": "UP",
                      "CA10__vpnConnection__c": "test2"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "499",
                  "conditionText": "CA10__vgwTelemetries__r.count(COMPLIANT) == number(0.0)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-08-31T15:18:03Z"
              },
              "Id": "test3",
              "CA10__disappearanceTime__c": null,
              "CA10__state__c": "available",
              "CA10__vgwTelemetries__r": [
                  {
                      "Id": "test3_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__status__c": "DOWN",
                      "CA10__vpnConnection__c": "test3"
                  },
                  {
                      "Id": "test3_2",
                      "CA10__disappearanceTime__c": null,
                      "CA10__status__c": "DOWN",
                      "CA10_vpnConnection__c": "test3"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__state__c') != 'available'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-08-31T15:18:03Z"
              },
              "Id": "test4",
              "CA10__disappearanceTime__c": null,
              "CA10__state__c": "deleted",
              "CA10__vgwTelemetries__r": [
                  {
                      "Id": "test4_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__status__c": "UP",
                      "CA10__vpnConnection__c": "test4"
                  },
                  {
                      "Id": "test4_2",
                      "CA10__disappearanceTime__c": null,
                      "CA10__status__c": "UP",
                      "CA10__vpnConnection__c": "test4"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "399",
                  "conditionText": "CA10__vgwTelemetries__r.count(COMPLIANT) == number(1.0)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-08-31T15:18:03Z"
              },
              "Id": "test5",
              "CA10__disappearanceTime__c": null,
              "CA10__state__c": "available",
              "CA10__vgwTelemetries__r": [
                  {
                      "Id": "test5_1",
                      "CA10__disappearanceTime__c": "2025-08-31T15:18:03Z",
                      "CA10__status__c": "UP",
                      "CA10__vpnConnection__c": "test5"
                  },
                  {
                      "Id": "test5_2",
                      "CA10__disappearanceTime__c": null,
                      "CA10__status__c": "UP",
                      "CA10__vpnConnection__c": "test5"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "CA10__vgwTelemetries__r.count(COMPLIANT) >= number(2.0)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-08-31T15:18:03Z"
              },
              "Id": "test6",
              "CA10__disappearanceTime__c": null,
              "CA10__state__c": "available",
              "CA10__vgwTelemetries__r": [
                  {
                      "Id": "test6_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__status__c": "UP",
                      "CA10__vpnConnection__c": "test6"
                  },
                  {
                      "Id": "test6_2",
                      "CA10__disappearanceTime__c": null,
                      "CA10__status__c": "UP",
                      "CA10__vpnConnection__c": "test6"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "CA10__vgwTelemetries__r.count(COMPLIANT) >= number(2.0)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-08-31T15:18:03Z"
              },
              "Id": "test7",
              "CA10__disappearanceTime__c": null,
              "CA10__state__c": "available",
              "CA10__vgwTelemetries__r": [
                  {
                      "Id": "test7_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__status__c": "UP",
                      "CA10__vpnConnection__c": "test7"
                  },
                  {
                      "Id": "test7_2",
                      "CA10__disappearanceTime__c": null,
                      "CA10__status__c": "UP",
                      "CA10__vpnConnection__c": "test7"
                  },
                  {
                      "Id": "test7_3",
                      "CA10__disappearanceTime__c": null,
                      "CA10__status__c": "UP",
                      "CA10__vpnConnection__c": "test7"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "CA10__vgwTelemetries__r.count(COMPLIANT) >= number(2.0)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-08-31T15:18:03Z"
              },
              "Id": "test8",
              "CA10__disappearanceTime__c": null,
              "CA10__state__c": "available",
              "CA10__vgwTelemetries__r": [
                  {
                      "Id": "test8_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__status__c": "DOWN",
                      "CA10__vpnConnection__c": "test8"
                  },
                  {
                      "Id": "test8_2",
                      "CA10__disappearanceTime__c": null,
                      "CA10__status__c": "UP",
                      "CA10__vpnConnection__c": "test8"
                  },
                  {
                      "Id": "test8_3",
                      "CA10__disappearanceTime__c": null,
                      "CA10__status__c": "UP",
                      "CA10__vpnConnection__c": "test8"
                  }
              ]
          }
      ]
  - path: /types/CA10__CaAwsVpnConnection__c/object.extracts.yaml
    md5Hash: 9B5659A3C6F6C7E429E7C0679395C259
    content: "---\nextracts:\n# Values: pending | available | deleting | deleted.\
      \ Not Nullable. Can't have no access, retrieved via ec2:DescribeVpnConnections\n\
      \  - name: CA10__state__c\n    value:\n      FIELD: \n        path: CA10__state__c\n\
      \        undeterminedIf:\n          isEmpty: \"Corrupted data. VPN Connection\
      \ State cannot be empty.\" \n"
  - path: /types/CA10__CaAwsVgwTelemetry__c/object.extracts.yaml
    md5Hash: 1256E8E9A9B830F090FC5D676BD63616
    content: "---\nextracts:\n# Values: UP | DOWN. Not Nullable. Can't have no access,\
      \ retrieved via ec2:DescribeVpnConnections\n  - name: CA10__status__c\n    value:\n\
      \      FIELD: \n        path: CA10__status__c\n        undeterminedIf:\n   \
      \       isEmpty: \"Corrupted data. Gateway Telemetry Status cannot be empty.\"\
      \ \n"
script: |-
  CREATE TEMP FUNCTION mock_ExpectedResult()
  RETURNS ARRAY<STRUCT<
          Id STRING,
          expectedResult STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, runtimeError STRING>
      >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "Id" : "test1",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "CA10__vgwTelemetries__r.count(COMPLIANT) == number(1.0)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "499",
      "conditionText" : "CA10__vgwTelemetries__r.count(COMPLIANT) == number(0.0)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__state__c') != 'available'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test5",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "CA10__vgwTelemetries__r.count(COMPLIANT) == number(1.0)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test6",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "CA10__vgwTelemetries__r.count(COMPLIANT) >= number(2.0)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test7",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "CA10__vgwTelemetries__r.count(COMPLIANT) >= number(2.0)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test8",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "CA10__vgwTelemetries__r.count(COMPLIANT) >= number(2.0)",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsVpnConnection__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__state__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test1",
    "CA10__disappearanceTime__c" : new Date("2025-08-31T15:18:03Z"),
    "CA10__state__c" : "available"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test2",
    "CA10__state__c" : "available"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test3",
    "CA10__state__c" : "available"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test4",
    "CA10__state__c" : "deleted"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test5",
    "CA10__state__c" : "available"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test6",
    "CA10__state__c" : "available"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test7",
    "CA10__state__c" : "available"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test8",
    "CA10__state__c" : "available"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsVgwTelemetry__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__status__c STRING,
      CA10__vpnConnection__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test1_1",
    "CA10__status__c" : "UP",
    "CA10__vpnConnection__c" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test1_2",
    "CA10__status__c" : "UP",
    "CA10__vpnConnection__c" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test2_1",
    "CA10__status__c" : "DOWN",
    "CA10__vpnConnection__c" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test2_2",
    "CA10__status__c" : "UP",
    "CA10__vpnConnection__c" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test3_1",
    "CA10__status__c" : "DOWN",
    "CA10__vpnConnection__c" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test3_2",
    "CA10__status__c" : "DOWN",
    "CA10__vpnConnection__c" : null
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test4_1",
    "CA10__status__c" : "UP",
    "CA10__vpnConnection__c" : "test4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test4_2",
    "CA10__status__c" : "UP",
    "CA10__vpnConnection__c" : "test4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test5_1",
    "CA10__disappearanceTime__c" : new Date("2025-08-31T15:18:03Z"),
    "CA10__status__c" : "UP",
    "CA10__vpnConnection__c" : "test5"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test5_2",
    "CA10__status__c" : "UP",
    "CA10__vpnConnection__c" : "test5"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test6_1",
    "CA10__status__c" : "UP",
    "CA10__vpnConnection__c" : "test6"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test6_2",
    "CA10__status__c" : "UP",
    "CA10__vpnConnection__c" : "test6"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test7_1",
    "CA10__status__c" : "UP",
    "CA10__vpnConnection__c" : "test7"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test7_2",
    "CA10__status__c" : "UP",
    "CA10__vpnConnection__c" : "test7"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test7_3",
    "CA10__status__c" : "UP",
    "CA10__vpnConnection__c" : "test7"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test8_1",
    "CA10__status__c" : "DOWN",
    "CA10__vpnConnection__c" : "test8"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test8_2",
    "CA10__status__c" : "UP",
    "CA10__vpnConnection__c" : "test8"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test8_3",
    "CA10__status__c" : "UP",
    "CA10__vpnConnection__c" : "test8"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsVpnConnection__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__state__c STRING,
          CA10__vgwTelemetries__r ARRAY<STRUCT<
              Id STRING,
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__status__c STRING,
              CA10__vpnConnection__c 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 fieldChecked4() {
          if (TextLib.isEmpty(obj.CA10__state__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__state__c.isEmpty()", currentStateMessage: "Corrupted data. VPN Connection State cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__state__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('State [obj.CA10__state__c]: ' + obj.CA10__state__c);
      try {
          if (TextLib.notEqual(extract3.call(extract3), 'available')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__state__c') != 'available'", currentStateMessage: "The VPN Connection is not available.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      var count_CA10__vgwTelemetries__r_COMPLIANT6 = 0;
      if (obj.CA10__vgwTelemetries__r != null) {
          for (var i7 = 0; i7 < obj.CA10__vgwTelemetries__r.length; i7++) {
              if (obj.CA10__vgwTelemetries__r[i7].result.status == 'COMPLIANT') {
                  count_CA10__vgwTelemetries__r_COMPLIANT6 += 1;
              }
          }
      }
      // condition[2], conditionIndex:[200..299]
      references1.push('Related list [CA10__vgwTelemetries__r] has ' + count_CA10__vgwTelemetries__r_COMPLIANT6 + ' objects in COMPLIANT status');
      if (count_CA10__vgwTelemetries__r_COMPLIANT6 != null && 2.0 != null && count_CA10__vgwTelemetries__r_COMPLIANT6 >= 2.0) {
          return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "CA10__vgwTelemetries__r.count(COMPLIANT) >= number(2.0)", currentStateMessage: "Both VPN Connection tunnels are in the UP state.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10__vgwTelemetries__r_COMPLIANT6 = 0;
      if (obj.CA10__vgwTelemetries__r != null) {
          for (var i8 = 0; i8 < obj.CA10__vgwTelemetries__r.length; i8++) {
              if (obj.CA10__vgwTelemetries__r[i8].result.status == 'COMPLIANT') {
                  count_CA10__vgwTelemetries__r_COMPLIANT6 += 1;
              }
          }
      }
      // condition[3], conditionIndex:[300..399]
      if (count_CA10__vgwTelemetries__r_COMPLIANT6 == 1.0) {
          return {status: 'INCOMPLIANT', conditionIndex: 399, conditionText: "CA10__vgwTelemetries__r.count(COMPLIANT) == number(1.0)", currentStateMessage: "One VPN Connection tunnel is not in the UP state.", currentStateReferences: references1.join('\n'), remediation: "This is often caused by a misconfiguration on the customer gateway device.", runtimeError: null};
      }
      var count_CA10__vgwTelemetries__r_COMPLIANT6 = 0;
      if (obj.CA10__vgwTelemetries__r != null) {
          for (var i9 = 0; i9 < obj.CA10__vgwTelemetries__r.length; i9++) {
              if (obj.CA10__vgwTelemetries__r[i9].result.status == 'COMPLIANT') {
                  count_CA10__vgwTelemetries__r_COMPLIANT6 += 1;
              }
          }
      }
      // condition[4], conditionIndex:[400..499]
      if (count_CA10__vgwTelemetries__r_COMPLIANT6 == 0.0) {
          return {status: 'INCOMPLIANT', conditionIndex: 499, conditionText: "CA10__vgwTelemetries__r.count(COMPLIANT) == number(0.0)", currentStateMessage: "None of the VPN Connection tunnels are in the UP state.", currentStateReferences: references1.join('\n'), remediation: "This is often caused by a misconfiguration on the customer gateway device.", runtimeError: null};
      }
      return {status: 'UNDETERMINED', conditionIndex: 500, conditionText: "otherwise", currentStateMessage: "Unexpected values in the fields.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__vgwTelemetries__r(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__status__c STRING,
          CA10__vpnConnection__c STRING
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
      var TextLib = new function () {
          this.normalize = function(arg) {
              return arg == null ? '' : arg.replace(/\s+/g, ' ').trim().toLowerCase();
          };
          this.isEmpty = function(arg) {
              return this.normalize(arg) == '';
          };
          this.isNotEmpty = function(arg) {
              return this.normalize(arg) != '';
          };
          this.equal = function(left, right) {
              return this.normalize(left) == this.normalize(right);
          };
          this.notEqual = function(left, right) {
              return this.normalize(left) != this.normalize(right);
          };
          this.startsWith = function(arg, substring) {
              return this.normalize(arg).startsWith(this.normalize(substring));
          };
          this.endsWith = function(arg, substring) {
              return this.normalize(arg).endsWith(this.normalize(substring));
          };
          this.contains = function(arg, substring) {
              return this.normalize(arg).includes(this.normalize(substring));
          };
          this.containsAll = function(arg, substrings) {
              if (substrings == null || substrings.length === 0) return false;
              let normalizedArg = this.normalize(arg);
              return substrings.every(sub => normalizedArg.includes(this.normalize(sub)));
          };
          this.containsAny = function(arg, substrings) {
              if (substrings == null || substrings.length === 0) return false;
              let normalizedArg = this.normalize(arg);
              return substrings.some(sub => normalizedArg.includes(this.normalize(sub)));
          };
      }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From AWS [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c);
      if (obj.CA10__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[1], conditionIndex:[100..199]
      function fieldChecked4() {
          if (TextLib.isEmpty(obj.CA10__status__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__status__c.isEmpty()", currentStateMessage: "Corrupted data. Gateway Telemetry Status cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__status__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Status [obj.CA10__status__c]: ' + obj.CA10__status__c);
      try {
          if (TextLib.equal(extract3.call(extract3), 'UP')) {
              return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__status__c') == 'UP'", currentStateMessage: "The tunnel is UP.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'INCOMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "The tunnel is DOWN.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;


  SELECT
    expectedResult.Id as Id,
    IF (
      IFNULL(expectedResult.expectedResult.status, '') = IFNULL(sObject.result.status, '')
      AND IFNULL(expectedResult.expectedResult.conditionIndex, -1) = IFNULL(sObject.result.conditionIndex, -1)
      AND IFNULL(expectedResult.expectedResult.conditionText, '') = IFNULL(sObject.result.conditionText, '')
      AND IFNULL(expectedResult.expectedResult.runtimeError, '') = IFNULL(sObject.result.runtimeError, ''),
      "MATCH",
      "FAIL"
    ) as match,
    expectedResult.expectedResult.status as expectedStatus, sObject.result.status as actualStatus,
    expectedResult.expectedResult.conditionIndex as expectedConditionIndex, sObject.result.conditionIndex as actualConditionIndex,
    expectedResult.expectedResult.conditionText as expectedConditionText, sObject.result.conditionText as actualConditionText,
    expectedResult.expectedResult.runtimeError as expectedRuntimeError, sObject.result.runtimeError as actualRuntimeError
  FROM UNNEST(mock_ExpectedResult()) expectedResult
  LEFT JOIN (
      SELECT
          sObject.Id AS Id,
          sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__state__c AS CA10__state__c,
          `CA10__vgwTelemetries__r`.arr AS CA10__vgwTelemetries__r,
          process_CA10__CaAwsVpnConnection__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__state__c AS CA10__state__c,
                  `CA10__vgwTelemetries__r`.arr AS CA10__vgwTelemetries__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsVpnConnection__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10__vpnConnection__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__status__c AS CA10__status__c,
                      sObject.CA10__vpnConnection__c AS CA10__vpnConnection__c,
                      process_CA10__vgwTelemetries__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__status__c AS CA10__status__c,
                              sObject.CA10__vpnConnection__c AS CA10__vpnConnection__c
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaAwsVgwTelemetry__c()) AS sObject
          GROUP BY sObject.CA10__vpnConnection__c
      ) AS `CA10__vgwTelemetries__r`
          ON sObject.Id = `CA10__vgwTelemetries__r`.CA10__vpnConnection__c
  ) sObject ON sObject.Id = expectedResult.Id;
