---
policy: /ce/ca/aws/rds/cluster-cloudwatch-logs-export
logic: /ce/ca/aws/rds/cluster-cloudwatch-logs-export/prod.logic.yaml
executionTime: 2026-01-31T12:02:10.18224453Z
generationMs: 60
executionMs: 741
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: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__enabledCloudwatchLogsExports__c').isNotEmpty()
      actual: extract('CA10__enabledCloudwatchLogsExports__c').isNotEmpty()
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/rds/cluster-cloudwatch-logs-export/policy.yaml
    md5Hash: 550AE5972777EB69C85F4458B83CCA32
    content: "---\nnames:\n  full: \"AWS RDS Cluster database logging is not enabled\"\
      \n  contextual: \"Cluster database logging is not enabled\"\ndescription: >\n\
      \  Ensure that RDS DB clusters are configured to export database logs to CloudWatch\
      \ Logs. \n  Enabling logging provides visibility into database activity, performance\
      \ issues, \n  and security events, which is critical for auditing and incident\
      \ response.\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n  - \"RELIABILITY\"\n\
      frameworkMappings:\n  - \"/frameworks/cloudaware/logging-and-monitoring/logging-and-monitoring-configuration\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/rds/34\"\n  - \"/frameworks/aws-fsbp-v1.0.0/rds/37\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/documentdb/04\"\n  - \"/frameworks/aws-fsbp-v1.0.0/neptune/02\"\
      \nsimilarPolicies:\n  awsSecurityHub:\n    - name: \"[RDS.34] Aurora MySQL DB\
      \ clusters should publish audit logs to CloudWatch Logs\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/rds-controls.html#rds-34\"\
      \n    - name: \"[RDS.37] Aurora PostgreSQL DB clusters should publish logs to\
      \ CloudWatch Logs\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/rds-controls.html#rds-37\"\
      \n    - name: \"[DocumentDB.4] Amazon DocumentDB clusters should publish audit\
      \ logs to CloudWatch Logs\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/documentdb-controls.html#documentdb-4\"\
      \n    - name: \"[Neptune.2] Neptune DB clusters should publish audit logs to\
      \ CloudWatch Logs\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/neptune-controls.html#neptune-2\"\
      \n"
  - path: /ce/ca/aws/rds/cluster-cloudwatch-logs-export/prod.logic.yaml
    md5Hash: 8B39A9FEA4EB55B03252EDE96F96B3BE
    content: |-
      ---
      inputType: "CA10__CaAwsDbCluster__c"
      testData:
        - file: "test-data.json"
      importExtracts:
        - file: "/types/CA10__CaAwsDbCluster__c/object.extracts.yaml"
      conditions:
        - status: "COMPLIANT"
          currentStateMessage: "The RDS Cluster is configured to publish logs to CloudWatch."
          check:
            NOT_EMPTY:
              arg:
                EXTRACT: "CA10__enabledCloudwatchLogsExports__c"
      otherwise:
        status: "INCOMPLIANT"
        currentStateMessage: "The RDS Cluster is not configured to publish logs to CloudWatch."
        remediationMessage: "Modify the RDS Cluster to enable CloudWatch logs."
  - path: /ce/ca/aws/rds/cluster-cloudwatch-logs-export/test-data.json
    md5Hash: 0FE81297F1C26E0F9B4F04B178184567
    content: |-
      [
        {
          "expectedResult": {
            "runtimeError": null,
            "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
            "conditionIndex": 99,
            "status": "DISAPPEARED"
          },
          "context": {
            "snapshotTime": "2026-01-30T10:53:34Z"
          },
          "CA10__enabledCloudwatchLogsExports__c": "",
          "Id": "test1",
          "CA10__disappearanceTime__c": "2026-01-20T22:12:18Z"
        },
        {
          "expectedResult": {
            "runtimeError": null,
            "conditionText": "extract('CA10__enabledCloudwatchLogsExports__c').isNotEmpty()",
            "conditionIndex": 199,
            "status": "COMPLIANT"
          },
          "context": {
            "snapshotTime": "2026-01-30T10:53:34Z"
          },
          "CA10__enabledCloudwatchLogsExports__c": "postgresql",
          "Id": "test2",
          "CA10__disappearanceTime__c": null
        },
        {
          "expectedResult": {
            "runtimeError": null,
            "conditionText": "otherwise",
            "conditionIndex": 200,
            "status": "INCOMPLIANT"
          },
          "context": {
            "snapshotTime": "2026-01-30T10:53:34Z"
          },
          "CA10__enabledCloudwatchLogsExports__c": "",
          "Id": "test3",
          "CA10__disappearanceTime__c": null
        }
      ]
  - path: /types/CA10__CaAwsDbCluster__c/object.extracts.yaml
    md5Hash: D2C2C5F972AEC114F6BD57EB74FA57CB
    content: |
      ---
      extracts:
        - name: CA10__engine__c
          value:
            FIELD:
              path: CA10__engine__c
              undeterminedIf:
                # https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-clusters.html
                # "Engine" attribute represents a non-nullable string.
                isEmpty: DB Engine value cannot be empty. Potential data corruption.
      # Values: Yes | No. Not nullable. Cannot have no access, retrieved via rds:DescribeDBClusters
        - name: CA10__autoMinorVersionUpgrade__c
          value:
            FIELD:
              path: CA10__autoMinorVersionUpgrade__c
      # Checkbox.
        - name: CA10__multiAZ__c
          value:
            FIELD:
              path: CA10__multiAZ__c
      # Checkbox.
        - name: CA10__storageEncrypted__c
          value:
            FIELD:
              path: CA10__storageEncrypted__c
      # Text.
        - name: CA10__masterUsername__c
          value:
            FIELD:
              path: CA10__masterUsername__c
      # Checkbox.
        - name: CA10__iamDatabaseAuthenticationEnabled__c
          value:
            FIELD:
              path: CA10__iamDatabaseAuthenticationEnabled__c
        - name: CA10__status__c
          value:
            FIELD:
              path: CA10__status__c
              undeterminedIf:
                # https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-clusters.html
                # "Engine" attribute represents a non-nullable string.
                isEmpty: DB Status value cannot be empty. Potential data corruption.
      # Nullable. Can't have no access, retrieved via rds:DescribeDBClusters
        - name: CA10__enabledCloudwatchLogsExports__c
          value:
            FIELD:
              path: CA10__enabledCloudwatchLogsExports__c
      # Checkbox.
        - name: CA10__copyTagsToSnapshot__c
          value:
            FIELD:
              path: CA10__copyTagsToSnapshot__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" : {
      "runtimeError" : null,
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "conditionIndex" : 99,
      "status" : "DISAPPEARED"
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "runtimeError" : null,
      "conditionText" : "extract('CA10__enabledCloudwatchLogsExports__c').isNotEmpty()",
      "conditionIndex" : 199,
      "status" : "COMPLIANT"
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "runtimeError" : null,
      "conditionText" : "otherwise",
      "conditionIndex" : 200,
      "status" : "INCOMPLIANT"
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsDbCluster__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__enabledCloudwatchLogsExports__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2026-01-30T10:53:34Z")
    },
    "CA10__disappearanceTime__c" : new Date("2026-01-20T22:12:18Z"),
    "CA10__enabledCloudwatchLogsExports__c" : "",
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-30T10:53:34Z")
    },
    "CA10__enabledCloudwatchLogsExports__c" : "postgresql",
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-30T10:53:34Z")
    },
    "CA10__enabledCloudwatchLogsExports__c" : "",
    "Id" : "test3"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsDbCluster__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__enabledCloudwatchLogsExports__c 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 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__enabledCloudwatchLogsExports__c; } return this.out; };
      references1.push('Enabled CloudWatch Logs Exports [obj.CA10__enabledCloudwatchLogsExports__c]: ' + obj.CA10__enabledCloudwatchLogsExports__c);
      if (TextLib.isNotEmpty(extract3.call(extract3))) {
          return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__enabledCloudwatchLogsExports__c').isNotEmpty()", currentStateMessage: "The RDS Cluster is configured to publish logs to CloudWatch.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'INCOMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "The RDS Cluster is not configured to publish logs to CloudWatch.", currentStateReferences: references1.join('\n'), remediation: "Modify the RDS Cluster to enable CloudWatch logs.", 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__enabledCloudwatchLogsExports__c AS CA10__enabledCloudwatchLogsExports__c,
          sObject.Id AS Id,
          process_CA10__CaAwsDbCluster__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__enabledCloudwatchLogsExports__c AS CA10__enabledCloudwatchLogsExports__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsDbCluster__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
