---
policy: /ce/ca/aws/elasticache/redis-cluster-auto-minor-version-upgrade
logic: /ce/ca/aws/elasticache/redis-cluster-auto-minor-version-upgrade/prod.logic.yaml
executionTime: 2025-10-08T17:39:17.272658712Z
generationMs: 55
executionMs: 581
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: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: not(extract('CA10__autoMinorVersionUpgrade__c'))
      actual: not(extract('CA10__autoMinorVersionUpgrade__c'))
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__engine__c') != 'redis'
      actual: extract('CA10__engine__c') != 'redis'
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/elasticache/redis-cluster-auto-minor-version-upgrade/policy.yaml
    md5Hash: 4AF4381E789301B060D70A0282891B57
    content: "---\nnames:\n  full: \"AWS ElastiCache Redis Cluster Auto Minor Version\
      \ Upgrade is not enabled\"\n  contextual: \"Redis Cluster Auto Minor Version\
      \ Upgrade is not enabled\"\ndescription: >\n  Ensure that ElastiCache Redis\
      \ clusters have the Auto Minor Version Upgrade flag enabled \n  in order to\
      \ receive automatically minor engine upgrades during the specified \n  maintenance\
      \ window.\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n  - \"RELIABILITY\"\nframeworkMappings:\n\
      \  - \"/frameworks/cloudaware/resource-reliability/infrastructure-modernization\"\
      \n  - \"/frameworks/aws-well-architected/operational-excellence/prepare/ops05/bp05\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/elasticache/02\""
  - path: /ce/ca/aws/elasticache/redis-cluster-auto-minor-version-upgrade/prod.logic.yaml
    md5Hash: 0442D415109CB2B83EEE20FB499C9FC4
    content: "---\ninputType: \"CA10__CaAwsCacheCluster__c\"\ntestData:\n  - file:\
      \ \"test-data.json\"\nimportExtracts:\n  - file: /types/CA10__CaAwsCacheCluster__c/object.extracts.yaml\n\
      conditions:\n  - status: \"INAPPLICABLE\"\n    currentStateMessage: \"The policy\
      \ only applicable to Redis Clusters.\"\n    check:\n      NOT_EQUAL:\n     \
      \   left:\n          EXTRACT: \"CA10__engine__c\"\n        right:\n        \
      \  TEXT: \"redis\"\n  - status: \"INCOMPLIANT\"\n    currentStateMessage: \"\
      ElastiCache Cluster Auto Minor Version Upgrade is not enabled.\"\n    remediationMessage:\
      \ \"Consider enabling Auto Minor Version Upgrade for this ElastiCache Cluster.\"\
      \    \n    check: \n      NOT:\n        arg:\n          EXTRACT: CA10__autoMinorVersionUpgrade__c\
      \ # autoMinorVersionUpgrade != true\notherwise:\n  status: \"COMPLIANT\"\n \
      \ currentStateMessage: \"ElastiCache Cluster Auto Minor Version Upgrade is enabled.\"\
      \n"
  - path: /ce/ca/aws/elasticache/redis-cluster-auto-minor-version-upgrade/test-data.json
    md5Hash: 14AF5E88E707B1F1E7BFF59D84013771
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-08T06:14:51Z"
              },
              "CA10__disappearanceTime__c": "2025-08-15T02:22:45Z",
              "CA10__engine__c": "redis",
              "CA10__autoMinorVersionUpgrade__c": true,
              "Id": "test1"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "300",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-08T06:14:51Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__engine__c": "redis",
              "CA10__autoMinorVersionUpgrade__c": true,
              "Id": "test2"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "not(extract('CA10__autoMinorVersionUpgrade__c'))",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-08T06:14:51Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__engine__c": "redis",
              "CA10__autoMinorVersionUpgrade__c": false,
              "Id": "test3"
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__engine__c') != 'redis'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-08T06:14:51Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__engine__c": "memcached",
              "CA10__autoMinorVersionUpgrade__c": false,
              "Id": "test4"
          }
      ]
  - path: /types/CA10__CaAwsCacheCluster__c/object.extracts.yaml
    md5Hash: 6B61F326DFF0C571F189D09F6614B172
    content: "---\nextracts:\n# Values: available, creating, deleted, deleting, incompatible-network,\
      \ modifying, \n# rebooting cluster nodes, restore-failed, snapshotting\n# Not\
      \ nullable. Can't have no access, retrieved via elasticache:DescribeCacheClusters\n\
      \  - name: \"CA10__status__c\"\n    value:\n      FIELD:\n        path: \"CA10__status__c\"\
      \n        undeterminedIf:\n          isEmpty: \"Corrupted data. Status cannot\
      \ be empty.\" \n# Values: memcached | redis. Not nullable. Can't have no access,\
      \ retrieved via elasticache:DescribeCacheClusters\n  - name: \"CA10__engine__c\"\
      \n    value:\n      FIELD:\n        path: \"CA10__engine__c\"\n        undeterminedIf:\n\
      \          isEmpty: \"Corrupted data. Engine cannot be empty.\"\n# Date/Time\n\
      \  - name: \"CA10__createTime__c\"\n    value:\n      FIELD:\n        path:\
      \ \"CA10__createTime__c\"\n# Percent\n  - name: \"CA10__cpuUtilizationAvg30d__c\"\
      \n    value:\n      FIELD:\n        path: \"CA10__cpuUtilizationAvg30d__c\"\n\
      # Checkbox. Can't have no access, retrieved via elasticache:DescribeCacheClusters\n\
      \  - name: \"CA10__autoMinorVersionUpgrade__c\"\n    value:\n      FIELD:\n\
      \        path: \"CA10__autoMinorVersionUpgrade__c\"\n"
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" : "COMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "not(extract('CA10__autoMinorVersionUpgrade__c'))",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__engine__c') != 'redis'",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsCacheCluster__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__engine__c STRING,
      CA10__autoMinorVersionUpgrade__c BOOLEAN,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-10-08T06:14:51Z")
    },
    "CA10__disappearanceTime__c" : new Date("2025-08-15T02:22:45Z"),
    "CA10__engine__c" : "redis",
    "CA10__autoMinorVersionUpgrade__c" : true,
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-08T06:14:51Z")
    },
    "CA10__engine__c" : "redis",
    "CA10__autoMinorVersionUpgrade__c" : true,
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-08T06:14:51Z")
    },
    "CA10__engine__c" : "redis",
    "CA10__autoMinorVersionUpgrade__c" : false,
    "Id" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-08T06:14:51Z")
    },
    "CA10__engine__c" : "memcached",
    "CA10__autoMinorVersionUpgrade__c" : false,
    "Id" : "test4"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsCacheCluster__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__engine__c STRING,
          CA10__autoMinorVersionUpgrade__c BOOLEAN,
          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 fieldChecked4() {
          if (TextLib.isEmpty(obj.CA10__engine__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__engine__c.isEmpty()", currentStateMessage: "Corrupted data. Engine cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__engine__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Engine [obj.CA10__engine__c]: ' + obj.CA10__engine__c);
      try {
          if (TextLib.notEqual(extract3.call(extract3), 'redis')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__engine__c') != 'redis'", currentStateMessage: "The policy only applicable to Redis Clusters.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // 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 (!extract6.call(extract6)) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "not(extract('CA10__autoMinorVersionUpgrade__c'))", currentStateMessage: "ElastiCache Cluster Auto Minor Version Upgrade is not enabled.", currentStateReferences: references1.join('\n'), remediation: "Consider enabling Auto Minor Version Upgrade for this ElastiCache Cluster.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "ElastiCache Cluster Auto Minor Version Upgrade is 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__engine__c AS CA10__engine__c,
          sObject.CA10__autoMinorVersionUpgrade__c AS CA10__autoMinorVersionUpgrade__c,
          sObject.Id AS Id,
          process_CA10__CaAwsCacheCluster__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__engine__c AS CA10__engine__c,
                  sObject.CA10__autoMinorVersionUpgrade__c AS CA10__autoMinorVersionUpgrade__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsCacheCluster__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
