---
policy: /ce/ca/aws/opensearch/domain-software-update
logic: /ce/ca/aws/opensearch/domain-software-update/prod.logic.yaml
executionTime: 2025-11-17T14:33:41.110780387Z
generationMs: 80
executionMs: 764
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: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__serviceSoftwareUpdateAvailable__c') == 'false'
      actual: extract('CA10__serviceSoftwareUpdateAvailable__c') == 'false'
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__serviceSoftwareUpdateAvailable__c') == 'true'
      actual: extract('CA10__serviceSoftwareUpdateAvailable__c') == 'true'
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/opensearch/domain-software-update/policy.yaml
    md5Hash: A05701721BA1162EB76BB151587C9D83
    content: "---\nnames:\n  full: \"AWS OpenSearch Domain latest Service Software\
      \ Update is not installed\"\n  contextual: \"Domain latest Service Software\
      \ Update is not installed\"\ndescription: >\n  Ensure that Amazon OpenSearch\
      \ Domains are running the latest compatible service \n  software update to benefit\
      \ from the latest security patches, bug fixes, and \n  performance improvements.\n\
      type: \"COMPLIANCE_POLICY\"\ncategories:\n  - \"RELIABILITY\"\nframeworkMappings:\n\
      \  - \"/frameworks/cloudaware/resource-reliability/infrastructure-modernization\"\
      \n  - \"/frameworks/aws-well-architected/sec/06/01\"\nsimilarPolicies:\n  awsSecurityHub:\n\
      \    - name: \"[Opensearch.10] OpenSearch domains should have the latest software\
      \ update installed\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/opensearch-controls.html#opensearch-10\"\
      \n"
  - path: /ce/ca/aws/opensearch/domain-software-update/prod.logic.yaml
    md5Hash: 2EA3993449534D0A26352F3CA3227D90
    content: |-
      ---
      inputType: "CA10__CaAwsElasticsearchDomain__c"
      testData:
        - file: "test-data.json"
      importExtracts:
        - file: "/types/CA10__CaAwsElasticsearchDomain__c/object.extracts.yaml"
      conditions:
        - status: "INCOMPLIANT"
          currentStateMessage: "A new service software update is available for the OpenSearch domain."
          remediationMessage: "Consider installing the latest compatible service software\
            \ update for the OpenSearch domain to get the latest features, security patches, and bug fixes."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__serviceSoftwareUpdateAvailable__c"
              right:
                TEXT: "false"
        - status: "COMPLIANT"
          currentStateMessage: "The OpenSearch domain is running the latest service software version."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__serviceSoftwareUpdateAvailable__c"
              right:
                TEXT: "true"
      otherwise:
        status: "UNDETERMINED"
        currentStateMessage: "Unexpected values in the field."
  - path: /ce/ca/aws/opensearch/domain-software-update/test-data.json
    md5Hash: 313F1EBFF1D8ECB7D3EDA231F025D597
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-29T06:46:08Z"
              },
              "CA10__disappearanceTime__c": "2025-08-17T07:38:43Z",
              "CA10__serviceSoftwareUpdateAvailable__c": "true",
              "Id": "test1"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__serviceSoftwareUpdateAvailable__c') == 'false'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-29T06:46:08Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__serviceSoftwareUpdateAvailable__c": "false",
              "Id": "test2"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "extract('CA10__serviceSoftwareUpdateAvailable__c') == 'true'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-29T06:46:08Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__serviceSoftwareUpdateAvailable__c": "true",
              "Id": "test3"
          }
      ]
  - path: /types/CA10__CaAwsElasticsearchDomain__c/object.extracts.yaml
    md5Hash: C072626C7FFF5273DA4B104B530A027E
    content: |
      ---
      extracts:
      # Values: true | false (TEXT). Not nullable. Can't have no access retrieved via es:DescribeDomains
        - name: "CA10__serviceSoftwareUpdateAvailable__c"
          value:
            FIELD:
              path: "CA10__serviceSoftwareUpdateAvailable__c"
      # Checkbox
        - name: "CA10__encryptionAtRestEnabled__c"
          value:
            FIELD:
              path: "CA10__encryptionAtRestEnabled__c"
      # Nullable. Can't have no access retrieved via es:DescribeDomains
        - name: "CA10__endpoint__c"
          value:
            FIELD:
              path: "CA10__endpoint__c"
      # Nullable. Can't have no access retrieved via es:DescribeDomains
        - name: "CA10__vpcEndpoints__c"
          value:
            FIELD:
              path: "CA10__vpcEndpoints__c"
      # Checkbox
        - name: "CA10__nodeToNodeEncryptionEnabled__c"
          value:
            FIELD:
              path: "CA10__nodeToNodeEncryptionEnabled__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" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__serviceSoftwareUpdateAvailable__c') == 'false'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__serviceSoftwareUpdateAvailable__c') == 'true'",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsElasticsearchDomain__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__serviceSoftwareUpdateAvailable__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-10-29T06:46:08Z")
    },
    "CA10__disappearanceTime__c" : new Date("2025-08-17T07:38:43Z"),
    "CA10__serviceSoftwareUpdateAvailable__c" : "true",
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-29T06:46:08Z")
    },
    "CA10__serviceSoftwareUpdateAvailable__c" : "false",
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-29T06:46:08Z")
    },
    "CA10__serviceSoftwareUpdateAvailable__c" : "true",
    "Id" : "test3"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsElasticsearchDomain__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__serviceSoftwareUpdateAvailable__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__serviceSoftwareUpdateAvailable__c; } return this.out; };
      references1.push('Service Software: Update Available [obj.CA10__serviceSoftwareUpdateAvailable__c]: ' + obj.CA10__serviceSoftwareUpdateAvailable__c);
      if (TextLib.equal(extract3.call(extract3), 'false')) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__serviceSoftwareUpdateAvailable__c') == 'false'", currentStateMessage: "A new service software update is available for the OpenSearch domain.", currentStateReferences: references1.join('\n'), remediation: "Consider installing the latest compatible service software update for the OpenSearch domain to get the latest features, security patches, and bug fixes.", runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10__serviceSoftwareUpdateAvailable__c; } return this.out; };
      if (TextLib.equal(extract6.call(extract6), 'true')) {
          return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__serviceSoftwareUpdateAvailable__c') == 'true'", currentStateMessage: "The OpenSearch domain is running the latest service software version.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'UNDETERMINED', conditionIndex: 300, 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__serviceSoftwareUpdateAvailable__c AS CA10__serviceSoftwareUpdateAvailable__c,
          sObject.Id AS Id,
          process_CA10__CaAwsElasticsearchDomain__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__serviceSoftwareUpdateAvailable__c AS CA10__serviceSoftwareUpdateAvailable__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsElasticsearchDomain__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
