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
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.- Create a Forge service account with the Terraform policy-management preset. The token must have policy read and write scopes.
- Export the token only in the Terraform shell or CI secret store.
- Configure the provider with the target organization URL key, a stable
manager_id, and a stablemanager_instance. - Write policy resources in HCL.
- Run a connected saved plan, review it, and apply that exact plan.
- Confirm the policy in Forge Console and run a final no-op plan.
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.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.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.- Open Policies in Forge Console.
- Search for
Block unapproved AI API destination. - Confirm the row says it is managed by Terraform.
- Open the policy and confirm the action is
Block, the surface isEndpoint route, and the condition isDestination domain equals api.deepseek.com. - From a protected endpoint, run a simple request such as:
Example: Block sensitive tool use
This Content policy blocks a high-risk tool call for one group at thepre_tool checkpoint.
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.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:
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:- Read the policy’s current revision and review its definition.
- Apply
forge_policy_authority; the claim fails if the revision changed. - Keep the authority resource in state.
- Add the corresponding policy resource with the exact remote definition.
- Import it, for example:
Emergency Break glass
An organization owner can use Break glass on the console’s read-only policy view during an active incident:- Open Policies from the side navigation.
- Open the Terraform-managed policy.
- Confirm the review panel says Managed by Terraform. Console editing is locked.
- Select Break glass.
- Enter a 10–1,024 character incident reason.
- Select Detach Terraform.
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
404removes the resource from Terraform state. - Destroy records a forward-only tombstone. The same authenticated
manager_id+manager_instancecan 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
429and5xxerrors.
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
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.