---
policy: /ce/ca/aws/dms/replication-instance-publicly-accessible
logic: /ce/ca/aws/dms/replication-instance-publicly-accessible/prod.logic.yaml
executionTime: 2025-07-12T12:02:34.009411693Z
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: 199
      actual: 199
    conditionText:
      expected: extract('CA10A1__publiclyAccessible__c')
      actual: extract('CA10A1__publiclyAccessible__c')
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/dms/replication-instance-publicly-accessible/policy.yaml
    md5Hash: 7425994B042072FF1A269CD80267DDC6
    content: "---\nnames:\n  full: AWS DMS Replication Instance is publicly accessible\n\
      \  contextual: Replication Instance is publicly accessible\ndescription: >\n\
      \  Ensure that AWS Database Migration Service (DMS) replication instances are\
      \ not \n  publicly accessible to minimize security risks such as unauthorized\
      \ access, \n  denial-of-service attacks, and data exfiltration.\ntype: COMPLIANCE_POLICY\n\
      categories:\n  - SECURITY\nframeworkMappings:\n  - \"/frameworks/cloudaware/resource-security/public-and-anonymous-access\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/dms/01\"\nsimilarPolicies:\n  awsSecurityHub:\n\
      \    - name: \"[DMS.1] Database Migration Service replication instances should\
      \ not be public\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/dms-controls.html#dms-1\"\
      \n  internal:\n    - \"dec-x-e02b5fdd\""
  - path: /ce/ca/aws/dms/replication-instance-publicly-accessible/prod.logic.yaml
    md5Hash: 2961BFDABD4896CB57CAD0BEE2B456D7
    content: "---\ninputType: \"CA10A1__CaAwsDmsReplicationInstance__c\"\nimportExtracts:\n\
      \  - file: /types/CA10A1__CaAwsDmsReplicationInstance__c/object.extracts.yaml\n\
      testData:\n  - file: \"test-data.json\"\nconditions:\n  - status: \"INCOMPLIANT\"\
      \n    currentStateMessage: \"The DMS Replication Instance is publicly accessible.\"\
      \n    remediationMessage: \"Consider changing the public access setting by deleting\
      \ your current instance, and then recreating it.\"    \n    check:\n      EXTRACT:\
      \ \"CA10A1__publiclyAccessible__c\"\notherwise:\n  status: \"COMPLIANT\"\n \
      \ currentStateMessage: \"The DMS Replication Instance is not publicly accessible.\""
  - path: /ce/ca/aws/dms/replication-instance-publicly-accessible/test-data.json
    md5Hash: 8135C4C68801F97113DE722E593D170D
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10A1__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-07-09T20:13:51Z"
              },
              "Id": "test1",
              "CA10A1__disappearanceTime__c": "2025-07-09T13:41:52Z",
              "CA10A1__publiclyAccessible__c": true
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10A1__publiclyAccessible__c')",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-07-09T20:13:51Z"
              },
              "Id": "test2",
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__publiclyAccessible__c": true
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "200",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-07-09T20:13:51Z"
              },
              "Id": "test3",
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__publiclyAccessible__c": false
          }
      ]
  - path: /types/CA10A1__CaAwsDmsReplicationInstance__c/object.extracts.yaml
    md5Hash: 87ABF7C3D90A331001E9277FC9A9E8E3
    content: "---\nextracts:\n# Checkbox. Values: true/false. Can't have no access,\
      \ retrieved via dms:DescribeReplicationInstances\n  - name: CA10A1__publiclyAccessible__c\n\
      \    value: \n      FIELD:\n        path: CA10A1__publiclyAccessible__c\n# Checkbox.\
      \ Values: true/false. Can't have no access, retrieved via dms:DescribeReplicationInstances\n\
      \  - name: CA10A1__minorVersionAutomaricUpdate__c\n    value: \n      FIELD:\n\
      \        path: CA10A1__minorVersionAutomaricUpdate__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(CA10A1__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10A1__publiclyAccessible__c')",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10A1__CaAwsDmsReplicationInstance__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10A1__disappearanceTime__c TIMESTAMP,
      CA10A1__publiclyAccessible__c BOOLEAN,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-07-09T20:13:51Z")
    },
    "Id" : "test1",
    "CA10A1__disappearanceTime__c" : new Date("2025-07-09T13:41:52Z"),
    "CA10A1__publiclyAccessible__c" : true
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-09T20:13:51Z")
    },
    "Id" : "test2",
    "CA10A1__publiclyAccessible__c" : true
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-09T20:13:51Z")
    },
    "Id" : "test3",
    "CA10A1__publiclyAccessible__c" : false
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10A1__CaAwsDmsReplicationInstance__c(
      obj STRUCT<
          Id STRING,
          CA10A1__disappearanceTime__c TIMESTAMP,
          CA10A1__publiclyAccessible__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 [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__publiclyAccessible__c; } return this.out; };
      references1.push('Publicly Accessible [obj.CA10A1__publiclyAccessible__c]: ' + obj.CA10A1__publiclyAccessible__c);
      if (extract3.call(extract3)) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10A1__publiclyAccessible__c')", currentStateMessage: "The DMS Replication Instance is publicly accessible.", currentStateReferences: references1.join('\n'), remediation: "Consider changing the public access setting by deleting your current instance, and then recreating it.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "The DMS Replication Instance is not publicly accessible.", 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__publiclyAccessible__c AS CA10A1__publiclyAccessible__c,
          process_CA10A1__CaAwsDmsReplicationInstance__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10A1__disappearanceTime__c AS CA10A1__disappearanceTime__c,
                  sObject.CA10A1__publiclyAccessible__c AS CA10A1__publiclyAccessible__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10A1__CaAwsDmsReplicationInstance__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
