---
policy: /ce/ca/aws/autoscaling/group-with-elb-without-elb-health-check
logic: /ce/ca/aws/autoscaling/group-with-elb-without-elb-health-check/prod.logic.yaml
executionTime: 2025-04-24T23:44:25.610153008Z
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__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r.hasNo(COMPLIANT)
      actual: CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r.hasNo(COMPLIANT)
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r.hasNo(COMPLIANT)
      actual: CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r.hasNo(COMPLIANT)
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r.hasNo(COMPLIANT)
      actual: CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r.hasNo(COMPLIANT)
    runtimeError: {}
  - id: test5
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: not(extract('CA10__healthCheckType__c').contains('ELB'))
      actual: not(extract('CA10__healthCheckType__c').contains('ELB'))
    runtimeError: {}
  - id: test6
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: extract('CA10__healthCheckType__c').contains('ELB')
      actual: extract('CA10__healthCheckType__c').contains('ELB')
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/autoscaling/group-with-elb-without-elb-health-check/policy.yaml
    md5Hash: 4C2B53ACF31B1CE0F665F3F5AE50F52B
    content: "---\nnames:\n  full: AWS EC2 Auto Scaling Group behind ELB doesn't use\
      \ ELB health check\n  contextual: Auto Scaling Group behind ELB doesn't use\
      \ ELB health check\ndescription: >\n  Ensure that Auto Scaling Groups associated\
      \ with Elastic Load Balancers (ELBs) are configured \n  to use ELB health checks\
      \ instead of EC2 health checks. ELB health checks provide more \n  accurate\
      \ health status for instances behind a load balancer.\ncategories:\n  - \"RELIABILITY\"\
      \ntype: \"COMPLIANCE_POLICY\"\nframeworkMappings:\n  - \"/frameworks/cloudaware/resource-reliability/system-configuration\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/auto-scaling/01\"\nsimilarPolicies:\n  internal:\n\
      \    - dec-x-71d45f32  "
  - path: /ce/ca/aws/autoscaling/group-with-elb-without-elb-health-check/prod.logic.yaml
    md5Hash: BDFAD3F7A248432F95EFD92026833D66
    content: |-
      ---
      inputType: "CA10__CaAwsAutoScalingGroup__c"
      importExtracts:
        - file: "/types/CA10__CaAwsAutoScalingGroupTrafficSourceLink__c/object.extracts.yaml"
        - file: "/types/CA10__CaAwsAutoScalingGroup__c/object.extracts.yaml"
      testData:
        - file: "test-data.json"
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "The AGS is not associated with a Load Balancer."
          check:
            RELATED_LIST_HAS_NO:
              relationshipName: "CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r"
              status: "COMPLIANT"
        - status: "INCOMPLIANT"
          currentStateMessage: "The AGS behind ELB does not use ELB health check."
          remediationMessage: "Configure Auto Scaling Group to use ELB health check."
          check:
            NOT:
              arg:
                CONTAINS:
                  arg:
                    EXTRACT: "CA10__healthCheckType__c"
                  substring:
                    TEXT: "ELB"
        - status: "COMPLIANT"
          currentStateMessage: "The ASG uses ELB health check."
          check:
            CONTAINS:
              arg:
                EXTRACT: "CA10__healthCheckType__c"
              substring:
                TEXT: "ELB"
      otherwise:
        status: "UNDETERMINED"
        currentStateMessage: "Unexpected values in the fields."
      relatedLists:
        - relationshipName: "CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r"
          conditions:
            - status: "COMPLIANT"
              currentStateMessage: "The ASG traffic source is a Classic Load Balancer."
              check:
                IS_EQUAL:
                  left:
                    EXTRACT: "CA10__trafficSourceType__c"
                  right:
                    TEXT: "elb"
            - status: "COMPLIANT"
              currentStateMessage: "The ASG traffic source is an ELB target group."
              check:
                IS_EQUAL:
                  left:
                    EXTRACT: "CA10__trafficSourceType__c"
                  right:
                    TEXT: "elbv2"
          otherwise:
            status: "INAPPLICABLE"
            currentStateMessage: "Unrelated ASG traffic source."
  - path: /types/CA10__CaAwsAutoScalingGroupTrafficSourceLink__c/object.extracts.yaml
    md5Hash: 5D75919837EC6FE643E714B0EB120E9F
    content: "---\nextracts:\n# Values: elb, elbv2, vpc-lattice. Not Nullable. Can't\
      \ have no access, retrieved via autoscaling:DescribeAutoScalingGroups\n  - name:\
      \ CA10__trafficSourceType__c\n    value: \n      FIELD:\n        path: CA10__trafficSourceType__c\n\
      \        undeterminedIf:\n          isEmpty: \"Possibly corrupted data. Traffic\
      \ source type cannot be empty.\""
  - path: /types/CA10__CaAwsAutoScalingGroup__c/object.extracts.yaml
    md5Hash: DD41D736933C31B7EA43278E6396A5FC
    content: "---\nextracts:\n  # AvailabilityZones.member.N\n  # One or more Availability\
      \ Zones for the group.\n  # Type: Array of strings\n  # Length Constraints:\
      \ Minimum length of 1. Maximum length of 255.\n  # Pattern: [\\u0020-\\uD7FF\\\
      uE000-\\uFFFD\\uD800\\uDC00-\\uDBFF\\uDFFF\\r\\n\\t]*\n  # Required: Yes\n \
      \ - name: CA10__availabilityZones__c\n    value: \n      FIELD:\n        path:\
      \ CA10__availabilityZones__c\n        undeterminedIf:\n          isEmpty: Corrupted\
      \ data. Availability zones should always present\n  - name: caExtract_availabilityZones_asCollection__c\n\
      \    value: \n      COLLECTION_FROM:\n        separator: \"\\n\"\n        arg:\n\
      \          EXTRACT: CA10__availabilityZones__c\n# A comma-separated value string\
      \ of one or more health check types.\n# Values: EC2, EBS, ELB, VPC_LATTICE.\
      \  Not nullable. Can't have no access, retrieved via autoscaling:DescribeAutoScalingGroups\n\
      \  - name: CA10__healthCheckType__c\n    value: \n      FIELD:\n        path:\
      \ CA10__healthCheckType__c          \n"
  - path: /ce/ca/aws/autoscaling/group-with-elb-without-elb-health-check/test-data.json
    md5Hash: C079D116AE211EE68A573FA2AE2008B0
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-04-15T22:26:01Z"
              },
              "Id": "test1",
              "CA10__disappearanceTime__c": "2025-04-07T08:34:09Z",
              "CA10__healthCheckType__c": "EC2",
              "CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r": [
                  {
                      "Id": "test1_1",
                      "CA10__disappearanceTime__c": "2025-04-07T08:34:09Z",
                      "CA10__trafficSourceType__c": "elbv2",
                      "CA10__autoScalingGroup__c": "test1"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r.hasNo(COMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-04-15T22:26:01Z"
              },
              "Id": "test2",
              "CA10__disappearanceTime__c": null,
              "CA10__healthCheckType__c": "EC2",
              "CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r": []
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r.hasNo(COMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-04-15T22:26:01Z"
              },
              "Id": "test3",
              "CA10__disappearanceTime__c": null,
              "CA10__healthCheckType__c": "EC2",
              "CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r": [
                  {
                      "Id": "test3_1",
                      "CA10__disappearanceTime__c": "2025-04-07T08:34:09Z",
                      "CA10__trafficSourceType__c": "elbv2",
                      "CA10__autoScalingGroup__c": "test3"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r.hasNo(COMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-04-15T22:26:01Z"
              },
              "Id": "test4",
              "CA10__disappearanceTime__c": null,
              "CA10__healthCheckType__c": "EC2",
              "CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r": [
                  {
                      "Id": "test4_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__trafficSourceType__c": "vpc-lattice",
                      "CA10__autoScalingGroup__c": "test4"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "not(extract('CA10__healthCheckType__c').contains('ELB'))",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-04-15T22:26:01Z"
              },
              "Id": "test5",
              "CA10__disappearanceTime__c": null,
              "CA10__healthCheckType__c": "EC2",
              "CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r": [
                  {
                      "Id": "test5_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__trafficSourceType__c": "elbv2",
                      "CA10__autoScalingGroup__c": "test5"
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "399",
                  "conditionText": "extract('CA10__healthCheckType__c').contains('ELB')",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-04-15T22:26:01Z"
              },
              "Id": "test6",
              "CA10__disappearanceTime__c": null,
              "CA10__healthCheckType__c": "ELB",
              "CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r": [
                  {
                      "Id": "test6_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__trafficSourceType__c": "elb",
                      "CA10__autoScalingGroup__c": "test6"
                  }
              ]
          }
      ]
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__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r.hasNo(COMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r.hasNo(COMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r.hasNo(COMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test5",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "not(extract('CA10__healthCheckType__c').contains('ELB'))",
      "runtimeError" : null
    }
  }, {
    "Id" : "test6",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "extract('CA10__healthCheckType__c').contains('ELB')",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsAutoScalingGroup__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__healthCheckType__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-04-15T22:26:01Z")
    },
    "Id" : "test1",
    "CA10__disappearanceTime__c" : new Date("2025-04-07T08:34:09Z"),
    "CA10__healthCheckType__c" : "EC2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-04-15T22:26:01Z")
    },
    "Id" : "test2",
    "CA10__healthCheckType__c" : "EC2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-04-15T22:26:01Z")
    },
    "Id" : "test3",
    "CA10__healthCheckType__c" : "EC2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-04-15T22:26:01Z")
    },
    "Id" : "test4",
    "CA10__healthCheckType__c" : "EC2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-04-15T22:26:01Z")
    },
    "Id" : "test5",
    "CA10__healthCheckType__c" : "EC2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-04-15T22:26:01Z")
    },
    "Id" : "test6",
    "CA10__healthCheckType__c" : "ELB"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsAutoScalingGroupTrafficSourceLink__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__trafficSourceType__c STRING,
      CA10__autoScalingGroup__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-04-15T22:26:01Z")
    },
    "Id" : "test1_1",
    "CA10__disappearanceTime__c" : new Date("2025-04-07T08:34:09Z"),
    "CA10__trafficSourceType__c" : "elbv2",
    "CA10__autoScalingGroup__c" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-04-15T22:26:01Z")
    },
    "Id" : "test3_1",
    "CA10__disappearanceTime__c" : new Date("2025-04-07T08:34:09Z"),
    "CA10__trafficSourceType__c" : "elbv2",
    "CA10__autoScalingGroup__c" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-04-15T22:26:01Z")
    },
    "Id" : "test4_1",
    "CA10__trafficSourceType__c" : "vpc-lattice",
    "CA10__autoScalingGroup__c" : "test4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-04-15T22:26:01Z")
    },
    "Id" : "test5_1",
    "CA10__trafficSourceType__c" : "elbv2",
    "CA10__autoScalingGroup__c" : "test5"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-04-15T22:26:01Z")
    },
    "Id" : "test6_1",
    "CA10__trafficSourceType__c" : "elb",
    "CA10__autoScalingGroup__c" : "test6"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsAutoScalingGroup__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__healthCheckType__c STRING,
          CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r ARRAY<STRUCT<
              Id STRING,
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__trafficSourceType__c STRING,
              CA10__autoScalingGroup__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));
          };
      }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From AWS [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c);
      if (obj.CA10__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r_COMPLIANT2 = 0;
      if (obj.CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r != null) {
          for (var i3 = 0; i3 < obj.CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r.length; i3++) {
              if (obj.CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r[i3].result.status == 'COMPLIANT') {
                  count_CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r_COMPLIANT2 += 1;
              }
          }
      }
      // condition[1], conditionIndex:[100..199]
      references1.push('Related list [CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r] ' + (count_CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r_COMPLIANT2 == 0 ? 'does not have' : 'has') + ' objects in COMPLIANT status');
      if (count_CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r_COMPLIANT2 == 0) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r.hasNo(COMPLIANT)", currentStateMessage: "The AGS is not associated with a Load Balancer.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract5() { if (!this.out) { this.out = obj.CA10__healthCheckType__c; } return this.out; };
      references1.push('Health Check Type [obj.CA10__healthCheckType__c]: ' + obj.CA10__healthCheckType__c);
      if (!TextLib.contains(extract5.call(extract5), 'ELB')) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "not(extract('CA10__healthCheckType__c').contains('ELB'))", currentStateMessage: "The AGS behind ELB does not use ELB health check.", currentStateReferences: references1.join('\n'), remediation: "Configure Auto Scaling Group to use ELB health check.", runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      function extract8() { if (!this.out) { this.out = obj.CA10__healthCheckType__c; } return this.out; };
      if (TextLib.contains(extract8.call(extract8), 'ELB')) {
          return {status: 'COMPLIANT', conditionIndex: 399, conditionText: "extract('CA10__healthCheckType__c').contains('ELB')", currentStateMessage: "The ASG uses ELB health check.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'UNDETERMINED', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "Unexpected values in the fields.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__trafficSourceType__c STRING,
          CA10__autoScalingGroup__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 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__trafficSourceType__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__trafficSourceType__c.isEmpty()", currentStateMessage: "Possibly corrupted data. Traffic source type cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__trafficSourceType__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Traffic Source Type [obj.CA10__trafficSourceType__c]: ' + obj.CA10__trafficSourceType__c);
      try {
          if (TextLib.equal(extract3.call(extract3), 'elb')) {
              return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__trafficSourceType__c') == 'elb'", currentStateMessage: "The ASG traffic source is a Classic Load Balancer.", 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__trafficSourceType__c)) {
              throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "CA10__trafficSourceType__c.isEmpty()", currentStateMessage: "Possibly corrupted data. Traffic source type cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__trafficSourceType__c;
      }
      function extract6() { if (!this.out) { this.out = fieldChecked7(); } return this.out; };
      try {
          if (TextLib.equal(extract6.call(extract6), 'elbv2')) {
              return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__trafficSourceType__c') == 'elbv2'", currentStateMessage: "The ASG traffic source is an ELB target group.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'INAPPLICABLE', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "Unrelated ASG traffic source.", 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__healthCheckType__c AS CA10__healthCheckType__c,
          `CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r`.arr AS CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r,
          process_CA10__CaAwsAutoScalingGroup__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__healthCheckType__c AS CA10__healthCheckType__c,
                  `CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r`.arr AS CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsAutoScalingGroup__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10__autoScalingGroup__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__trafficSourceType__c AS CA10__trafficSourceType__c,
                      sObject.CA10__autoScalingGroup__c AS CA10__autoScalingGroup__c,
                      process_CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__trafficSourceType__c AS CA10__trafficSourceType__c,
                              sObject.CA10__autoScalingGroup__c AS CA10__autoScalingGroup__c
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaAwsAutoScalingGroupTrafficSourceLink__c()) AS sObject
          GROUP BY sObject.CA10__autoScalingGroup__c
      ) AS `CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r`
          ON sObject.Id = `CA10__AWS_EC2_Auto_Scaling_Group_Tfc_Src_Links__r`.CA10__autoScalingGroup__c
  ) sObject ON sObject.Id = expectedResult.Id;
