---
policy: /ce/ca/aws/elb/load-balancer-connection-draining
logic: /ce/ca/aws/elb/load-balancer-connection-draining/prod.logic.yaml
executionTime: 2026-01-31T12:01:56.098018753Z
generationMs: 61
executionMs: 643
rows:
  - id: '001'
    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: '002'
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__type__c') != 'classic'
      actual: extract('CA10__type__c') != 'classic'
    runtimeError: {}
  - id: '003'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__connectionDrainingEnabled__c') == false
      actual: extract('CA10__connectionDrainingEnabled__c') == false
    runtimeError: {}
  - id: '004'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: extract('CA10__connectionDrainingEnabled__c') == true
      actual: extract('CA10__connectionDrainingEnabled__c') == true
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/elb/load-balancer-connection-draining/policy.yaml
    md5Hash: 181BB223E08D89B964F9B4D8B17CFBBE
    content: "---\nnames:\n  full: \"AWS ELB Classic Load Balancer Connection Draining\
      \ is disabled\"\n  contextual: \"Classic Load Balancer Connection Draining is\
      \ disabled\"\ndescription: >\n  Ensure that connection draining is enabled for\
      \ AWS Classic Load Balancers. \n  Connection draining allows the load balancer\
      \ to complete in-flight requests \n  made to instances that are deregistering\
      \ or becoming unhealthy, preventing \n  service interruptions during maintenance\
      \ or scaling events.\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n  - \"RELIABILITY\"\
      \nframeworkMappings:\n  - \"/frameworks/cloudaware/resource-reliability/system-configuration\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/elb/07\"\nsimilarPolicies:\n  awsSecurityHub:\n\
      \    - name: \"[ELB.7] Classic Load Balancers should have connection draining\
      \ enabled\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/elb-controls.html#elb-7\"\
      \n  cloudConformity:\n    - url: https://www.trendmicro.com/cloudoneconformity/knowledge-base/aws/ELB/elb-connection-draining-enabled.html\n\
      \      name: ELB Connection Draining Enabled"
  - path: /ce/ca/aws/elb/load-balancer-connection-draining/prod.logic.yaml
    md5Hash: CA385ADC5C1A470299045482755B0A40
    content: |
      ---
      inputType: "CA10__CaAwsLoadBalancer__c"
      importExtracts:
        - file: "/types/CA10__CaAwsLoadBalancer__c/object.extracts.yaml"
      testData:
        - file: "test-data.json"
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "Connection Draining is supported only for Classic Load Balancers."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10__type__c"
              right:
                TEXT: "classic"
        - status: "INCOMPLIANT"
          currentStateMessage: "The Load Balancer Connection Draining is not enabled."
          remediationMessage: "Enable Load Balancer Connection Draining."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__connectionDrainingEnabled__c"
              right:
                BOOLEAN: false
        - status: "COMPLIANT"
          currentStateMessage: "The Load Balancer Connection Draining is enabled."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__connectionDrainingEnabled__c"
              right:
                BOOLEAN: true
      otherwise:
        status: "UNDETERMINED"
        currentStateMessage: "Unexpected values in the field."
  - path: /ce/ca/aws/elb/load-balancer-connection-draining/test-data.json
    md5Hash: C105CB2129AA70EB240B27CA83D8428B
    content: |
      [
        {
          "expectedResult": {
            "status": "DISAPPEARED",
            "conditionIndex": "99",
            "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2026-01-07T07:54:04Z" },
          "CA10__disappearanceTime__c": "2025-12-29T17:28:56Z",
          "CA10__type__c": "classic",
          "CA10__connectionDrainingEnabled__c": false,
          "Id": "001",
          "RecordTypeId": "Rt_001",
          "RecordType": { "Id": "Rt_001" }
        },
        {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "199",
            "conditionText": "extract('CA10__type__c') != 'classic'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2026-01-07T07:54:04Z" },
          "CA10__disappearanceTime__c": null,
          "CA10__type__c": "application",
          "CA10__connectionDrainingEnabled__c": false,
          "Id": "002",
          "RecordTypeId": "Rt_001",
          "RecordType": { "Id": "Rt_001" }
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "299",
            "conditionText": "extract('CA10__connectionDrainingEnabled__c') == false",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2026-01-07T07:54:04Z" },
          "CA10__disappearanceTime__c": null,
          "CA10__type__c": "classic",
          "CA10__connectionDrainingEnabled__c": false,
          "Id": "003",
          "RecordTypeId": "Rt_001",
          "RecordType": { "Id": "Rt_001" }
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "399",
            "conditionText": "extract('CA10__connectionDrainingEnabled__c') == true",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2026-01-07T07:54:04Z" },
          "CA10__disappearanceTime__c": null,
          "CA10__type__c": "classic",
          "CA10__connectionDrainingEnabled__c": true,
          "Id": "004",
          "RecordTypeId": "Rt_001",
          "RecordType": { "Id": "Rt_001" }
        }
      ]
  - path: /types/CA10__CaAwsLoadBalancer__c/object.extracts.yaml
    md5Hash: 9895F1EB30DFD8DDB6D571F452C5A7DE
    content: "---\nextracts:\n  # The subnets for the load balancer.\n  # Type: Array\
      \ of AvailabilityZone objects\n  # Required: No\n  # \n  # apparently it could\
      \ be empty according to documentation, but I don't believe so and can't find\
      \ any LB without AZs\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: caSetFrom_availabilityZones__c\n    value: \n      SET_FROM:\n  \
      \      separator: \"\\n\"\n        arg:\n          EXTRACT: CA10__availabilityZones__c\n\
      # Checkbox for Classic load balancer record type.\n  - name: CA10__crossZoneLoadBalancing__c\n\
      \    value: \n      FIELD:\n        path: CA10__crossZoneLoadBalancing__c\n\
      # Values: classic | application | network | gateway. Not nullable\n  - name:\
      \ CA10__type__c\n    value: \n      FIELD:\n        path: CA10__type__c\n  \
      \      undeterminedIf:\n          isEmpty: \"Corrupted data. Load Balancer Type\
      \ cannot be empty.\"\n  - name: CA10__additionalAttributes__c\n    value: \n\
      \      FIELD:\n        path: CA10__additionalAttributes__c\n  - name: caSetFrom_additionalAttributes__c\n\
      \    value: \n      SET_FROM:\n        separator: \"\\n\"\n        arg:\n  \
      \        EXTRACT: CA10__additionalAttributes__c\n# Checkbox.\n  - name: CA10__accessLogsEnabled__c\n\
      \    value: \n      FIELD:\n        path: CA10__accessLogsEnabled__c\n# Number.\n\
      \  - name: CA10__requestCountOneMonth__c\n    value: \n      FIELD:\n      \
      \  path: CA10__requestCountOneMonth__c\n# Date/Time.\n  - name: CA10__createdTime__c\n\
      \    value: \n      FIELD:\n        path: CA10__createdTime__c\n# Checkbox.\n\
      \  - name: CA10__connectionDrainingEnabled__c\n    value: \n      FIELD:\n \
      \       path: CA10__connectionDrainingEnabled__c\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" : "001",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "002",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__type__c') != 'classic'",
      "runtimeError" : null
    }
  }, {
    "Id" : "003",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__connectionDrainingEnabled__c') == false",
      "runtimeError" : null
    }
  }, {
    "Id" : "004",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "extract('CA10__connectionDrainingEnabled__c') == true",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsLoadBalancer__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__type__c STRING,
      CA10__connectionDrainingEnabled__c BOOLEAN,
      Id STRING,
      RecordTypeId STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2026-01-07T07:54:04Z")
    },
    "CA10__disappearanceTime__c" : new Date("2025-12-29T17:28:56Z"),
    "CA10__type__c" : "classic",
    "CA10__connectionDrainingEnabled__c" : false,
    "Id" : "001",
    "RecordTypeId" : "Rt_001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-07T07:54:04Z")
    },
    "CA10__type__c" : "application",
    "CA10__connectionDrainingEnabled__c" : false,
    "Id" : "002",
    "RecordTypeId" : "Rt_001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-07T07:54:04Z")
    },
    "CA10__type__c" : "classic",
    "CA10__connectionDrainingEnabled__c" : false,
    "Id" : "003",
    "RecordTypeId" : "Rt_001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-07T07:54:04Z")
    },
    "CA10__type__c" : "classic",
    "CA10__connectionDrainingEnabled__c" : true,
    "Id" : "004",
    "RecordTypeId" : "Rt_001"
  } ];
  """;

  CREATE TEMP FUNCTION mock_RecordType()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2026-01-07T07:54:04Z")
    },
    "Id" : "Rt_001"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsLoadBalancer__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__type__c STRING,
          CA10__connectionDrainingEnabled__c BOOLEAN,
          Id STRING,
          RecordTypeId STRING,
          RecordType STRUCT<
              Id STRING
          >
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
  var TextLib = new function () {
      this.normalize = function(arg) {
          return arg == null ? '' : arg.replace(/\s+/g, ' ').trim().toLowerCase();
      };
      this.isEmpty = function(arg) {
          return this.normalize(arg) == '';
      };
      this.isNotEmpty = function(arg) {
          return this.normalize(arg) != '';
      };
      this.equal = function(left, right) {
          return this.normalize(left) == this.normalize(right);
      };
      this.notEqual = function(left, right) {
          return this.normalize(left) != this.normalize(right);
      };
      this.startsWith = function(arg, substring) {
          return this.normalize(arg).startsWith(this.normalize(substring));
      };
      this.endsWith = function(arg, substring) {
          return this.normalize(arg).endsWith(this.normalize(substring));
      };
      this.contains = function(arg, substring) {
          return this.normalize(arg).includes(this.normalize(substring));
      };
      this.containsAll = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.every(sub => normalizedArg.includes(this.normalize(sub)));
      };
      this.containsAny = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.some(sub => normalizedArg.includes(this.normalize(sub)));
      };
  }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From AWS [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c);
      if (obj.CA10__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[1], conditionIndex:[100..199]
      function fieldChecked4() {
          if (TextLib.isEmpty(obj.CA10__type__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__type__c.isEmpty()", currentStateMessage: "Corrupted data. Load Balancer Type cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__type__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Type [obj.CA10__type__c]: ' + obj.CA10__type__c);
      try {
          if (TextLib.notEqual(extract3.call(extract3), 'classic')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__type__c') != 'classic'", currentStateMessage: "Connection Draining is supported only for Classic Load Balancers.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10__connectionDrainingEnabled__c; } return this.out; };
      references1.push('Connection Draining Enabled [obj.CA10__connectionDrainingEnabled__c]: ' + obj.CA10__connectionDrainingEnabled__c);
      if (extract6.call(extract6) == false) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__connectionDrainingEnabled__c') == false", currentStateMessage: "The Load Balancer Connection Draining is not enabled.", currentStateReferences: references1.join('\n'), remediation: "Enable Load Balancer Connection Draining.", runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      function extract9() { if (!this.out) { this.out = obj.CA10__connectionDrainingEnabled__c; } return this.out; };
      if (extract9.call(extract9) == true) {
          return {status: 'COMPLIANT', conditionIndex: 399, conditionText: "extract('CA10__connectionDrainingEnabled__c') == true", currentStateMessage: "The Load Balancer Connection Draining is enabled.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'UNDETERMINED', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "Unexpected values in the field.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;


  SELECT
    expectedResult.Id as Id,
    IF (
      IFNULL(expectedResult.expectedResult.status, '') = IFNULL(sObject.result.status, '')
      AND IFNULL(expectedResult.expectedResult.conditionIndex, -1) = IFNULL(sObject.result.conditionIndex, -1)
      AND IFNULL(expectedResult.expectedResult.conditionText, '') = IFNULL(sObject.result.conditionText, '')
      AND IFNULL(expectedResult.expectedResult.runtimeError, '') = IFNULL(sObject.result.runtimeError, ''),
      "MATCH",
      "FAIL"
    ) as match,
    expectedResult.expectedResult.status as expectedStatus, sObject.result.status as actualStatus,
    expectedResult.expectedResult.conditionIndex as expectedConditionIndex, sObject.result.conditionIndex as actualConditionIndex,
    expectedResult.expectedResult.conditionText as expectedConditionText, sObject.result.conditionText as actualConditionText,
    expectedResult.expectedResult.runtimeError as expectedRuntimeError, sObject.result.runtimeError as actualRuntimeError
  FROM UNNEST(mock_ExpectedResult()) expectedResult
  LEFT JOIN (
      SELECT
          sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__type__c AS CA10__type__c,
          sObject.CA10__connectionDrainingEnabled__c AS CA10__connectionDrainingEnabled__c,
          sObject.Id AS Id,
          sObject.RecordTypeId AS RecordTypeId,
          STRUCT (
              `RecordType`.Id AS Id
          ) AS RecordType,
          process_CA10__CaAwsLoadBalancer__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__type__c AS CA10__type__c,
                  sObject.CA10__connectionDrainingEnabled__c AS CA10__connectionDrainingEnabled__c,
                  sObject.Id AS Id,
                  sObject.RecordTypeId AS RecordTypeId,
                  STRUCT (
                      `RecordType`.Id AS Id
                  ) AS RecordType
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsLoadBalancer__c()) AS sObject
      LEFT JOIN UNNEST(mock_RecordType()) AS `RecordType`
          ON sObject.RecordTypeId = `RecordType`.Id
  ) sObject ON sObject.Id = expectedResult.Id;
