---
policy: /ce/ca/aws/rds/instance-auto-minor-version-upgrade
logic: /ce/ca/aws/rds/instance-auto-minor-version-upgrade/prod.logic.yaml
executionTime: 2025-04-24T23:45:02.306927275Z
rows:
  - id: a01
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__autoMinorVersionUpgrade__c') == true
      actual: extract('CA10__autoMinorVersionUpgrade__c') == true
    runtimeError: {}
  - id: a02
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/rds/instance-auto-minor-version-upgrade/policy.yaml
    md5Hash: 50FFA099653F127CB62C85EDA7BFAB8C
    content: |
      ---
      names:
        full: AWS RDS Instance Auto Minor Version Upgrade is not enabled
        contextual: Instance Auto Minor Version Upgrade is not enabled
      description: "Ensure that RDS database instances have the Auto Minor Version Upgrade\
        \ flag enabled in order to receive automatically minor engine upgrades during the\
        \ specified maintenance window. So, RDS instances can get the new features, bug\
        \ fixes, and security patches for their database engines."
      type: COMPLIANCE_POLICY
      categories:
        - SECURITY
        - RELIABILITY
        - PERFORMANCE
      frameworkMappings:
        - "/frameworks/cis-aws-v5.0.0/02/02/02"
        - "/frameworks/cloudaware/resource-reliability/infrastructure-modernization"
        - "/frameworks/aws-fsbp-v1.0.0/rds/13"
      similarPolicies:
        internal:
          - dec-x-215302da
        cloudConformity:
          - url: https://www.trendmicro.com/cloudoneconformity/knowledge-base/aws/RDS/rds-auto-minor-version-upgrade.html
            name: RDS Auto Minor Version Upgrade
  - path: /ce/ca/aws/rds/instance-auto-minor-version-upgrade/prod.logic.yaml
    md5Hash: 64565887D18E08A1CC831FBCF2BB234B
    content: "---\ninputType: \"CA10__CaAwsDbInstance__c\"\ntestData:\n  - file: test-data.json\n\
      importExtracts:\n  - file: /types/CA10__CaAwsDbInstance__c/object.extracts.yaml\n\
      conditions:\n  - status: \"COMPLIANT\"\n    currentStateMessage: \"RDS Instance\
      \ Auto Minor Version Upgrade feature is enabled.\"\n    check: \n      IS_EQUAL:\n\
      \        left:\n          EXTRACT: CA10__autoMinorVersionUpgrade__c\n      \
      \  right:\n          BOOLEAN: true \notherwise:\n  status: \"INCOMPLIANT\"\n\
      \  currentStateMessage: \"RDS Instance Auto Minor Version Upgrade feature is\
      \ disabled.\"\n  remediationMessage: \"Enable Auto Minor Version Upgrade feature\
      \ for this RDS Instance.\"\n"
  - path: /ce/ca/aws/rds/instance-auto-minor-version-upgrade/test-data.json
    md5Hash: 542738EC78F854A99BE85A2EC3EEAC97
    content: |
      [
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "199",
            "conditionText": "extract('CA10__autoMinorVersionUpgrade__c') == true",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-06-04T19:44:50Z" },
          "Id": "a01",
          "CA10__disappearanceTime__c": null,
          "CA10__autoMinorVersionUpgrade__c": true
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-06-04T19:44:50Z" },
          "Id": "a02",
          "CA10__disappearanceTime__c": null,
          "CA10__autoMinorVersionUpgrade__c": false
        }
      ]
  - path: /types/CA10__CaAwsDbInstance__c/object.extracts.yaml
    md5Hash: FF9B20D94B2A03C8B9A5C755DC5EF3A9
    content: "---\nextracts:\n# Not Nullable. Can't have no access, retrieved via\
      \ rds:DescribeDBInstances\n  - name: CA10__engine__c\n    value:\n      FIELD:\n\
      \        path: CA10__engine__c\n        undeterminedIf:\n          isEmpty:\
      \ \"Corrupted data. DB Instance Engine cannot be empty.\"\n# Not Nullable. Can't\
      \ have no access, retrieved via rds:DescribeDBInstances\n  - name: CA10__endpointPort__c\n\
      \    value:\n      FIELD:\n        path: CA10__endpointPort__c\n        undeterminedIf:\n\
      \          isEmpty: \"Corrupted data. DB Endpoint Port cannot be empty.\"\n\
      # Checkbox. Can't have no access, retrieved via rds:DescribeDBInstances\n  -\
      \ name: CA10__publiclyAccessible__c\n    value:\n      FIELD:\n        path:\
      \ CA10__publiclyAccessible__c\n# Checkbox. Can't have no access, retrieved via\
      \ rds:DescribeDBInstances\n  - name: CA10__storageEncrypted__c\n    value: \n\
      \      FIELD:\n        path: CA10__storageEncrypted__c\n# Checkbox. Can't have\
      \ no access, retrieved via rds:DescribeDBInstances\n  - name: CA10__autoMinorVersionUpgrade__c\n\
      \    value: \n      FIELD:\n        path: CA10__autoMinorVersionUpgrade__c\n\
      # Checkbox. Can't have no access, retrieved via rds:DescribeDBInstances\n  -\
      \ name: CA10__multiAz__c\n    value: \n      FIELD:\n        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" : "a01",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__autoMinorVersionUpgrade__c') == true",
      "runtimeError" : null
    }
  }, {
    "Id" : "a02",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsDbInstance__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__autoMinorVersionUpgrade__c BOOLEAN,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-06-04T19:44:50Z")
    },
    "Id" : "a01",
    "CA10__autoMinorVersionUpgrade__c" : true
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-04T19:44:50Z")
    },
    "Id" : "a02",
    "CA10__autoMinorVersionUpgrade__c" : false
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsDbInstance__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__autoMinorVersionUpgrade__c BOOLEAN
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
      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__autoMinorVersionUpgrade__c; } return this.out; };
      references1.push('Auto Minor Version Upgrade [obj.CA10__autoMinorVersionUpgrade__c]: ' + obj.CA10__autoMinorVersionUpgrade__c);
      if (extract3.call(extract3) == true) {
          return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__autoMinorVersionUpgrade__c') == true", currentStateMessage: "RDS Instance Auto Minor Version Upgrade feature is enabled.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'INCOMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "RDS Instance Auto Minor Version Upgrade feature is disabled.", currentStateReferences: references1.join('\n'), remediation: "Enable Auto Minor Version Upgrade feature for this RDS Instance.", 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__autoMinorVersionUpgrade__c AS CA10__autoMinorVersionUpgrade__c,
          process_CA10__CaAwsDbInstance__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__autoMinorVersionUpgrade__c AS CA10__autoMinorVersionUpgrade__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsDbInstance__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
