---
policy: /ce/ca/aws/rds/instance-service-quota
logic: /ce/ca/aws/rds/instance-service-quota/prod.logic.yaml
executionTime: 2025-12-27T12:02:09.324164816Z
generationMs: 99
executionMs: 690
rows:
  - id: '001'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: CA10__AWS_Account_Limits__r.has(COMPLIANT)
      actual: CA10__AWS_Account_Limits__r.has(COMPLIANT)
    runtimeError: {}
  - id: '002'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: CA10__AWS_Account_Limits__r.has(COMPLIANT)
      actual: CA10__AWS_Account_Limits__r.has(COMPLIANT)
    runtimeError: {}
  - id: '003'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10__AWS_Account_Limits__r.has(INCOMPLIANT)
      actual: CA10__AWS_Account_Limits__r.has(INCOMPLIANT)
    runtimeError: {}
  - id: '004'
    match: true
    status:
      expected: UNDETERMINED
      actual: UNDETERMINED
    conditionIndex:
      expected: 400
      actual: 400
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/rds/instance-service-quota/policy.yaml
    md5Hash: 63A17E657DCCC825B61ADA7D597B90E5
    content: |
      ---
      names:
        full: "AWS RDS Instance count has reach the service quota"
        contextual: "Instance count has reach the service quota"
      description: "Ensure that the number of RDS database instances provisioned in your AWS account \
        \ has not reached the service quota established for your organization for the RDS workload deployed."
      type: "COMPLIANCE_POLICY"
      categories:
        - "RELIABILITY"
      frameworkMappings:
        - "/frameworks/cloudaware/resource-reliability/system-configuration"
        - "/frameworks/aws-well-architected/rel/01/05"
      similarPolicies:
        cloudConformity:
          - url: "https://www.trendmicro.com/cloudoneconformity/knowledge-base/aws/RDS/db-instance-counts.html"
            name: "RDS Instance Counts"
  - path: /ce/ca/aws/rds/instance-service-quota/prod.logic.yaml
    md5Hash: 44E1DABE99DFB7B9C36A4F90F2203EB6
    content: "---\ninputType: \"CA10__CaAwsAccount__c\"\ntestData:\n  - file: test-data.json\n\
      conditions:\n  - status: \"INCOMPLIANT\"\n    currentStateMessage: \"The number\
      \ of RDS database instances in your AWS account has reached the service quota.\"\
      \n    remediationMessage: \"Consider increasing the service limit for RDS database\
      \ instances.\"\n    check:\n      RELATED_LIST_HAS:\n        relationshipName:\
      \ \"CA10__AWS_Account_Limits__r\"\n        status: \"INCOMPLIANT\"\n  - status:\
      \ \"COMPLIANT\"\n    currentStateMessage: \"The number of RDS database instances\
      \ in your AWS account has not reached the service quota.\"\n    check:\n   \
      \   RELATED_LIST_HAS:\n        relationshipName: \"CA10__AWS_Account_Limits__r\"\
      \n        status: \"COMPLIANT\"\n  - status: \"UNDETERMINED\"\n    currentStateMessage:\
      \ \"The service quota for the Account is not available.\"\n    check:\n    \
      \  RELATED_LIST_HAS:\n        relationshipName: \"CA10__AWS_Account_Limits__r\"\
      \n        status: \"UNDETERMINED\"\notherwise:\n  status: \"UNDETERMINED\"\n\
      \  currentStateMessage: \"The service quota for the Account is not available.\"\
      \nrelatedLists:\n  - relationshipName: \"CA10__AWS_Account_Limits__r\"\n   \
      \ importExtracts:\n      - file: /types/CA10__CaAwsAccountLimits__c/object.extracts.yaml\n\
      \    conditions:\n      - status: \"INCOMPLIANT\"\n        currentStateMessage:\
      \ \"The number of RDS database instances in your AWS account has reached the\
      \ service quota.\"\n        remediationMessage: \"Consider increasing the service\
      \ limit for RDS database instances.\"\n        check:\n          GREATER_THAN_EQUAL:\n\
      \            left:\n              EXTRACT: \"CA10__rdsInstancesUsedPercent__c\"\
      \n            right:\n              NUMBER: 90.0\n      - status: \"COMPLIANT\"\
      \n        currentStateMessage: \"There is no RDS database instances in your\
      \ AWS account\"\n        check:\n          IS_EMPTY: \n            arg:\n  \
      \            EXTRACT: \"CA10__rdsInstancesUsedPercent__c\"   \n      - status:\
      \ \"COMPLIANT\"\n        currentStateMessage: \"The number of RDS database instances\
      \ provisioned in your AWS account has not reached the service quota.\"\n   \
      \     check:\n          LESS_THAN:\n            left:\n              EXTRACT:\
      \ \"CA10__rdsInstancesUsedPercent__c\"\n            right:\n              NUMBER:\
      \ 90.0\n    otherwise:\n      status: \"UNDETERMINED\"\n      currentStateMessage:\
      \ \"Unexpected value in the field.\"\n      "
  - path: /ce/ca/aws/rds/instance-service-quota/test-data.json
    md5Hash: BABC70AC7966B052CDBDECBF8AD06C9D
    content: |
      [
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "299",
            "conditionText": "CA10__AWS_Account_Limits__r.has(COMPLIANT)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-11-24T03:44:20Z" },
          "Id": "001",
          "CA10__AWS_Account_Limits__r": [
            {
              "CA10__rdsInstancesUsedPercent__c": 0,
              "CA10__account__c": "001",
              "Id": "001-1"
            },
            {
              "CA10__rdsInstancesUsedPercent__c": 0,
              "CA10__account__c": "001",
              "Id": "001-2"
            },
            {
              "CA10__rdsInstancesUsedPercent__c": null,
              "CA10__account__c": "001",
              "Id": "001-3"
            }
          ]
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "299",
            "conditionText": "CA10__AWS_Account_Limits__r.has(COMPLIANT)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-11-24T03:44:20Z" },
          "Id": "002",
          "CA10__AWS_Account_Limits__r": [
            {
              "CA10__rdsInstancesUsedPercent__c": 50.0,
              "CA10__account__c": "002",
              "Id": "002-1"
            },
            {
              "CA10__rdsInstancesUsedPercent__c": 40.0,
              "CA10__account__c": "002",
              "Id": "001-2"
            },
            {
              "CA10__rdsInstancesUsedPercent__c": 30.0,
              "CA10__account__c": "002",
              "Id": "002-3"
            }
          ]
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "199",
            "conditionText": "CA10__AWS_Account_Limits__r.has(INCOMPLIANT)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-11-24T03:44:20Z" },
          "Id": "003",
          "CA10__AWS_Account_Limits__r": [
            {
              "CA10__rdsInstancesUsedPercent__c": 95.0,
              "CA10__account__c": "003",
              "Id": "003-1"
            },
            {
              "CA10__rdsInstancesUsedPercent__c": 40.0,
              "CA10__account__c": "003",
              "Id": "003-2"
            },
            {
              "CA10__rdsInstancesUsedPercent__c": 30.0,
              "CA10__account__c": "003",
              "Id": "003-3"
            }
          ]
        },
        {
          "expectedResult": {
            "status": "UNDETERMINED",
            "conditionIndex": "400",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-11-24T03:44:20Z" },
          "Id": "004",
          "CA10__AWS_Account_Limits__r": []
        }
      ]
  - path: /types/CA10__CaAwsAccountLimits__c/object.extracts.yaml
    md5Hash: C2C335CB4467FE917B74EB4417888D5C
    content: "---\nextracts:\n# Nullable. \n  - name: CA10__rdsInstancesUsedPercent__c\n\
      \    value: \n      FIELD:\n        path: CA10__rdsInstancesUsedPercent__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" : "001",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "CA10__AWS_Account_Limits__r.has(COMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "002",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "CA10__AWS_Account_Limits__r.has(COMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "003",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "CA10__AWS_Account_Limits__r.has(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "004",
    "expectedResult" : {
      "status" : "UNDETERMINED",
      "conditionIndex" : "400",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsAccount__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-11-24T03:44:20Z")
    },
    "Id" : "001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-24T03:44:20Z")
    },
    "Id" : "002"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-24T03:44:20Z")
    },
    "Id" : "003"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-24T03:44:20Z")
    },
    "Id" : "004"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsAccountLimits__c()
  RETURNS ARRAY<STRUCT<
      CA10__rdsInstancesUsedPercent__c FLOAT64,
      CA10__account__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-11-24T03:44:20Z")
    },
    "CA10__rdsInstancesUsedPercent__c" : 0,
    "CA10__account__c" : "001",
    "Id" : "001-1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-24T03:44:20Z")
    },
    "CA10__rdsInstancesUsedPercent__c" : 40.0,
    "CA10__account__c" : "002",
    "Id" : "001-2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-24T03:44:20Z")
    },
    "CA10__rdsInstancesUsedPercent__c" : null,
    "CA10__account__c" : "001",
    "Id" : "001-3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-24T03:44:20Z")
    },
    "CA10__rdsInstancesUsedPercent__c" : 50.0,
    "CA10__account__c" : "002",
    "Id" : "002-1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-24T03:44:20Z")
    },
    "CA10__rdsInstancesUsedPercent__c" : 30.0,
    "CA10__account__c" : "002",
    "Id" : "002-3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-24T03:44:20Z")
    },
    "CA10__rdsInstancesUsedPercent__c" : 95.0,
    "CA10__account__c" : "003",
    "Id" : "003-1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-24T03:44:20Z")
    },
    "CA10__rdsInstancesUsedPercent__c" : 40.0,
    "CA10__account__c" : "003",
    "Id" : "003-2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-11-24T03:44:20Z")
    },
    "CA10__rdsInstancesUsedPercent__c" : 30.0,
    "CA10__account__c" : "003",
    "Id" : "003-3"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsAccount__c(
      obj STRUCT<
          Id STRING,
          CA10__AWS_Account_Limits__r ARRAY<STRUCT<
              CA10__rdsInstancesUsedPercent__c FLOAT64,
              CA10__account__c STRING,
              Id STRING,
              result STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError 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]
      if (false) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared()", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10__AWS_Account_Limits__r_INCOMPLIANT2 = 0;
      if (obj.CA10__AWS_Account_Limits__r != null) {
          for (var i3 = 0; i3 < obj.CA10__AWS_Account_Limits__r.length; i3++) {
              if (typeof(obj.CA10__AWS_Account_Limits__r[i3].status) !== 'undefined') {
                  if (obj.CA10__AWS_Account_Limits__r[i3].status == 'INCOMPLIANT') {
                      count_CA10__AWS_Account_Limits__r_INCOMPLIANT2 += obj.CA10__AWS_Account_Limits__r[i3].count;
                  }
              } else  {
                  if (obj.CA10__AWS_Account_Limits__r[i3].result.status == 'INCOMPLIANT') {
                      count_CA10__AWS_Account_Limits__r_INCOMPLIANT2 += 1;
                  }
              }
          }
      }
      // condition[1], conditionIndex:[100..199]
      references1.push('Related list [CA10__AWS_Account_Limits__r] ' + (count_CA10__AWS_Account_Limits__r_INCOMPLIANT2 > 0 ? 'has' : 'does not have') + ' objects in INCOMPLIANT status');
      if (count_CA10__AWS_Account_Limits__r_INCOMPLIANT2 > 0) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "CA10__AWS_Account_Limits__r.has(INCOMPLIANT)", currentStateMessage: "The number of RDS database instances in your AWS account has reached the service quota.", currentStateReferences: references1.join('\n'), remediation: "Consider increasing the service limit for RDS database instances.", runtimeError: null};
      }
      var count_CA10__AWS_Account_Limits__r_COMPLIANT4 = 0;
      if (obj.CA10__AWS_Account_Limits__r != null) {
          for (var i5 = 0; i5 < obj.CA10__AWS_Account_Limits__r.length; i5++) {
              if (typeof(obj.CA10__AWS_Account_Limits__r[i5].status) !== 'undefined') {
                  if (obj.CA10__AWS_Account_Limits__r[i5].status == 'COMPLIANT') {
                      count_CA10__AWS_Account_Limits__r_COMPLIANT4 += obj.CA10__AWS_Account_Limits__r[i5].count;
                  }
              } else  {
                  if (obj.CA10__AWS_Account_Limits__r[i5].result.status == 'COMPLIANT') {
                      count_CA10__AWS_Account_Limits__r_COMPLIANT4 += 1;
                  }
              }
          }
      }
      // condition[2], conditionIndex:[200..299]
      if (count_CA10__AWS_Account_Limits__r_COMPLIANT4 > 0) {
          return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "CA10__AWS_Account_Limits__r.has(COMPLIANT)", currentStateMessage: "The number of RDS database instances in your AWS account has not reached the service quota.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10__AWS_Account_Limits__r_UNDETERMINED6 = 0;
      if (obj.CA10__AWS_Account_Limits__r != null) {
          for (var i7 = 0; i7 < obj.CA10__AWS_Account_Limits__r.length; i7++) {
              if (typeof(obj.CA10__AWS_Account_Limits__r[i7].status) !== 'undefined') {
                  if (obj.CA10__AWS_Account_Limits__r[i7].status == 'UNDETERMINED') {
                      count_CA10__AWS_Account_Limits__r_UNDETERMINED6 += obj.CA10__AWS_Account_Limits__r[i7].count;
                  }
              } else  {
                  if (obj.CA10__AWS_Account_Limits__r[i7].result.status == 'UNDETERMINED') {
                      count_CA10__AWS_Account_Limits__r_UNDETERMINED6 += 1;
                  }
              }
          }
      }
      // condition[3], conditionIndex:[300..399]
      if (count_CA10__AWS_Account_Limits__r_UNDETERMINED6 > 0) {
          return {status: 'UNDETERMINED', conditionIndex: 399, conditionText: "CA10__AWS_Account_Limits__r.has(UNDETERMINED)", currentStateMessage: "The service quota for the Account is not available.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'UNDETERMINED', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "The service quota for the Account is not available.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__AWS_Account_Limits__r(
      obj STRUCT<
          CA10__rdsInstancesUsedPercent__c FLOAT64,
          CA10__account__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 IsEmptyLib = new function () {
      this.simpleIsEmpty = function(arg) {
          return arg == null;
      };
      this.simpleIsNotEmpty = function(arg) {
          return arg != null;
      };
  }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      if (false) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared()", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[1], conditionIndex:[100..199]
      function extract4() { if (!this.out) { this.out = obj.CA10__rdsInstancesUsedPercent__c; } return this.out; };
      references1.push('RDS: Instances, Used % [obj.CA10__rdsInstancesUsedPercent__c]: ' + obj.CA10__rdsInstancesUsedPercent__c);
      if (extract4.call(extract4) != null && 90.0 != null && extract4.call(extract4) >= 90.0) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__rdsInstancesUsedPercent__c') >= number(90.0)", currentStateMessage: "The number of RDS database instances in your AWS account has reached the service quota.", currentStateReferences: references1.join('\n'), remediation: "Consider increasing the service limit for RDS database instances.", runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract7() { if (!this.out) { this.out = obj.CA10__rdsInstancesUsedPercent__c; } return this.out; };
      if (IsEmptyLib.simpleIsEmpty(extract7.call(extract7))) {
          return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__rdsInstancesUsedPercent__c').isEmpty()", currentStateMessage: "There is no RDS database instances in your AWS account", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      function extract11() { if (!this.out) { this.out = obj.CA10__rdsInstancesUsedPercent__c; } return this.out; };
      if (extract11.call(extract11) != null && 90.0 != null && extract11.call(extract11) < 90.0) {
          return {status: 'COMPLIANT', conditionIndex: 399, conditionText: "extract('CA10__rdsInstancesUsedPercent__c') < number(90.0)", currentStateMessage: "The number of RDS database instances provisioned in your AWS account has not reached the service quota.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'UNDETERMINED', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "Unexpected value 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.Id AS Id,
          `CA10__AWS_Account_Limits__r`.arr AS CA10__AWS_Account_Limits__r,
          process_CA10__CaAwsAccount__c(
              STRUCT(
                  sObject.Id AS Id,
                  `CA10__AWS_Account_Limits__r`.arr AS CA10__AWS_Account_Limits__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsAccount__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10__account__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.CA10__rdsInstancesUsedPercent__c AS CA10__rdsInstancesUsedPercent__c,
                      sObject.CA10__account__c AS CA10__account__c,
                      sObject.Id AS Id,
                      process_CA10__AWS_Account_Limits__r(
                          STRUCT(
                              sObject.CA10__rdsInstancesUsedPercent__c AS CA10__rdsInstancesUsedPercent__c,
                              sObject.CA10__account__c AS CA10__account__c,
                              sObject.Id AS Id
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaAwsAccountLimits__c()) AS sObject
          GROUP BY sObject.CA10__account__c
      ) AS `CA10__AWS_Account_Limits__r`
          ON sObject.Id = `CA10__AWS_Account_Limits__r`.CA10__account__c
  ) sObject ON sObject.Id = expectedResult.Id;
