> ## Documentation Index
> Fetch the complete documentation index at: https://docs.forge.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# forge_resource_policy

> A Forge Resource policy using native conditions or forge.rego.v1 match logic.

# forge\_resource\_policy (Resource)

A Resource policy controls authenticated HTTP/HTTPS, PostgreSQL, MySQL, and
Redis operations without mixing Resource fields into Access or Content
policies. HTTP bodies and PostgreSQL/MySQL results support typed transformations;
Redis policies match command metadata and can allow, block, or require approval,
with `enforcement = "monitor"` available to observe matches without enforcing the
outcome.

```hcl theme={"system"}
resource "forge_resource_policy" "protect_customer_results" {
  id                    = "protect-customer-results"
  name                  = "Protect customer result data"
  resources             = [forge_resource.production_database.id]
  action                = "redact"
  data_target           = "postgres_result"
  redaction_strategy    = "constant"
  redaction_replacement = "[REDACTED]"
  redaction_paths       = ["$.email"]

  module = <<-REGO
    package forge.resource
    match := {"matched": input.request.postgres.command == "SELECT"}
  REGO
}
```

MySQL result redaction uses `data_target = "mysql_result"` with the same row
and column-path model. Redis has no result transformation target; govern its
commands directly, including approval:

```hcl theme={"system"}
resource "forge_resource_policy" "approve_redis_deletes" {
  id            = "approve-redis-deletes"
  name          = "Approve Redis deletes"
  resources     = [forge_resource.production_cache.id]
  action        = "require_approval"
  approval_mode = "admin_approval"
  conditions    = { field = "request.redis.command", op = "eq", value = "DEL" }
}
```

Automatically routed traffic can be limited to products from the Forge
catalog. Every recognized product in the process ancestry is considered, so a
nested tool cannot hide its parent product:

```hcl theme={"system"}
resource "forge_resource_policy" "block_codex_production_deletes" {
  id        = "block-codex-production-deletes"
  name      = "Block Codex production deletes"
  resources = [forge_resource.production_database.id]
  action    = "block"
  message   = "Use the reviewed migration workflow for production deletes."

  conditions = {
    all = [
      { field = "product.id", op = "in", value = ["openai/codex"] },
      { field = "request.postgres.command", op = "eq", value = "DELETE" }
    ]
  }
}
```

`product.id` is unavailable for direct Resource gateway connections because
they do not carry trusted endpoint process context. Product-scoped rules do not
match those connections; other applicable Resource rules still do.

The Rego module is only the match predicate. Keep `action`, `data_target`, and
redaction, filtering, or approval settings in typed Terraform attributes.

## Schema

### Required

* `action` (String) Allow, block, flag for review, redact, filter, or require approval for matching Resource operations.
* `id` (String) Stable policy identifier.
* `name` (String)

### Optional

* `acknowledge_broad_scope` (Boolean) Required before enabling a broad disruptive Resource policy.
* `compliance_frameworks` (Set of String)
* `conditions` (Dynamic) A native HCL Resource condition using Resource fields, including `product.id` for originating products on automatically routed traffic, `process.id`, and `destination.domain`; `field`/`op`/`value` leaves; `all`, `any`, and `not`; or prior-event, sequence, count, and distinct-value conditions. Set exactly one of `conditions` or `module`.
* `description` (String)
* `data_target` (String) Data transformed by `redact` or `filter`: `http_request_body`, `http_response_body`, `postgres_result`, or `mysql_result`.
* `devices` (Set of String)
* `enabled` (Boolean) (default: `true`)
* `enforcement` (String) `enforce` applies matching outcomes; `monitor` records what would have happened while allowing traffic. (default: `enforce`)
* `except` (Dynamic) One anonymous exception. Prefer `exceptions` for named, reasoned, and optionally expiring exceptions.
* `exceptions` (Dynamic) Named scoped exceptions with an ID, reason, optional expiration, and Resource conditions.
* `group_directory_ids` (Map of String) Optional map from a configured group name to a Forge directory ID, used only to disambiguate duplicate exact matches.
* `groups` (Set of String)
* `labels` (Set of String)
* `message` (String) Customer-facing guidance returned with a block, approval, or fail-closed transformation.
* `module` (String) A `forge.rego.v1` module with the `data.forge.resource.match` entrypoint. Set exactly one of `module` or `conditions`.
* `rationale` (String)
* `approval_mode` (String) Approval mode for `require_approval`: `admin_approval` or `self_serve`.
* `filter_collection_path` (String) Collection whose matching entries are removed by `filter`.
* `filter_on_unavailable` (String) `allow` or `block` when filtering cannot be applied safely.
* `filter_operator` (String) Comparison used by `filter`.
* `filter_path` (String) Value tested within each collection entry.
* `filter_value` (Dynamic) Typed value compared by `filter`.
* `redaction_apply_to` (String) Set to `matches` for match-only redaction.
* `redaction_fake_subtype` (String) Synthetic value type used by `fake` redaction.
* `redaction_keep_end` (Number) Trailing characters retained by `partial` redaction.
* `redaction_keep_start` (Number) Leading characters retained by `partial` redaction.
* `redaction_mask_character` (String) Character used by `partial` redaction.
* `redaction_paths` (Set of String) JSON paths or PostgreSQL/MySQL column paths transformed by `redact`.
* `redaction_pattern` (String) Pattern used for match-only redaction.
* `redaction_replacement` (String) Replacement used by `constant` redaction.
* `redaction_salt_ref` (String) Stable salt reference used by `hash` redaction.
* `redaction_strategy` (String) `constant`, `partial`, `hash`, `nullify`, or `fake`.
* `resources` (Set of String) Stable Forge Resource IDs governed by this policy.
* `service_accounts` (Set of String)
* `severity` (String) (default: `medium`)
* `use_cases` (Set of String)
* `user_directory_ids` (Map of String) Optional map from a configured user email to a Forge directory ID, used only to disambiguate duplicate exact matches.
* `users` (Set of String)

### Read-Only

* `current_revision` (Number)
* `definition_sha256` (String)
* `module_sha256` (String)
* `validation_token` (String, Sensitive) Short-lived server plan binding. Managed internally by the provider and never authored.

## Import

Import a Resource policy by its stable policy ID:

```sh theme={"system"}
terraform import forge_resource_policy.production_database production-database-deletes
```

Native conditions and `forge.resource` Rego input support proven caller
identity, device and process IDs, originating product IDs for automatically
routed traffic, destination domain, Resource identity and
protocol, HTTP request metadata, PostgreSQL and MySQL query metadata, and Redis
user, database, and command metadata. Rego defines
only the match predicate; action, data target, redaction/filter settings, and
approval mode remain typed Terraform attributes.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.