---
policy: /ce/ca/aws/elastic-beanstalk/environment-logs
logic: /ce/ca/aws/elastic-beanstalk/environment-logs/prod.logic.yaml
executionTime: 2025-12-27T12:01:57.606279745Z
generationMs: 94
executionMs: 803
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: extract('CA10__status__c') != 'Ready'
      actual: extract('CA10__status__c') != 'Ready'
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: CA10__AWS_Beanstalk_Configuration_Settings__r.has(COMPLIANT)
      actual: CA10__AWS_Beanstalk_Configuration_Settings__r.has(COMPLIANT)
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: CA10__AWS_Beanstalk_Configuration_Settings__r.has(COMPLIANT)
      actual: CA10__AWS_Beanstalk_Configuration_Settings__r.has(COMPLIANT)
    runtimeError: {}
  - id: test5
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: CA10__AWS_Beanstalk_Configuration_Settings__r.has(INCOMPLIANT)
      actual: CA10__AWS_Beanstalk_Configuration_Settings__r.has(INCOMPLIANT)
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/elastic-beanstalk/environment-logs/policy.yaml
    md5Hash: 199301D242B1DB7F07FC778CF383B709
    content: "---\nnames:\n  full: \"AWS Elastic Beanstalk Environment does not have\
      \ logs enabled\"\n  contextual: \"Environment does not have logs enabled\"\n\
      description: >\n  Ensure that AWS Elastic Beanstalk environments are configured\
      \ to publish logs. \n  Enabling log publication to Amazon S3 or streaming logs\
      \ to Amazon CloudWatch Logs \n  ensures that instance logs are preserved for\
      \ troubleshooting, auditing, and \n  historical analysis.\ntype: \"COMPLIANCE_POLICY\"\
      \ncategories:\n  - \"SECURITY\"\n  - \"RELIABILITY\"\nframeworkMappings:\n \
      \ - \"/frameworks/cloudaware/logging-and-monitoring/logging-and-monitoring-configuration\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/elastic-beanstalk/03\"\n  - \"/frameworks/aws-well-architected/sec/04/02\"\
      \n  - \"/frameworks/aws-well-architected/rel/06/05\"\nsimilarPolicies:\n  awsSecurityHub:\n\
      \    - name: \"[ElasticBeanstalk.3] Elastic Beanstalk should stream logs to\
      \ CloudWatch\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/elasticbeanstalk-controls.html#elasticbeanstalk-3\"\
      \n  cloudConformity:\n    - url: \"https://www.trendmicro.com/cloudoneconformity/knowledge-base/aws/ElasticBeanstalk/logging-enabled.html\"\
      \n      name: Elastic Beanstalk Persistent Logs\n"
  - path: /ce/ca/aws/elastic-beanstalk/environment-logs/prod.logic.yaml
    md5Hash: 372292DCD1C499CD24081BA3B7428915
    content: |
      ---
      inputType: "CA10__CaAwsBeanstalkEnvironment__c"
      testData:
        - file: "test-data.json"
      importExtracts:
        - file: "/types/CA10__CaAwsBeanstalkEnvironment__c/object.extracts.yaml"
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "The Elastic Beanstalk Environment is not in the Ready status."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10__status__c"
              right:
                TEXT: "Ready"
        - status: "INCOMPLIANT"
          currentStateMessage: "Logs are not enabled for this Elastic Beanstalk Environment."
          remediationMessage: "Enable CloudWatch log streaming or S3 log rotation for the environment."
          check:
            RELATED_LIST_HAS:
              status: "INCOMPLIANT"
              relationshipName: "CA10__AWS_Beanstalk_Configuration_Settings__r"
        - status: "COMPLIANT"
          currentStateMessage: "Logs are enabled for this Elastic Beanstalk Environment."
          check:
            RELATED_LIST_HAS:
              status: "COMPLIANT"
              relationshipName: "CA10__AWS_Beanstalk_Configuration_Settings__r"
      otherwise:
        status: "UNDETERMINED"
        currentStateMessage: "Unable to determine logs configuration for this Elastic Beanstalk Environment."
      relatedLists:
        - relationshipName: "CA10__AWS_Beanstalk_Configuration_Settings__r"
          importExtracts:
            - file: "/types/CA10__CaAwsBeanstalkConfigurationSettings__c/object.extracts.yaml"
          recordTypes:
            - "caEnvironmentConfigurationSettings"
          conditions:
            - status: "COMPLIANT"
              currentStateMessage: "Elastic Beanstalk Environment logs enabled."
              check:
                OR:
                  args:
                    - CONTAINS:
                        arg:
                          EXTRACT: "caSetFrom_optionSettings__c"
                        search:
                          TEXT: "aws:elasticbeanstalk:hostmanager LogPublicationControl true"
                    - CONTAINS:
                        arg:
                          EXTRACT: "caSetFrom_optionSettings__c"
                        search:
                          TEXT: "aws:elasticbeanstalk:cloudwatch:logs StreamLogs true"
          otherwise:
            status: "INCOMPLIANT"
            currentStateMessage: "Elastic Beanstalk Environment logs aren't enabled."
  - path: /ce/ca/aws/elastic-beanstalk/environment-logs/test-data.json
    md5Hash: BF6602AD3C99617140460B265DABB283
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-22T08:35:50Z"
              },
              "CA10__disappearanceTime__c": "2025-10-22T08:35:50Z",
              "CA10__status__c": "Ready",
              "Id": "test1",
              "CA10__AWS_Beanstalk_Configuration_Settings__r": [
                  {
                      "Id": "test1_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__optionSettings__c": "aws:elasticbeanstalk:healthreporting:system SystemType basic",
                      "CA10__environment__c": "test1",
                      "RecordTypeId": "RecordTypeId",
                      "RecordType": {
                          "Id": "RecordTypeId",
                          "DeveloperName": "caEnvironmentConfigurationSettings"
                      }
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__status__c') != 'Ready'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-22T08:35:50Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "Terminated",
              "Id": "test2",
              "CA10__AWS_Beanstalk_Configuration_Settings__r": [
                  {
                      "Id": "test2_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__optionSettings__c": "aws:elasticbeanstalk:healthreporting:system SystemType basic",
                      "CA10__environment__c": "test2",
                      "RecordTypeId": "RecordTypeId",
                      "RecordType": {
                          "Id": "RecordTypeId",
                          "DeveloperName": "caEnvironmentConfigurationSettings"
                      }
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "399",
                  "conditionText": "CA10__AWS_Beanstalk_Configuration_Settings__r.has(COMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-22T08:35:50Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "Ready",
              "Id": "test3",
              "CA10__AWS_Beanstalk_Configuration_Settings__r": [
                  {
                      "Id": "test3_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__optionSettings__c": "aws:elasticbeanstalk:hostmanager LogPublicationControl true\naws:elasticbeanstalk:cloudwatch:logs StreamLogs false",
                      "CA10__environment__c": "test3",
                      "RecordTypeId": "RecordTypeId",
                      "RecordType": {
                          "Id": "RecordTypeId",
                          "DeveloperName": "caEnvironmentConfigurationSettings"
                      }
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "399",
                  "conditionText": "CA10__AWS_Beanstalk_Configuration_Settings__r.has(COMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-22T08:35:50Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "Ready",
              "Id": "test4",
              "CA10__AWS_Beanstalk_Configuration_Settings__r": [
                  {
                      "Id": "test4_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__optionSettings__c": "aws:elasticbeanstalk:hostmanager LogPublicationControl false\naws:elasticbeanstalk:cloudwatch:logs StreamLogs true",
                      "CA10__environment__c": "test4",
                      "RecordTypeId": "RecordTypeId",
                      "RecordType": {
                          "Id": "RecordTypeId",
                          "DeveloperName": "caEnvironmentConfigurationSettings"
                      }
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "CA10__AWS_Beanstalk_Configuration_Settings__r.has(INCOMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-22T08:35:50Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "Ready",
              "Id": "test5",
              "CA10__AWS_Beanstalk_Configuration_Settings__r": [
                  {
                      "Id": "test5_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__optionSettings__c": "",
                      "CA10__environment__c": "test5",
                      "RecordTypeId": "RecordTypeId",
                      "RecordType": {
                          "Id": "RecordTypeId",
                          "DeveloperName": "caEnvironmentConfigurationSettings"
                      }
                  }
              ]
          }
      ]
  - path: /types/CA10__CaAwsBeanstalkEnvironment__c/object.extracts.yaml
    md5Hash: 7ACAF7762510181D988F30947AAC6E3C
    content: "---\nextracts:\n# Values: Aborting | Launching | Updating | LinkingFrom\
      \ | LinkingTo | Ready | Terminating | Terminated.\n# Not nullable. Can't have\
      \ no access, retrieved via elasticbeanstalk:DescribeEnvironments\n  - name:\
      \ CA10__status__c\n    value: \n      FIELD:\n        path: CA10__status__c\n"
  - path: /types/CA10__CaAwsBeanstalkConfigurationSettings__c/object.extracts.yaml
    md5Hash: F3CD872B998B7F9C970705C541D5636E
    content: "---\nextracts:\n  - name: CA10__optionSettings__c\n    value: \n   \
      \   FIELD:\n        path: CA10__optionSettings__c\n  - name: caSetFrom_optionSettings__c\n\
      \    value: \n      SET_FROM:\n        separator: \"\\n\"\n        arg:\n  \
      \        EXTRACT: CA10__optionSettings__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" : "extract('CA10__status__c') != 'Ready'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "CA10__AWS_Beanstalk_Configuration_Settings__r.has(COMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "CA10__AWS_Beanstalk_Configuration_Settings__r.has(COMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test5",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "CA10__AWS_Beanstalk_Configuration_Settings__r.has(INCOMPLIANT)",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsBeanstalkEnvironment__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__status__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-10-22T08:35:50Z")
    },
    "CA10__disappearanceTime__c" : new Date("2025-10-22T08:35:50Z"),
    "CA10__status__c" : "Ready",
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-22T08:35:50Z")
    },
    "CA10__status__c" : "Terminated",
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-22T08:35:50Z")
    },
    "CA10__status__c" : "Ready",
    "Id" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-22T08:35:50Z")
    },
    "CA10__status__c" : "Ready",
    "Id" : "test4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-22T08:35:50Z")
    },
    "CA10__status__c" : "Ready",
    "Id" : "test5"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsBeanstalkConfigurationSettings__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__optionSettings__c STRING,
      CA10__environment__c STRING,
      Id STRING,
      RecordTypeId STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-10-22T08:35:50Z")
    },
    "CA10__optionSettings__c" : "aws:elasticbeanstalk:healthreporting:system SystemType basic",
    "CA10__environment__c" : "test1",
    "Id" : "test1_1",
    "RecordTypeId" : "RecordTypeId"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-22T08:35:50Z")
    },
    "CA10__optionSettings__c" : "aws:elasticbeanstalk:healthreporting:system SystemType basic",
    "CA10__environment__c" : "test2",
    "Id" : "test2_1",
    "RecordTypeId" : "RecordTypeId"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-22T08:35:50Z")
    },
    "CA10__optionSettings__c" : "aws:elasticbeanstalk:hostmanager LogPublicationControl true\naws:elasticbeanstalk:cloudwatch:logs StreamLogs false",
    "CA10__environment__c" : "test3",
    "Id" : "test3_1",
    "RecordTypeId" : "RecordTypeId"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-22T08:35:50Z")
    },
    "CA10__optionSettings__c" : "aws:elasticbeanstalk:hostmanager LogPublicationControl false\naws:elasticbeanstalk:cloudwatch:logs StreamLogs true",
    "CA10__environment__c" : "test4",
    "Id" : "test4_1",
    "RecordTypeId" : "RecordTypeId"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-22T08:35:50Z")
    },
    "CA10__optionSettings__c" : "",
    "CA10__environment__c" : "test5",
    "Id" : "test5_1",
    "RecordTypeId" : "RecordTypeId"
  } ];
  """;

  CREATE TEMP FUNCTION mock_RecordType()
  RETURNS ARRAY<STRUCT<
      DeveloperName STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-10-22T08:35:50Z")
    },
    "DeveloperName" : "caEnvironmentConfigurationSettings",
    "Id" : "RecordTypeId"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsBeanstalkEnvironment__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__status__c STRING,
          Id STRING,
          CA10__AWS_Beanstalk_Configuration_Settings__r ARRAY<STRUCT<
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__optionSettings__c STRING,
              CA10__environment__c STRING,
              Id STRING,
              RecordTypeId STRING,
              RecordType STRUCT<
                  DeveloperName STRING,
                  Id STRING
              >,
              result STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
          >>
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
  var TextLib = new function () {
      this.normalize = function(arg) {
          return arg == null ? '' : arg.replace(/\s+/g, ' ').trim().toLowerCase();
      };
      this.isEmpty = function(arg) {
          return this.normalize(arg) == '';
      };
      this.isNotEmpty = function(arg) {
          return this.normalize(arg) != '';
      };
      this.equal = function(left, right) {
          return this.normalize(left) == this.normalize(right);
      };
      this.notEqual = function(left, right) {
          return this.normalize(left) != this.normalize(right);
      };
      this.startsWith = function(arg, substring) {
          return this.normalize(arg).startsWith(this.normalize(substring));
      };
      this.endsWith = function(arg, substring) {
          return this.normalize(arg).endsWith(this.normalize(substring));
      };
      this.contains = function(arg, substring) {
          return this.normalize(arg).includes(this.normalize(substring));
      };
      this.containsAll = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.every(sub => normalizedArg.includes(this.normalize(sub)));
      };
      this.containsAny = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.some(sub => normalizedArg.includes(this.normalize(sub)));
      };
  }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From AWS [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c);
      if (obj.CA10__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[1], conditionIndex:[100..199]
      function extract3() { if (!this.out) { this.out = obj.CA10__status__c; } return this.out; };
      references1.push('Status [obj.CA10__status__c]: ' + obj.CA10__status__c);
      if (TextLib.notEqual(extract3.call(extract3), 'Ready')) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__status__c') != 'Ready'", currentStateMessage: "The Elastic Beanstalk Environment is not in the Ready status.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10__AWS_Beanstalk_Configuration_Settings__r_INCOMPLIANT5 = 0;
      if (obj.CA10__AWS_Beanstalk_Configuration_Settings__r != null) {
          for (var i6 = 0; i6 < obj.CA10__AWS_Beanstalk_Configuration_Settings__r.length; i6++) {
              if (typeof(obj.CA10__AWS_Beanstalk_Configuration_Settings__r[i6].status) !== 'undefined') {
                  if (obj.CA10__AWS_Beanstalk_Configuration_Settings__r[i6].status == 'INCOMPLIANT') {
                      count_CA10__AWS_Beanstalk_Configuration_Settings__r_INCOMPLIANT5 += obj.CA10__AWS_Beanstalk_Configuration_Settings__r[i6].count;
                  }
              } else  {
                  if (obj.CA10__AWS_Beanstalk_Configuration_Settings__r[i6].result.status == 'INCOMPLIANT') {
                      count_CA10__AWS_Beanstalk_Configuration_Settings__r_INCOMPLIANT5 += 1;
                  }
              }
          }
      }
      // condition[2], conditionIndex:[200..299]
      references1.push('Related list [CA10__AWS_Beanstalk_Configuration_Settings__r] ' + (count_CA10__AWS_Beanstalk_Configuration_Settings__r_INCOMPLIANT5 > 0 ? 'has' : 'does not have') + ' objects in INCOMPLIANT status');
      if (count_CA10__AWS_Beanstalk_Configuration_Settings__r_INCOMPLIANT5 > 0) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "CA10__AWS_Beanstalk_Configuration_Settings__r.has(INCOMPLIANT)", currentStateMessage: "Logs are not enabled for this Elastic Beanstalk Environment.", currentStateReferences: references1.join('\n'), remediation: "Enable CloudWatch log streaming or S3 log rotation for the environment.", runtimeError: null};
      }
      var count_CA10__AWS_Beanstalk_Configuration_Settings__r_COMPLIANT7 = 0;
      if (obj.CA10__AWS_Beanstalk_Configuration_Settings__r != null) {
          for (var i8 = 0; i8 < obj.CA10__AWS_Beanstalk_Configuration_Settings__r.length; i8++) {
              if (typeof(obj.CA10__AWS_Beanstalk_Configuration_Settings__r[i8].status) !== 'undefined') {
                  if (obj.CA10__AWS_Beanstalk_Configuration_Settings__r[i8].status == 'COMPLIANT') {
                      count_CA10__AWS_Beanstalk_Configuration_Settings__r_COMPLIANT7 += obj.CA10__AWS_Beanstalk_Configuration_Settings__r[i8].count;
                  }
              } else  {
                  if (obj.CA10__AWS_Beanstalk_Configuration_Settings__r[i8].result.status == 'COMPLIANT') {
                      count_CA10__AWS_Beanstalk_Configuration_Settings__r_COMPLIANT7 += 1;
                  }
              }
          }
      }
      // condition[3], conditionIndex:[300..399]
      if (count_CA10__AWS_Beanstalk_Configuration_Settings__r_COMPLIANT7 > 0) {
          return {status: 'COMPLIANT', conditionIndex: 399, conditionText: "CA10__AWS_Beanstalk_Configuration_Settings__r.has(COMPLIANT)", currentStateMessage: "Logs are enabled for this Elastic Beanstalk Environment.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'UNDETERMINED', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "Unable to determine logs configuration for this Elastic Beanstalk Environment.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__AWS_Beanstalk_Configuration_Settings__r(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__optionSettings__c STRING,
          CA10__environment__c STRING,
          Id STRING,
          RecordTypeId STRING,
          RecordType STRUCT<
              DeveloperName STRING,
              Id STRING
          >
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
  var TextLib = new function () {
      this.normalize = function(arg) {
          return arg == null ? '' : arg.replace(/\s+/g, ' ').trim().toLowerCase();
      };
      this.isEmpty = function(arg) {
          return this.normalize(arg) == '';
      };
      this.isNotEmpty = function(arg) {
          return this.normalize(arg) != '';
      };
      this.equal = function(left, right) {
          return this.normalize(left) == this.normalize(right);
      };
      this.notEqual = function(left, right) {
          return this.normalize(left) != this.normalize(right);
      };
      this.startsWith = function(arg, substring) {
          return this.normalize(arg).startsWith(this.normalize(substring));
      };
      this.endsWith = function(arg, substring) {
          return this.normalize(arg).endsWith(this.normalize(substring));
      };
      this.contains = function(arg, substring) {
          return this.normalize(arg).includes(this.normalize(substring));
      };
      this.containsAll = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.every(sub => normalizedArg.includes(this.normalize(sub)));
      };
      this.containsAny = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.some(sub => normalizedArg.includes(this.normalize(sub)));
      };
  }();
  var BytesLib = new function () {
      this.normalize = function(arg) {
          return arg == null ? '' : arg;
      };
      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 CollectionLib = new function () {
      this.parse = function(arg, separator, skipEmpty, skipDuplicates, sort, normalize) {
          if (arg == null) return [];
          let parts = arg.split(separator);
          return this.fromArray(parts, skipEmpty, skipDuplicates, sort, normalize);
      };
      this.fromArray = function(arr, skipEmpty, skipDuplicates, sort, normalize) {
          if (arr == null) return [];
          let result = [];
          let seen = new Set();
          arr.forEach(el => {
              let normalized = normalize ? TextLib.normalize(el) : BytesLib.normalize(el);
              if (!skipEmpty || (normalize ? TextLib.isNotEmpty(el) : BytesLib.isNotEmpty(el))) {
                  if (!skipDuplicates || !seen.has(normalized)) {
                      if (skipDuplicates) seen.add(normalized);
                      result.push(normalized);
                  }
              }
          });
          if (sort) result.sort();
          return result;
      };
      this.equal = function(left, right) {
          left = left == null ? [] : left;
          right = right == null ? [] : right;
          if (left.length !== right.length) return false;
          for (let i = 0; i < left.length; i++) {
              if (left[i] !== right[i]) return false;
          }
          return true;
      };
      this.notEqual = function(left, right) {
          return !this.equal(left, right);
      };
      this.size = function(collection) {
          return collection == null ? 0 : collection.length;
      };
      this.startsWith = function(collection, search, normalize) {
          if (collection == null || collection.length === 0) return false;
          let normalizedSearch = normalize ? TextLib.normalize(search) : BytesLib.normalize(search);
          return collection[0] === normalizedSearch;
      };
      this.endsWith = function(collection, search, normalize) {
          if (collection == null || collection.length === 0) return false;
          let normalizedSearch = normalize ? TextLib.normalize(search) : BytesLib.normalize(search);
          return collection[collection.length - 1] === normalizedSearch;
      };
      this.contains = function(collection, search, normalize) {
          if (collection == null || collection.length === 0) return false;
          return collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search));
      };
      this.containsAll = function(collection, searchArray, normalize) {
          if (collection == null || collection.length === 0 || searchArray == null || searchArray.length === 0) return false;
          return searchArray.every(search => collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search)));
      };
      this.containsAny = function(collection, searchArray, normalize) {
          if (collection == null || collection.length === 0 || searchArray == null || searchArray.length === 0) return false;
          return searchArray.some(search => collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search)));
      };
  }();
      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]
      references1.push('Record Type Name [obj.RecordType.DeveloperName]: ' + obj.RecordType.DeveloperName);
      if (!CollectionLib.contains(CollectionLib.fromArray(['caEnvironmentConfigurationSettings'], true, true, true, true), obj.RecordType.DeveloperName, true)) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "not(setOfText(['caEnvironmentConfigurationSettings']).contains(RecordType.DeveloperName))", currentStateMessage: "Object record type is not applicable", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10__optionSettings__c; } return this.out; };
      function extract4() { if (!this.out) { this.out = CollectionLib.parse(extract6.call(extract6), '\n', true, true, true, true); } return this.out; };
      references1.push('Option Settings [obj.CA10__optionSettings__c]: ' + obj.CA10__optionSettings__c);
      if (CollectionLib.contains(extract4.call(extract4), 'aws:elasticbeanstalk:hostmanager LogPublicationControl true', true) || CollectionLib.contains(extract4.call(extract4), 'aws:elasticbeanstalk:cloudwatch:logs StreamLogs true', true)) {
          return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "extract('caSetFrom_optionSettings__c').contains('aws:elasticbeanstalk:hostmanager LogPublicationControl true') || extract('caSetFrom_optionSettings__c').contains('aws:elasticbeanstalk:cloudwatch:logs StreamLogs true')", currentStateMessage: "Elastic Beanstalk Environment logs enabled.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'INCOMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "Elastic Beanstalk Environment logs aren't enabled.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;


  SELECT
    expectedResult.Id as Id,
    IF (
      IFNULL(expectedResult.expectedResult.status, '') = IFNULL(sObject.result.status, '')
      AND IFNULL(expectedResult.expectedResult.conditionIndex, -1) = IFNULL(sObject.result.conditionIndex, -1)
      AND IFNULL(expectedResult.expectedResult.conditionText, '') = IFNULL(sObject.result.conditionText, '')
      AND IFNULL(expectedResult.expectedResult.runtimeError, '') = IFNULL(sObject.result.runtimeError, ''),
      "MATCH",
      "FAIL"
    ) as match,
    expectedResult.expectedResult.status as expectedStatus, sObject.result.status as actualStatus,
    expectedResult.expectedResult.conditionIndex as expectedConditionIndex, sObject.result.conditionIndex as actualConditionIndex,
    expectedResult.expectedResult.conditionText as expectedConditionText, sObject.result.conditionText as actualConditionText,
    expectedResult.expectedResult.runtimeError as expectedRuntimeError, sObject.result.runtimeError as actualRuntimeError
  FROM UNNEST(mock_ExpectedResult()) expectedResult
  LEFT JOIN (
      SELECT
          sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__status__c AS CA10__status__c,
          sObject.Id AS Id,
          `CA10__AWS_Beanstalk_Configuration_Settings__r`.arr AS CA10__AWS_Beanstalk_Configuration_Settings__r,
          process_CA10__CaAwsBeanstalkEnvironment__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__status__c AS CA10__status__c,
                  sObject.Id AS Id,
                  `CA10__AWS_Beanstalk_Configuration_Settings__r`.arr AS CA10__AWS_Beanstalk_Configuration_Settings__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsBeanstalkEnvironment__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10__environment__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__optionSettings__c AS CA10__optionSettings__c,
                      sObject.CA10__environment__c AS CA10__environment__c,
                      sObject.Id AS Id,
                      sObject.RecordTypeId AS RecordTypeId,
                      STRUCT (
                          `RecordType`.DeveloperName AS DeveloperName,
                          `RecordType`.Id AS Id
                      ) AS RecordType,
                      process_CA10__AWS_Beanstalk_Configuration_Settings__r(
                          STRUCT(
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__optionSettings__c AS CA10__optionSettings__c,
                              sObject.CA10__environment__c AS CA10__environment__c,
                              sObject.Id AS Id,
                              sObject.RecordTypeId AS RecordTypeId,
                              STRUCT (
                                  `RecordType`.DeveloperName AS DeveloperName,
                                  `RecordType`.Id AS Id
                              ) AS RecordType
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaAwsBeanstalkConfigurationSettings__c()) AS sObject
          LEFT JOIN UNNEST(mock_RecordType()) AS `RecordType`
              ON sObject.RecordTypeId = `RecordType`.Id
          GROUP BY sObject.CA10__environment__c
      ) AS `CA10__AWS_Beanstalk_Configuration_Settings__r`
          ON sObject.Id = `CA10__AWS_Beanstalk_Configuration_Settings__r`.CA10__environment__c
  ) sObject ON sObject.Id = expectedResult.Id;
