---
policy: /ce/ca/aws/rds/cluster-auto-minor-version-upgrade
logic: /ce/ca/aws/rds/cluster-auto-minor-version-upgrade/prod.logic.yaml
executionTime: 2025-10-18T12:01:44.236564866Z
generationMs: 58
executionMs: 685
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: not(extract('CA10__multiAZ__c'))
      actual: not(extract('CA10__multiAZ__c'))
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__autoMinorVersionUpgrade__c') == 'No'
      actual: extract('CA10__autoMinorVersionUpgrade__c') == 'No'
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: extract('CA10__autoMinorVersionUpgrade__c') == 'Yes'
      actual: extract('CA10__autoMinorVersionUpgrade__c') == 'Yes'
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/rds/cluster-auto-minor-version-upgrade/policy.yaml
    md5Hash: 07C5FBC01B3533A55FF7A3A2FC7452D1
    content: |-
      ---
      names:
        full: "AWS RDS Multi-AZ Cluster Auto Minor Version Upgrade is not enabled"
        contextual: "Multi-AZ Cluster Auto Minor Version Upgrade is not enabled"
      description: "Ensure that RDS Multi-AZ database clusters have the Auto Minor Version Upgrade\
        \ flag enabled in order to receive automatically minor engine upgrades, including\
        \ security patches and bug fixes."
      type: COMPLIANCE_POLICY
      categories:
        - "SECURITY"
        - "RELIABILITY"
        - "PERFORMANCE"
      frameworkMappings:
        - "/frameworks/cloudaware/resource-reliability/infrastructure-modernization"
        - "/frameworks/aws-fsbp-v1.0.0/rds/35"
        - "/frameworks/aws-well-architected/ops/05/05"
      similarPolicies:
        awsSecurityHub:
          - name: "[RDS.35] RDS DB clusters should have automatic minor version upgrade enabled"
            url: "https://docs.aws.amazon.com/securityhub/latest/userguide/rds-controls.html#rds-35"
  - path: /ce/ca/aws/rds/cluster-auto-minor-version-upgrade/prod.logic.yaml
    md5Hash: 7FC42C32D909A23DE529FC9DF1733D8C
    content: "---\ninputType: \"CA10__CaAwsDbCluster__c\"\ntestData:\n  - file: test-data.json\n\
      importExtracts:\n  - file: /types/CA10__CaAwsDbCluster__c/object.extracts.yaml\n\
      conditions:\n  - status: \"INAPPLICABLE\"\n    currentStateMessage: \"This policy\
      \ applies only to Multi-AZ RDS clusters.\"\n    check: \n      NOT:\n      \
      \  arg:\n          EXTRACT: CA10__multiAZ__c # multiAZ != true\n  - status:\
      \ \"INCOMPLIANT\"\n    currentStateMessage: \"The Cluster's Auto Minor Version\
      \ Upgrade feature is not enabled.\"\n    remediationMessage: \"Enable the Auto\
      \ Minor Version Upgrade feature for the Cluster.\"\n    check: \n      IS_EQUAL:\n\
      \        left:\n          EXTRACT: CA10__autoMinorVersionUpgrade__c\n      \
      \  right:\n          TEXT: \"No\" \n  - status: \"COMPLIANT\"\n    currentStateMessage:\
      \ \"The Cluster's Auto Minor Version Upgrade feature is enabled.\"\n    check:\
      \ \n      IS_EQUAL:\n        left:\n          EXTRACT: CA10__autoMinorVersionUpgrade__c\n\
      \        right:\n          TEXT: \"Yes\" \notherwise:\n  status: \"UNDETERMINED\"\
      \n  currentStateMessage: \"Unexpected values in the field.\"\n"
  - path: /ce/ca/aws/rds/cluster-auto-minor-version-upgrade/test-data.json
    md5Hash: 1AE1CADA77322568BE73F4FAD801DACE
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-09T10:02:45Z"
              },
              "CA10__disappearanceTime__c": "2025-10-09T10:02:45Z",
              "CA10__multiAZ__c": false,
              "CA10__autoMinorVersionUpgrade__c": "Yes",
              "Id": "test1"
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "not(extract('CA10__multiAZ__c'))",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-09T10:02:45Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__multiAZ__c": false,
              "CA10__autoMinorVersionUpgrade__c": "Yes",
              "Id": "test2"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "extract('CA10__autoMinorVersionUpgrade__c') == 'No'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-09T10:02:45Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__multiAZ__c": true,
              "CA10__autoMinorVersionUpgrade__c": "No",
              "Id": "test3"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "399",
                  "conditionText": "extract('CA10__autoMinorVersionUpgrade__c') == 'Yes'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-09T10:02:45Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__multiAZ__c": true,
              "CA10__autoMinorVersionUpgrade__c": "Yes",
              "Id": "test4"
          }
      ]
  - path: /types/CA10__CaAwsDbCluster__c/object.extracts.yaml
    md5Hash: 67D56565AC3D5D186C8D23A35271C8EB
    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
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" : "not(extract('CA10__multiAZ__c'))",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__autoMinorVersionUpgrade__c') == 'No'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "extract('CA10__autoMinorVersionUpgrade__c') == 'Yes'",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsDbCluster__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__multiAZ__c BOOLEAN,
      CA10__autoMinorVersionUpgrade__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-10-09T10:02:45Z")
    },
    "CA10__disappearanceTime__c" : new Date("2025-10-09T10:02:45Z"),
    "CA10__multiAZ__c" : false,
    "CA10__autoMinorVersionUpgrade__c" : "Yes",
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-09T10:02:45Z")
    },
    "CA10__multiAZ__c" : false,
    "CA10__autoMinorVersionUpgrade__c" : "Yes",
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-09T10:02:45Z")
    },
    "CA10__multiAZ__c" : true,
    "CA10__autoMinorVersionUpgrade__c" : "No",
    "Id" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-09T10:02:45Z")
    },
    "CA10__multiAZ__c" : true,
    "CA10__autoMinorVersionUpgrade__c" : "Yes",
    "Id" : "test4"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsDbCluster__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__multiAZ__c BOOLEAN,
          CA10__autoMinorVersionUpgrade__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__multiAZ__c; } return this.out; };
      references1.push('Multi AZ [obj.CA10__multiAZ__c]: ' + obj.CA10__multiAZ__c);
      if (!extract3.call(extract3)) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "not(extract('CA10__multiAZ__c'))", currentStateMessage: "This policy applies only to Multi-AZ RDS clusters.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10__autoMinorVersionUpgrade__c; } return this.out; };
      references1.push('Auto Minor Version Upgrade [obj.CA10__autoMinorVersionUpgrade__c]: ' + obj.CA10__autoMinorVersionUpgrade__c);
      if (TextLib.equal(extract6.call(extract6), 'No')) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__autoMinorVersionUpgrade__c') == 'No'", currentStateMessage: "The Cluster's Auto Minor Version Upgrade feature is not enabled.", currentStateReferences: references1.join('\n'), remediation: "Enable the Auto Minor Version Upgrade feature for the Cluster.", runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      function extract9() { if (!this.out) { this.out = obj.CA10__autoMinorVersionUpgrade__c; } return this.out; };
      if (TextLib.equal(extract9.call(extract9), 'Yes')) {
          return {status: 'COMPLIANT', conditionIndex: 399, conditionText: "extract('CA10__autoMinorVersionUpgrade__c') == 'Yes'", currentStateMessage: "The Cluster's Auto Minor Version Upgrade feature 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__multiAZ__c AS CA10__multiAZ__c,
          sObject.CA10__autoMinorVersionUpgrade__c AS CA10__autoMinorVersionUpgrade__c,
          sObject.Id AS Id,
          process_CA10__CaAwsDbCluster__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__multiAZ__c AS CA10__multiAZ__c,
                  sObject.CA10__autoMinorVersionUpgrade__c AS CA10__autoMinorVersionUpgrade__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsDbCluster__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
