Skip to main content
The Forge provider manages policies, Resources, Resource Gateways, credentials, and policy-adjacent routing. Identities, integrations, products, models, MCP servers, and skills stay server-owned and are referenced by readable names. The public provider is published in the Terraform Registry as a37ai/forge. The v0.3 release line includes signed checksums and provider packages for Darwin, Linux, and Windows on amd64 and arm64.

Configure the provider

Set FORGE_API_TOKEN to a Forge service-account token with policies:read and policies:write. endpoint defaults to https://api.forge.ai and can be supplied with FORGE_ENDPOINT. Plain HTTP is accepted only for localhost development. manager_id identifies the durable policy manager, such as a repository. manager_instance distinguishes independent deployments, such as production and staging. Keep both stable; changing them makes existing authority checks fail. The server binds manager_id and manager_instance to the authenticated service-account principal that first claims or creates the policy. Matching headers from another credential cannot read, update, release, or delete that Terraform-owned policy. The values identify state ownership; they are not secrets and do not replace token authorization. The provider checks compatibility with Forge before planning a mutation. A connected plan validates readable references, policy structure, Rego, the current revision, and policy ownership. Apply rechecks the reviewed plan and fails before changing the policy if a relevant remote value changed. The provider refreshes short-lived validation automatically at apply while keeping the exact definition, references, revision, and manager binding unchanged.

Manage Policies End To End

Use this workflow when Forge policies are owned by a security repository, reviewed in pull requests, and applied by CI.
  1. Create a Forge service account with the Terraform policy-management preset. The token must have policy read and write scopes.
  2. Export the token only in the Terraform shell or CI secret store.
  3. Configure the provider with the target organization URL key, a stable manager_id, and a stable manager_instance.
  4. Write policy resources in HCL.
  5. Run a connected saved plan, review it, and apply that exact plan.
  6. Confirm the policy in Forge Console and run a final no-op plan.
The final terraform plan -detailed-exitcode should report no changes. In Forge Console, the policy should show Terraform authority with the configured manager values. Console editing is locked for Terraform-managed policies so operators cannot accidentally fork production policy state.

Example: Deploy direct Resource access

Terraform creates the Gateway and Resource assignment, but never receives a runtime deployment credential. After apply, open the Resource Gateway in Forge Console, create its Docker Compose files, and run them in the target network. The files are shown once; their deployment credential remains valid until it is rotated by creating fresh files.
This Resource supports direct access through the customer-deployed Gateway and automatic routing from managed devices. Keep gateway_id and set transparent_routing = false for direct-only access. Forge computes access_name for direct client instructions.

Example: Protect PostgreSQL end to end

This minimal configuration wires the Gateway, Resource, destination credential, and Resource Policy. Terraform 1.11 or newer keeps the password out of plan and state through a write-only ephemeral value.
After apply, deploy the Gateway from the Console, test the credential and connection, run one allowed query and one DELETE in a non-production test database, and verify both outcomes under Live → Resources.

Example: Block an AI API destination

This Access policy blocks direct endpoint-route traffic to an unapproved AI API domain. It uses the native condition language, so it can be reviewed directly in Terraform plans and in the Forge policy editor.
After apply, validate the user-visible workflow:
  1. Open Policies in Forge Console.
  2. Search for Block unapproved AI API destination.
  3. Confirm the row says it is managed by Terraform.
  4. Open the policy and confirm the action is Block, the surface is Endpoint route, and the condition is Destination domain equals api.deepseek.com.
  5. From a protected endpoint, run a simple request such as:
The request should be blocked once the endpoint has received the current policy bundle. A normal HTTP response from the destination indicates the endpoint did not enforce this policy on that traffic path.

Example: Block sensitive tool use

This Content policy blocks a high-risk tool call for one group at the pre_tool checkpoint.
Use native conditions for straightforward comparisons and module for policy-as-code logic that needs branching, normalization, or multiple facts. Forge compiles and validates Rego on the server before mutation.

Example: Monitor production database writes

Resource Policies are separate from AI product Access Policies and agent session Content Policies. This example records PostgreSQL write attempts without blocking them during rollout: Resource is nevertheless a full policy family over the same condition, outcome, exception, revision, Rego, backtest, validation, and ownership infrastructure. Only its scope, protocol fields, monitoring mode, and capability-gated actions differ.
Review the matches under Live → Resources, then change enforcement to enforce when the scope is ready. If Terraform already tracks this rule as forge_access_policy, change the HCL type and move the existing state address before planning:
Do not remove and recreate the policy. The state move preserves its server identity, revision history, exceptions, evaluations, and ownership.

What Terraform sends to Forge

The provider uses the headless Forge API. Terraform users usually should not call these endpoints directly for policy lifecycle management because the provider handles schema conversion, readable reference resolution, retries, idempotency, validation tokens, and state. The API sequence is: Every mutating Terraform API request includes:

Resources

Typed data sources resolve one exact customer-visible selector through the same organization-scoped resolver used by connected plans: Missing and ambiguous references fail rather than selecting the first result.

Supported automation use cases

Production validation

Qualify each resource against your target Forge environment before production rollout. Use the same provider version, service-account scopes, organization, manager identity, and remote state backend that you will use in production. For every row, confirm that failed validation or ownership checks leave the remote resource unchanged, the final no-op plan is empty, and the Forge audit trail identifies the expected service account and manager.

Import IDs

Every resource imports by its stable Forge identifier: Import reads state; it never bypasses or implicitly claims policy authority.

Provider arguments

Reference

Policy Resources

Access, Content, and Resource schemas, native conditions, actions, examples, and readable references.

Gateway Profile

LLM gateway access-profile and route-plan attributes with a complete example.

Registry ACLs

MCP and skill ACL resources, parameter descriptions, and examples.

Conditions

Policy field types, exact meanings, operators, and history-aware matching.

Authority

Replacement or destroy releases the claim; it does not disable, delete, or tombstone the underlying policy.

Ownership, adoption, and import

New resources are atomically created as Terraform-managed. To adopt an existing Forge-managed policy:
  1. Read the policy’s current revision and review its definition.
  2. Apply forge_policy_authority; the claim fails if the revision changed.
  3. Keep the authority resource in state.
  4. Add the corresponding policy resource with the exact remote definition.
  5. Import it, for example:
Import never claims authority implicitly. Importing before a claim, using a different manager binding, or removing the authority resource while the policy remains in state produces an authority error. Destroying the authority resource releases ownership back to Forge; destroying a policy resource disables and tombstones the policy.

Emergency Break glass

An organization owner can use Break glass on the console’s read-only policy view during an active incident:
  1. Open Policies from the side navigation.
  2. Open the Terraform-managed policy.
  3. Confirm the review panel says Managed by Terraform. Console editing is locked.
  4. Select Break glass.
  5. Enter a 10–1,024 character incident reason.
  6. Select Detach Terraform.
Forge creates a new immutable Forge-managed revision from the definition shown in the editor, records policy_family.break_glass in the organization audit log with the owner and reason, clears the Terraform manager binding, closes the Break glass dialog, and unlocks console editing. The policy record changes from Authority: Terraform to Authority: Forge. The old Terraform state cannot silently revert the emergency revision. A subsequent Terraform refresh or plan fails with an authority conflict similar to policy is managed by forge; explicitly claim it with forge_policy_authority before import. Recovery requires a reviewed Terraform claim or transfer.

Drift, retries, and state

  • Updates use the last observed immutable revision for optimistic concurrency.
  • Refresh verifies the exact Terraform manager and restores readable selectors.
  • Remote 404 removes the resource from Terraform state.
  • Destroy records a forward-only tombstone. The same authenticated manager_id + manager_instance can recreate that resource from the same state after destroy; the server assigns the next revision and preserves the complete history. A different manager cannot reuse the tombstoned ID.
  • Reads, updates, and deletes have bounded retries for 429 and 5xx errors.
Use lifecycle { prevent_destroy = true } for policies that need a separate retirement review. Terraform state contains policy configuration, sensitive match values, and an expiring signed plan-binding token; store it in an encrypted backend with narrow access. Never put API tokens or secret material in Rego source, selector names, descriptions, or filter values. Terraform applies resources independently. A multi-resource plan is not an atomic policy bundle: earlier resources can commit while a later reference, validation, authority, or network error fails the apply. Use one remote state writer, preserve the saved plan, and run a refresh plus policy-impact review after any partial failure. This guide assumes state created with a v0.3.x provider. Review the release notes and a saved plan before upgrading earlier state. The provider rejects an incompatible Forge deployment before planning a mutation. Rego modules and readable references are validated by the target Forge server during planning. terraform validate and an offline terraform plan -refresh=false prove only HCL/provider schema validity. A connected saved plan validates references, policy semantics, revision, and manager compatibility. Apply refreshes the short-lived signature and fails without mutation if any validated fact changed.

CI workflow

Pin the provider to a reviewed compatible minor line and commit the dependency lock file. Upgrade by changing the version constraint, running terraform init -upgrade, reviewing provider checksums and the complete plan, and applying a saved plan. Do not combine a provider upgrade with unrelated policy scope or action changes. Run plans with one writer per state backend. Review policy deletions, authority changes, scope expansion, stronger consequences, Rego source changes, and gateway limits as security-sensitive changes.

Troubleshooting