---
title: Get an IaC custom rule
description: Get a custom IaC (Infrastructure as Code) rule and its current revision.
breadcrumbs: Docs > API > Get an IaC custom rule
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# Get an IaC custom rule

## v2 (latest)

{% alert level="warning" %}
**Note**: This endpoint is in Preview and is subject to change.
If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help.md).
{% /alert %}

| Datadog site      | API endpoint                                                                               |
| ----------------- | ------------------------------------------------------------------------------------------ |
| app.datadoghq.com | GET https://api.datadoghq.com/api/v2/security/code_security/iac_custom_rules/{rule_id}     |
| us3.datadoghq.com | GET https://api.us3.datadoghq.com/api/v2/security/code_security/iac_custom_rules/{rule_id} |
| us5.datadoghq.com | GET https://api.us5.datadoghq.com/api/v2/security/code_security/iac_custom_rules/{rule_id} |
| app.datadoghq.eu  | GET https://api.datadoghq.eu/api/v2/security/code_security/iac_custom_rules/{rule_id}      |
| ap1.datadoghq.com | GET https://api.ap1.datadoghq.com/api/v2/security/code_security/iac_custom_rules/{rule_id} |
| ap2.datadoghq.com | GET https://api.ap2.datadoghq.com/api/v2/security/code_security/iac_custom_rules/{rule_id} |
| uk1.datadoghq.com | GET https://api.uk1.datadoghq.com/api/v2/security/code_security/iac_custom_rules/{rule_id} |
| app.ddog-gov.com  | GET https://api.ddog-gov.com/api/v2/security/code_security/iac_custom_rules/{rule_id}      |
| us2.ddog-gov.com  | GET https://api.us2.ddog-gov.com/api/v2/security/code_security/iac_custom_rules/{rule_id}  |

### Overview

Get a custom IaC (Infrastructure as Code) rule and its current revision.
Use `GET /api/v2/security/code_security/iac_custom_rules` to search rules.
Use `GET /api/v2/security/code_security/iac_custom_rules/{rule_id}/revisions` to get the previous revisions.

This endpoint requires the `appsec_vm_read` permission.

OAuth apps require the `appsec_vm_read` authorization [scope](https://docs.datadoghq.com/api/latest/scopes.md#code-security) to access this endpoint.

### Arguments

#### Path Parameters

| Field                | Type   | Description                                                                                     |
| -------------------- | ------ | ----------------------------------------------------------------------------------------------- |
| rule_id [*required*] | string | The ID of the IaC custom rule, for example `custom-terraform-aws-s3-bucket-without-encryption`. |

### Response

{% tabs %}
{% tab label="200" %}
OK

{% tabs %}
{% tab label="Model" %}
An IaC custom rule.

| Parent field | Field                       | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ------------ | --------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|              | data [*required*]           | object  | An IaC custom rule and its current revision.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| data         | attributes [*required*]     | object  | The attributes of an IaC custom rule, from its current revision.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| attributes   | category [*required*]       | enum    | The category of the misconfiguration that the rule detects. - `access_control`: Access to resources. - `availability`: Resilience and uptime of resources. - `backup`: Backups, snapshots, and versioning. - `best_practices`: General configuration practices. - `bill_of_materials`: Inventory of the components that the configuration declares. - `build_process`: Build and image instructions. - `encryption`: Encryption of data at rest and in transit. - `insecure_configurations`: Settings that weaken security. - `insecure_defaults`: Default values that weaken security. - `least_privilege`: Permissions broader than the resource needs. - `networking_and_firewall`: Network exposure and firewall rules. - `observability`: Logging, monitoring, and auditing. - `resource_management`: Resource limits and quotas. - `secret_management`: Secrets and credentials in the configuration. - `structure_and_semantics`: Syntax and structure of the configuration. - `supply_chain`: Origin and integrity of dependencies and images. Allowed enum values: `access_control`, `availability`, `backup`, `best_practices`, `bill_of_materials`, `build_process`, `encryption`, `insecure_configurations`, `insecure_defaults`, `least_privilege`, `networking_and_firewall`, `observability`, `resource_management`, `secret_management`, `structure_and_semantics`, `supply_chain`.                                                                                                                                                                                                                       |
| attributes   | created_at [*required*]     | int64   | The creation time of the rule, in milliseconds since the Unix epoch, in UTC.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| attributes   | created_by_id [*required*]  | string  | The UUID (universally unique identifier) of the user who created the rule.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| attributes   | cwe_id [*required*]         | string  | The CWE (Common Weakness Enumeration) ID of the weakness that the rule detects, in the `CWE-<number>` format. `null` when the rule has no CWE ID.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| attributes   | description [*required*]    | string  | What the rule detects and why it matters, at most 10,000 bytes in UTF-8. Search it with `filter[query]`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| attributes   | is_published [*required*]   | boolean | `true` when scans run the rule. `false` when the rule is a draft, which scans skip. Filter with `filter[is_published]=true`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| attributes   | modified_at [*required*]    | int64   | The creation time of the current revision, in milliseconds since the Unix epoch, in UTC.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| attributes   | modified_by_id [*required*] | string  | The UUID of the user who stored the current revision.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| attributes   | name [*required*]           | string  | The display name of the rule, between 1 and 60 bytes in UTF-8. Search it with `filter[query]`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| attributes   | platform [*required*]       | enum    | The IaC (Infrastructure as Code) platform of the files that the rule scans, as stored. Rules created outside this API can have a platform that custom rules don't support. Scans don't run these rules, and create, update, and validate requests don't accept that platform. - `ansible`: Ansible playbooks. - `azure_resource_manager`: Azure Resource Manager templates. Custom rules don't support it. - `buildah`: Buildah files. Custom rules don't support it. - `cicd`: GitHub Actions workflows. - `cloudformation`: AWS CloudFormation templates. - `common`: Rules that aren't specific to one platform. Custom rules don't support it. - `crossplane`: Crossplane manifests. Custom rules don't support it. - `docker_compose`: Docker Compose files. - `dockerfile`: Dockerfiles. - `google_deployment_manager`: Google Cloud Deployment Manager templates. Custom rules don't support it. - `grpc`: gRPC Protocol Buffers definitions. Custom rules don't support it. - `knative`: Knative manifests. Custom rules don't support it. - `kubernetes`: Kubernetes manifests. - `openapi`: OpenAPI definitions. Custom rules don't support it. - `pulumi`: Pulumi programs. Custom rules don't support it. - `serverless_fw`: Serverless Framework files. Custom rules don't support it. - `terraform`: Terraform configuration files. Allowed enum values: `ansible`, `azure_resource_manager`, `buildah`, `cicd`, `cloudformation`, `common`, `crossplane`, `docker_compose`, `dockerfile`, `google_deployment_manager`, `grpc`, `knative`, `kubernetes`, `openapi`, `pulumi`, `serverless_fw`, `terraform`. |
| attributes   | provider [*required*]       | string  | The cloud or service provider that the rule targets, in lowercase, for example `aws`. `null` when the rule has no provider. Filter with `filter[provider]=aws`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| attributes   | rego_query [*required*]     | string  | The Rego source of the rule, in plain text.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| attributes   | sample_file [*required*]    | string  | An example IaC file, in plain text, that contains the misconfiguration that the rule detects. `null` when the rule has no sample file.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| attributes   | severity [*required*]       | enum    | The severity of the findings that the rule reports. - `critical`: The highest severity. - `high`: The second highest severity. - `medium`: The middle severity. - `low`: The second lowest severity. - `info`: The lowest severity, for informational findings. Allowed enum values: `critical`, `high`, `medium`, `low`, `info`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| attributes   | version [*required*]        | int64   | The number of the current revision, starting at `1`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| data         | id [*required*]             | string  | The ID of the rule, for example `custom-terraform-aws-s3-bucket-without-encryption`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| data         | type [*required*]           | enum    | The type of the resource. The value is always `iac_custom_rules`. Allowed enum values: `iac_custom_rules`. Default: `iac_custom_rules`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
{% /tab %}

{% tab label="Example" %}
```json
{
  "data": {
    "attributes": {
      "category": "encryption",
      "created_at": 1793271987422,
      "created_by_id": "00000000-0000-0000-0000-000000001234",
      "cwe_id": "CWE-311",
      "description": "S3 buckets must encrypt data at rest.",
      "is_published": false,
      "modified_at": 1793271987422,
      "modified_by_id": "00000000-0000-0000-0000-000000001234",
      "name": "S3 bucket without encryption",
      "platform": "terraform",
      "provider": "aws",
      "rego_query": "package datadog\n\nDatadogPolicy contains result if {\n\tsome i, doc in input.document\n\tsome type, resources in doc.resource\n\tsome name, resource in resources\n\ttype == \"aws_s3_bucket\"\n\tnot resource.server_side_encryption_configuration\n\tresult := {\n\t\t\"documentId\": doc.id,\n\t\t\"resourceType\": type,\n\t\t\"resourceName\": name,\n\t\t\"searchKey\": sprintf(\"resource.%s.%s\", [type, name]),\n\t}\n}",
      "sample_file": "resource \"aws_s3_bucket\" \"my_bucket\" {\n  bucket = \"my-bucket\"\n}",
      "severity": "high",
      "version": 1
    },
    "id": "custom-terraform-aws-s3-bucket-without-encryption",
    "type": "iac_custom_rules"
  }
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="403" %}
Forbidden

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="404" %}
Not Found

{% tabs %}
{% tab label="Model" %}
API error response.

| Parent field | Field               | Type     | Description                                                                     |
| ------------ | ------------------- | -------- | ------------------------------------------------------------------------------- |
|              | errors [*required*] | [object] | A list of errors.                                                               |
| errors       | code                | string   | An application-specific error code.                                             |
| errors       | detail              | string   | A human-readable explanation specific to this occurrence of the error.          |
| errors       | meta                | object   | Non-standard meta-information about the error                                   |
| errors       | source              | object   | References to the source of the error.                                          |
| source       | header              | string   | A string indicating the name of a single request header which caused the error. |
| source       | parameter           | string   | A string indicating which URI query parameter caused the error.                 |
| source       | pointer             | string   | A JSON pointer to the value in the request document that caused the error.      |
| errors       | status              | string   | Status code of the response.                                                    |
| errors       | title               | string   | Short human-readable summary of the error.                                      |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    {
      "code": "invalid_request",
      "detail": "Missing required attribute in body",
      "meta": {},
      "source": {
        "header": "Authorization",
        "parameter": "limit",
        "pointer": "/data/attributes/title"
      },
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="429" %}
Too many requests

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}
{% /tabs %}

### Code Example

{% tabs %}
{% tab label="Curl" %}
```bash
# Path parameters
export rule_id="custom-terraform-aws-s3-bucket-without-encryption"

# Set your Datadog site and credentials
export DD_SITE="datadoghq.com" # Or us3.datadoghq.com, us5.datadoghq.com, datadoghq.eu, ap1.datadoghq.com, ap2.datadoghq.com, uk1.datadoghq.com, ddog-gov.com, us2.ddog-gov.com
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X GET "https://api.${DD_SITE}/api/v2/security/code_security/iac_custom_rules/${rule_id}" \
-H "Accept: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}"
```
{% /tab %}
{% /tabs %}
