---
policy: /ce/ca/aws/data-sync/task-logging
logic: /ce/ca/aws/data-sync/task-logging/prod.logic.yaml
executionTime: 2025-07-21T17:35:51.124508549Z
rows:
  - id: test1
    match: true
    status:
      expected: DISAPPEARED
      actual: DISAPPEARED
    conditionIndex:
      expected: 99
      actual: 99
    conditionText:
      expected: isDisappeared(CA10A1__disappearanceTime__c)
      actual: isDisappeared(CA10A1__disappearanceTime__c)
    runtimeError: {}
  - id: test2
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: isEmptyLookup('CA10A1__cloudWatchLogGroup__r')
      actual: isEmptyLookup('CA10A1__cloudWatchLogGroup__r')
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: isEmptyLookup('CA10A1__cloudWatchLogGroup__r')
      actual: isEmptyLookup('CA10A1__cloudWatchLogGroup__r')
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test5
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10A1__cloudWatchLogGroupArn__c').isEmpty()
      actual: extract('CA10A1__cloudWatchLogGroupArn__c').isEmpty()
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/data-sync/task-logging/policy.yaml
    md5Hash: 234DC6D9FBCB29AFC5362CF648409BE0
    content: "---\nnames:\n  full: AWS Data Sync Task logging is not enabled\n  contextual:\
      \ Task logging is not enabled\ndescription: >\n  Ensure that AWS DataSync task\
      \ logging is enabled to capture detailed information \n  about task executions,\
      \ data transfers, and potential errors in Amazon CloudWatch Logs.\ntype: COMPLIANCE_POLICY\n\
      categories:\n  - SECURITY\nframeworkMappings:\n  - \"/frameworks/cloudaware/logging-and-monitoring/logging-and-monitoring-configuration\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/datasync/01\"\nsimilarPolicies:\n  awsSecurityHub:\n\
      \    - name: \"[DataSync.1] DataSync tasks should have logging enabled\"\n \
      \     url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/datasync-controls.html#datasync-1\"\
      \n"
  - path: /ce/ca/aws/data-sync/task-logging/prod.logic.yaml
    md5Hash: CAD87DA260D7F275699BD91FE9E95B6C
    content: "---\ninputType: \"CA10A1__CaAwsDataSyncTask__c\"\nimportExtracts:\n\
      \  - file: /types/CA10A1__CaAwsDataSyncTask__c/object.extracts.yaml\ntestData:\n\
      \  - file: \"test-data.json\"\nconditions:\n  - status: \"INCOMPLIANT\"\n  \
      \  currentStateMessage: \"DataSync Task logging is not enabled.\"\n    remediationMessage:\
      \ \"Consider configuring a CloudWatch Log Group for the DataSync Task.\"\n \
      \   check:\n      IS_EMPTY: \n        arg:\n          EXTRACT: \"CA10A1__cloudWatchLogGroupArn__c\"\
      \n  - status: \"INCOMPLIANT\"\n    currentStateMessage: \"DataSync Task logging\
      \ has been deleted or does not exist in the CMDB.\"\n    remediationMessage:\
      \ \"Confirm that CloudWatch Log Group for the DataSync Task is configured.\"\
      \n    check:\n      IS_EMPTY_LOOKUP: \"CA10A1__cloudWatchLogGroup__r\"\notherwise:\n\
      \  status: \"COMPLIANT\"\n  currentStateMessage: \"DataSync Task logging is\
      \ enabled.\""
  - path: /types/CA10A1__CaAwsDataSyncTask__c/object.extracts.yaml
    md5Hash: 881FF834A04825679B9ABF5AEDC88474
    content: "---\nextracts: \n# Nullable. \n  - name: CA10A1__cloudWatchLogGroupArn__c\n\
      \    value: \n      FIELD:\n        path: CA10A1__cloudWatchLogGroupArn__c\n\
      \        # undeterminedIf:\n        #   noAccessDelegate:\n        #     path:\
      \ \"CA10A1__cloudWatchLogGroupArn__c\"\n        #     currentStateMessage: \"\
      Possible permissions issue with datasync:DescribeTask.\"\n"
  - path: /ce/ca/aws/data-sync/task-logging/test-data.json
    md5Hash: 7E7493658454D6CD3DDC6136AF740E8A
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10A1__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-07-21T01:08:22Z"
              },
              "Id": "test1",
              "CA10A1__disappearanceTime__c": "2025-07-21T01:08:22Z",
              "CA10A1__cloudWatchLogGroup__c": "",
              "CA10A1__cloudWatchLogGroupArn__c": "cloudWatchLogGroupArn1",
              "CA10A1__cloudWatchLogGroup__r": {
                  "Id": null,
                  "CA10__disappearanceTime__c": null
              }
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "isEmptyLookup('CA10A1__cloudWatchLogGroup__r')",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-07-21T01:08:22Z"
              },
              "Id": "test2",
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__cloudWatchLogGroup__c": "",
              "CA10A1__cloudWatchLogGroupArn__c": "cloudWatchLogGroupArn2",
              "CA10A1__cloudWatchLogGroup__r": {
                  "Id": null,
                  "CA10__disappearanceTime__c": null
              }
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "isEmptyLookup('CA10A1__cloudWatchLogGroup__r')",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-07-21T01:08:22Z"
              },
              "Id": "test3",
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__cloudWatchLogGroup__c": "cloudWatchLogGroup3",
              "CA10A1__cloudWatchLogGroupArn__c": "cloudWatchLogGroupArn3",
              "CA10A1__cloudWatchLogGroup__r": {
                  "Id": "cloudWatchLogGroup3",
                  "CA10__disappearanceTime__c": "2025-07-21T01:08:22Z"
              }
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "300",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-07-21T01:08:22Z"
              },
              "Id": "test4",
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__cloudWatchLogGroup__c": "cloudWatchLogGroup4",
              "CA10A1__cloudWatchLogGroupArn__c": "cloudWatchLogGroupArn4",
              "CA10A1__cloudWatchLogGroup__r": {
                  "Id": "cloudWatchLogGroup4",
                  "CA10__disappearanceTime__c": null
              }
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10A1__cloudWatchLogGroupArn__c').isEmpty()",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-07-21T01:08:22Z"
              },
              "Id": "test5",
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__cloudWatchLogGroup__c": "",
              "CA10A1__cloudWatchLogGroupArn__c": "",
              "CA10A1__cloudWatchLogGroup__r": {
                  "Id": null,
                  "CA10__disappearanceTime__c": null
              }
          }
      ]
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(CA10A1__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "isEmptyLookup('CA10A1__cloudWatchLogGroup__r')",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "isEmptyLookup('CA10A1__cloudWatchLogGroup__r')",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test5",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10A1__cloudWatchLogGroupArn__c').isEmpty()",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10A1__CaAwsDataSyncTask__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10A1__disappearanceTime__c TIMESTAMP,
      CA10A1__cloudWatchLogGroupArn__c STRING,
      CA10A1__cloudWatchLogGroup__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-07-21T01:08:22Z")
    },
    "Id" : "test1",
    "CA10A1__disappearanceTime__c" : new Date("2025-07-21T01:08:22Z"),
    "CA10A1__cloudWatchLogGroupArn__c" : "cloudWatchLogGroupArn1",
    "CA10A1__cloudWatchLogGroup__c" : ""
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-21T01:08:22Z")
    },
    "Id" : "test2",
    "CA10A1__cloudWatchLogGroupArn__c" : "cloudWatchLogGroupArn2",
    "CA10A1__cloudWatchLogGroup__c" : ""
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-21T01:08:22Z")
    },
    "Id" : "test3",
    "CA10A1__cloudWatchLogGroupArn__c" : "cloudWatchLogGroupArn3",
    "CA10A1__cloudWatchLogGroup__c" : "cloudWatchLogGroup3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-21T01:08:22Z")
    },
    "Id" : "test4",
    "CA10A1__cloudWatchLogGroupArn__c" : "cloudWatchLogGroupArn4",
    "CA10A1__cloudWatchLogGroup__c" : "cloudWatchLogGroup4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-21T01:08:22Z")
    },
    "Id" : "test5",
    "CA10A1__cloudWatchLogGroupArn__c" : "",
    "CA10A1__cloudWatchLogGroup__c" : ""
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsCloudWatchLogsLogGroup__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-07-21T01:08:22Z")
    },
    "Id" : null
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-21T01:08:22Z")
    },
    "Id" : "cloudWatchLogGroup3",
    "CA10__disappearanceTime__c" : new Date("2025-07-21T01:08:22Z")
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-21T01:08:22Z")
    },
    "Id" : "cloudWatchLogGroup4"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10A1__CaAwsDataSyncTask__c(
      obj STRUCT<
          Id STRING,
          CA10A1__disappearanceTime__c TIMESTAMP,
          CA10A1__cloudWatchLogGroupArn__c STRING,
          CA10A1__cloudWatchLogGroup__c STRING,
          CA10A1__cloudWatchLogGroup__r STRUCT<
              Id STRING,
              CA10__disappearanceTime__c TIMESTAMP
          >
      >,
      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 [CA10A1__disappearanceTime__c]: ' + obj.CA10A1__disappearanceTime__c);
      if (obj.CA10A1__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10A1__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.CA10A1__cloudWatchLogGroupArn__c; } return this.out; };
      references1.push('Cloud Watch Log Group ARN [obj.CA10A1__cloudWatchLogGroupArn__c]: ' + obj.CA10A1__cloudWatchLogGroupArn__c);
      if (TextLib.isEmpty(extract3.call(extract3))) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10A1__cloudWatchLogGroupArn__c').isEmpty()", currentStateMessage: "DataSync Task logging is not enabled.", currentStateReferences: references1.join('\n'), remediation: "Consider configuring a CloudWatch Log Group for the DataSync Task.", runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      if (TextLib.isEmpty(obj.CA10A1__cloudWatchLogGroupArn__c) || TextLib.isEmpty(obj.CA10A1__cloudWatchLogGroup__c) || obj.CA10A1__cloudWatchLogGroup__r.CA10__disappearanceTime__c != null) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "isEmptyLookup('CA10A1__cloudWatchLogGroup__r')", currentStateMessage: "DataSync Task logging has been deleted or does not exist in the CMDB.", currentStateReferences: references1.join('\n'), remediation: "Confirm that CloudWatch Log Group for the DataSync Task is configured.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "DataSync Task logging 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.Id AS Id,
          sObject.CA10A1__disappearanceTime__c AS CA10A1__disappearanceTime__c,
          sObject.CA10A1__cloudWatchLogGroupArn__c AS CA10A1__cloudWatchLogGroupArn__c,
          sObject.CA10A1__cloudWatchLogGroup__c AS CA10A1__cloudWatchLogGroup__c,
          STRUCT (
              `CA10A1__cloudWatchLogGroup__r`.Id AS Id,
              `CA10A1__cloudWatchLogGroup__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c
          ) AS CA10A1__cloudWatchLogGroup__r,
          process_CA10A1__CaAwsDataSyncTask__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10A1__disappearanceTime__c AS CA10A1__disappearanceTime__c,
                  sObject.CA10A1__cloudWatchLogGroupArn__c AS CA10A1__cloudWatchLogGroupArn__c,
                  sObject.CA10A1__cloudWatchLogGroup__c AS CA10A1__cloudWatchLogGroup__c,
                  STRUCT (
                      `CA10A1__cloudWatchLogGroup__r`.Id AS Id,
                      `CA10A1__cloudWatchLogGroup__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c
                  ) AS CA10A1__cloudWatchLogGroup__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10A1__CaAwsDataSyncTask__c()) AS sObject
      LEFT JOIN UNNEST(mock_CA10__CaAwsCloudWatchLogsLogGroup__c()) AS `CA10A1__cloudWatchLogGroup__r`
          ON sObject.CA10A1__cloudWatchLogGroup__c = `CA10A1__cloudWatchLogGroup__r`.Id
  ) sObject ON sObject.Id = expectedResult.Id;
