---
policy: /ce/ca/aws/rds/instance-automated-backups
logic: /ce/ca/aws/rds/instance-automated-backups/prod.logic.yaml
executionTime: 2025-10-25T12:01:58.609867127Z
generationMs: 64
executionMs: 580
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: CA10__backupRetentionPeriod__c == number(0.0)
      actual: CA10__backupRetentionPeriod__c == number(0.0)
    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/rds/instance-automated-backups/policy.yaml
    md5Hash: 5A202E092D23DCB72783BA1452D0C5A3
    content: |-
      ---
      names:
        full: "AWS RDS Instance automated backups are not enabled"
        contextual: "Instance automated backups are not enabled"
      description: "Ensure that automated backups are enabled for AWS RDS DB instances. Automated
        backups allow you to recover your database to any point in time within your retention
        period."
      type: "COMPLIANCE_POLICY"
      categories:
        - "SECURITY"
      frameworkMappings:
        - "/frameworks/cloudaware/resource-security/data-protection-and-recovery"
        - "/frameworks/aws-fsbp-v1.0.0/rds/11"
        - "/frameworks/aws-well-architected/rel/09/01"
        - "/frameworks/aws-well-architected/rel/09/03"
      similarPolicies:
        awsSecurityHub:
          - name: "[RDS.11] RDS instances should have automatic backups enabled"
            url: "https://docs.aws.amazon.com/securityhub/latest/userguide/rds-controls.html#rds-11"
  - path: /ce/ca/aws/rds/instance-automated-backups/prod.logic.yaml
    md5Hash: 79F27782DFE1BE7A9391431599C03E6C
    content: |-
      ---
      inputType: "CA10__CaAwsDbInstance__c"
      testData:
        - file: test-data.json
      importExtracts:
        - file: /types/CA10__CaAwsDbInstance__c/object.extracts.yaml
      conditions:
        - status: INCOMPLIANT
          currentStateMessage: "The DB Instance automated backups are disabled."
          remediationMessage: "Enable automated backups by setting the backup retention\
            \ period to a value greater than 0 days."
          check:
            IS_EQUAL:
              left:
                FIELD:
                  path: CA10__backupRetentionPeriod__c
              right:
                NUMBER: 0.0
      otherwise:
        status: COMPLIANT
        currentStateMessage: "The DB Instance automated backups are enabled."
  - path: /ce/ca/aws/rds/instance-automated-backups/test-data.json
    md5Hash: 1448C4D27357DA7488617485E08D1536
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-21T01:48:33Z"
              },
              "CA10__disappearanceTime__c": "2025-08-15T02:09:15Z",
              "CA10__backupRetentionPeriod__c": 14,
              "Id": "test1"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "CA10__backupRetentionPeriod__c == number(0.0)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-21T01:48:33Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__backupRetentionPeriod__c": 0,
              "Id": "test2"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "200",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-21T01:48:33Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__backupRetentionPeriod__c": 7,
              "Id": "test3"
          }
      ]
  - path: /types/CA10__CaAwsDbInstance__c/object.extracts.yaml
    md5Hash: 26DCC1C39C347B18BF7B5A1C5DBD9419
    content: "---\nextracts:\n# Not Nullable. Can't have no access, retrieved via\
      \ rds:DescribeDBInstances\n  - name: CA10__engine__c\n    value:\n      FIELD:\n\
      \        path: CA10__engine__c\n        undeterminedIf:\n          isEmpty:\
      \ \"Corrupted data. DB Instance Engine cannot be empty.\"\n# Not Nullable. Can't\
      \ have no access, retrieved via rds:DescribeDBInstances\n  - name: CA10__endpointPort__c\n\
      \    value:\n      FIELD:\n        path: CA10__endpointPort__c\n        undeterminedIf:\n\
      \          isEmpty: \"Corrupted data. DB Endpoint Port cannot be empty.\"\n\
      # Checkbox. Can't have no access, retrieved via rds:DescribeDBInstances\n  -\
      \ name: CA10__publiclyAccessible__c\n    value:\n      FIELD:\n        path:\
      \ CA10__publiclyAccessible__c\n# Checkbox. Can't have no access, retrieved via\
      \ rds:DescribeDBInstances\n  - name: CA10__storageEncrypted__c\n    value: \n\
      \      FIELD:\n        path: CA10__storageEncrypted__c\n# Checkbox. Can't have\
      \ no access, retrieved via rds:DescribeDBInstances\n  - name: CA10__autoMinorVersionUpgrade__c\n\
      \    value: \n      FIELD:\n        path: CA10__autoMinorVersionUpgrade__c\n\
      # Checkbox. Can't have no access, retrieved via rds:DescribeDBInstances\n  -\
      \ name: CA10__multiAz__c\n    value: \n      FIELD:\n        path: CA10__multiAz__c\n\
      # Nullable. Values: available, backing-up, creating ...\n  - name: \"CA10__status__c\"\
      \n    value:\n      FIELD:\n        path: \"CA10__status__c\"\n# Nullable.\n\
      \  - name: \"CA10__createTime__c\"\n    value:\n      FIELD:\n        path:\
      \ \"CA10__createTime__c\"\n# Nullable.\n  - name: \"CA10__averageCpuOneMonth__c\"\
      \n    value:\n      FIELD:\n        path: \"CA10__averageCpuOneMonth__c\"\n\
      # Nullable.\n  - name: \"CA10__regionName__c\"\n    value:\n      FIELD:\n \
      \       path: \"CA10__regionName__c\"\n# Nullable.\n  - name: \"CA10__diskReadIopsAvg30d__c\"\
      \n    value:\n      FIELD:\n        path: \"CA10__diskReadIopsAvg30d__c\"\n\
      # Nullable.\n  - name: \"CA10__diskWriteIopsAvg30d__c\"\n    value:\n      FIELD:\n\
      \        path: \"CA10__diskWriteIopsAvg30d__c\"\n# Nullable.\n  - name: \"CA10__databaseConnectionsAvg30d__c\"\
      \n    value:\n      FIELD:\n        path: \"CA10__databaseConnectionsAvg30d__c\"\
      \n# Not nullable. Can't have no access, retrieved via rds:DescribeDBInstances\n\
      \  - name: \"CA10__backupRetentionPeriod__c\"\n    value:\n      FIELD:\n  \
      \      path: \"CA10__backupRetentionPeriod__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" : "CA10__backupRetentionPeriod__c == number(0.0)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsDbInstance__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__backupRetentionPeriod__c FLOAT64,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-10-21T01:48:33Z")
    },
    "CA10__disappearanceTime__c" : new Date("2025-08-15T02:09:15Z"),
    "CA10__backupRetentionPeriod__c" : 14,
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-21T01:48:33Z")
    },
    "CA10__backupRetentionPeriod__c" : 0,
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-21T01:48:33Z")
    },
    "CA10__backupRetentionPeriod__c" : 7,
    "Id" : "test3"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsDbInstance__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__backupRetentionPeriod__c FLOAT64,
          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 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]
      references1.push('Backup Retention Period [obj.CA10__backupRetentionPeriod__c]: ' + obj.CA10__backupRetentionPeriod__c);
      if (obj.CA10__backupRetentionPeriod__c == 0.0) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "CA10__backupRetentionPeriod__c == number(0.0)", currentStateMessage: "The DB Instance automated backups are disabled.", currentStateReferences: references1.join('\n'), remediation: "Enable automated backups by setting the backup retention period to a value greater than 0 days.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "The DB Instance automated backups are 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__backupRetentionPeriod__c AS CA10__backupRetentionPeriod__c,
          sObject.Id AS Id,
          process_CA10__CaAwsDbInstance__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__backupRetentionPeriod__c AS CA10__backupRetentionPeriod__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsDbInstance__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
