---
policy: /ce/ca/aws/redshift/cluster-version-upgrade
logic: /ce/ca/aws/redshift/cluster-version-upgrade/prod.logic.yaml
executionTime: 2026-01-31T12:02:17.513588089Z
generationMs: 78
executionMs: 905
rows:
  - id: '001'
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__status__c') != 'available'
      actual: extract('CA10__status__c') != 'available'
    runtimeError: {}
  - id: '002'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__versionUpgrade__c') == 'Allowed'
      actual: extract('CA10__versionUpgrade__c') == 'Allowed'
    runtimeError: {}
  - id: '003'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/redshift/cluster-version-upgrade/policy.yaml
    md5Hash: 9364865079B6942746E4E2E9E7804CB1
    content: "---\nnames:\n  full: \"AWS Redshift Cluster automatic major version\
      \ upgrade is not enabled\"\n  contextual: \"Cluster automatic major version\
      \ upgrade is not enabled\"\ndescription: >\n  Ensure that Amazon Redshift clusters\
      \ have the version upgrade feature enabled. \n  This allows the cluster to automatically\
      \ receive major engine upgrades, including \n  performance improvements and\
      \ new features, during its maintenance window.\ntype: \"COMPLIANCE_POLICY\"\n\
      categories:\n  - \"RELIABILITY\"\nframeworkMappings:\n  - \"/frameworks/cloudaware/resource-reliability/infrastructure-modernization\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/redshift/06\"\nsimilarPolicies:\n  awsSecurityHub:\n\
      \    - name: \"[Redshift.6] Amazon Redshift should have automatic upgrades to\
      \ major versions enabled\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/redshift-controls.html#redshift-6\"\
      \n  cloudConformity:\n    - url: \"http://trendmicro.com/cloudoneconformity/knowledge-base/aws/Redshift/redshift-cluster-allow-version-upgrade.html\"\
      \n      name: Redshift Cluster Allow Version Upgrade"
  - path: /ce/ca/aws/redshift/cluster-version-upgrade/prod.logic.yaml
    md5Hash: B7DA0EDF88E6A095DF3305B89F023E40
    content: |-
      ---
      inputType: "CA10__CaAwsRedshiftCluster__c"
      importExtracts:
        - file: "/types/CA10__CaAwsRedshiftCluster__c/object.extracts.yaml"
      testData:
        - file: "test-data.json"
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "The Cluster is not available."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10__status__c"
              right:
                TEXT: "available"
        - status: "COMPLIANT"
          currentStateMessage: "The Redshift Cluster Version Upgrade is enabled."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__versionUpgrade__c"
              right:
                TEXT: "Allowed"
      otherwise:
        status: "INCOMPLIANT"
        currentStateMessage: "The Redshift Cluster Version Upgrade is not enabled."
        remediationMessage: "Consider enabling Version Upgrade for the Cluster."
  - path: /ce/ca/aws/redshift/cluster-version-upgrade/test-data.json
    md5Hash: DDF4F7FD258A8370470CB54BCEB53E93
    content: |
      [
          {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "199",
            "conditionText": "extract('CA10__status__c') != 'available'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2026-01-13T09:41:32Z" },
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "paused",
          "CA10__versionUpgrade__c": "Allowed",
          "Id": "001"
          },
          {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "299",
            "conditionText": "extract('CA10__versionUpgrade__c') == 'Allowed'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2026-01-13T05:10:00Z" },
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "available",
          "CA10__versionUpgrade__c": "Allowed",
          "Id": "002"
          },
          {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "300",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2026-01-13T05:10:00Z" },
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "available",
          "CA10__versionUpgrade__c": null,
          "Id": "003"
          }
      ]
  - path: /types/CA10__CaAwsRedshiftCluster__c/object.extracts.yaml
    md5Hash: DBF4D0413CB4EF01D13D17E4ED636EC5
    content: |
      ---
      extracts:
      # Nullable. Values: available, modifying, creating ...
        - name: "CA10__status__c"
          value:
            FIELD:
              path: "CA10__status__c"
      # Nullable.
        - name: "CA10__createTime__c"
          value:
            FIELD:
              path: "CA10__createTime__c"
      # Nullable.
        - name: "CA10__cpuUtilizationAvg30d__c"
          value:
            FIELD:
              path: "CA10__cpuUtilizationAvg30d__c"
      # Nullable.
        - name: "CA10__diskReadIopsAvg30d__c"
          value:
            FIELD:
              path: "CA10__diskReadIopsAvg30d__c"
      # Nullable.
        - name: "CA10__diskWriteIopsAvg30d__c"
          value:
            FIELD:
              path: "CA10__diskWriteIopsAvg30d__c"
      # Nullable.
        - name: "CA10__logging__c"
          value:
            FIELD:
              path: "CA10__logging__c"
      # Nullable.
        - name: "CA10__automatedSnapshotRetentionPeriod__c"
          value:
            FIELD:
              path: "CA10__automatedSnapshotRetentionPeriod__c"
      # Text.
        - name: "CA10__encryption__c"
          value:
            FIELD:
              path: "CA10__encryption__c"
      # Text.
        - name: "CA10__masterUsername__c"
          value:
            FIELD:
              path: "CA10__masterUsername__c"
      # Text.
        - name: "CA10__versionUpgrade__c"
          value:
            FIELD:
              path: "CA10__versionUpgrade__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" : "001",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__status__c') != 'available'",
      "runtimeError" : null
    }
  }, {
    "Id" : "002",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__versionUpgrade__c') == 'Allowed'",
      "runtimeError" : null
    }
  }, {
    "Id" : "003",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsRedshiftCluster__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__status__c STRING,
      CA10__versionUpgrade__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2026-01-13T09:41:32Z")
    },
    "CA10__status__c" : "paused",
    "CA10__versionUpgrade__c" : "Allowed",
    "Id" : "001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-13T05:10:00Z")
    },
    "CA10__status__c" : "available",
    "CA10__versionUpgrade__c" : "Allowed",
    "Id" : "002"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-13T05:10:00Z")
    },
    "CA10__status__c" : "available",
    "CA10__versionUpgrade__c" : null,
    "Id" : "003"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsRedshiftCluster__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__status__c STRING,
          CA10__versionUpgrade__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__status__c; } return this.out; };
      references1.push('Status [obj.CA10__status__c]: ' + obj.CA10__status__c);
      if (TextLib.notEqual(extract3.call(extract3), 'available')) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__status__c') != 'available'", currentStateMessage: "The Cluster is not available.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10__versionUpgrade__c; } return this.out; };
      references1.push('Version Upgrade [obj.CA10__versionUpgrade__c]: ' + obj.CA10__versionUpgrade__c);
      if (TextLib.equal(extract6.call(extract6), 'Allowed')) {
          return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__versionUpgrade__c') == 'Allowed'", currentStateMessage: "The Redshift Cluster Version Upgrade is enabled.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'INCOMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "The Redshift Cluster Version Upgrade is not enabled.", currentStateReferences: references1.join('\n'), remediation: "Consider enabling Version Upgrade for the Cluster.", 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.CA10__versionUpgrade__c AS CA10__versionUpgrade__c,
          sObject.Id AS Id,
          process_CA10__CaAwsRedshiftCluster__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__status__c AS CA10__status__c,
                  sObject.CA10__versionUpgrade__c AS CA10__versionUpgrade__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsRedshiftCluster__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
