writ

module
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: Apache-2.0

README

Writ

Plan, approve, and apply OpenTofu on your own server.

Writ is an open-source, self-hosted control plane for OpenTofu. Point it at a Git repository of stacks. When you or a CI job send a commit, Writ plans it on your server, waits for your team to approve that exact plan, and applies it. CI jobs and laptops never hold cloud credentials or state keys.

Writ ships as one Go binary under the Apache 2.0 license, with no limits on users, runs, or resources. A team server stores records in Postgres; local development (writ serve --dev) uses SQLite on loopback.

Writ control UI showing plans waiting for approval, active applies, failed runs, and drifted stacks.

What it does

  • Server-side plans. You or a CI job submit a commit SHA. writ serve fetches that commit from GitHub or GitLab and runs tofu plan -lock=false in an isolated Linux namespace without modifying state.
  • Plan-bound approvals. Reviewers approve a plan by its plan ID, and writ apply --remote runs that exact saved plan. Wherever an approval rule applies, the plan's author can't approve it. Approvals
  • Split cloud roles. Plans run with your plan_role (which you keep read-only). Only an approved apply, or an override with a recorded reason, gets apply_role. AWS roles and credentials
  • Secret masking. Writ strips secrets from every plan, run log, diagnostic, and state index row it stores or serves. Secrets and the mask
  • Rego policy. Writ evaluates OPA Rego policy sets at plan time and again before apply. Mandatory denials can't be overridden. Write and test policies
  • Drift checks and notifications. Writ schedules drift plans and notifies Slack or webhooks, optionally signed, on drift, failed plans or applies, completed applies, out-of-band state writes, and pending approvals. Drift checks, Notifications
  • Run isolation and egress control. On a team server, each OpenTofu step runs under a dedicated UID in private Linux namespaces, with an opt-in egress proxy. Cgroup resource limits and a seccomp filter apply where the host allows them, and writ serve --check says whether they do. Run isolation and egress
  • UI, CLI, API, imports, and MCP. Review and approve plans in the built-in web UI or script everything with --json. Generate resource and import blocks with writ import bulk, or expose read-only planning to coding agents through writ mcp. Import many objects, Use Writ with an agent

Quick start

writ serve --dev runs a single-user control plane on loopback with SQLite, no sign-in, and no cloud account.

Requirements: Linux, minisign, Git, and OpenTofu 1.13.9 on PATH.

  1. Install writ v0.1.8 (verifies the minisign signature and SHA-256 checksum, then installs to ~/.local/bin):

    curl -fsSL https://github.com/mr-karan/writ/releases/download/v0.1.8/install.sh | sh
    export PATH="$HOME/.local/bin:$PATH"
    
  2. Start the dev control plane and leave it running:

    writ serve --dev
    
  3. In a second terminal, create a repository with one stack (.tf files plus a committed .terraform.lock.hcl) and register it:

    export PATH="$HOME/.local/bin:$PATH"
    mkdir -p ~/writ-demo/app
    cd ~/writ-demo
    git init -b main
    cat > app/main.tf <<'EOF'
    terraform {
      backend "http" {}
    
      required_providers {
        random = { source = "hashicorp/random", version = "3.9.1" }
      }
    }
    
    resource "random_pet" "name" {
      length = 2
    }
    EOF
    (cd app && tofu providers lock)
    git add .
    git commit -m "one stack"
    writ repo add .
    
  4. Plan the commit and apply the plan by ID:

    $ cd app
    $ writ plan --remote
    OpenTofu 1.13.9 plan of app@dev
    
      + random_pet.name (create)
    
    Plan: 1 to add, 0 to change, 0 to destroy.
    Plan 3f613cf08763b0bf56626574288f85af for dev (app), by alice (dev), expires 2026-11-16T04:40:49Z.
    It needs no approval. Apply it with: writ apply --remote 3f613cf08763b0bf56626574288f85af
    $ writ apply --remote 3f613cf08763b0bf56626574288f85af
    OpenTofu apply of app@dev
      random_pet.name: create complete
    Apply: 1 added, 0 changed, 0 destroyed.
    State version 1 of app@dev.
    

    Output of a real run, 2026-11-15, with some lines cut.

Open the control UI link printed by writ serve --dev to inspect the plan and run in your browser. Next, follow set up Writ for a team.

Connect GitHub Actions

GitHub repository reads, webhooks, and GitHub Actions OIDC support land in the first release after v0.1.8 (see CHANGELOG.md).

Point writ serve at GitHub with a fine-grained read token (Contents: read and Metadata: read; a GitHub App is not built yet) and a github-actions OIDC issuer:

issuer "github" {
  kind     = "github-actions"
  identity = "github"
  url      = "https://token.actions.githubusercontent.com"
}

forge "github" {
  kind            = "github"
  read_token_file = "/run/secrets/writ/github_read"
}

repo {
  name    = "infra"
  forge   = "github"
  project = "acme/infra"
}

Generate the workflow (a per-stack plan matrix plus one required check named writ, skipping fork and Dependabot PRs) and matching server grants with:

writ ci github --repo infra

Each job requests its own GitHub Actions ID token and runs writ plan --remote --slot-wait 15m without a checkout or cloud keys; people approve and apply. See Set up GitHub Actions and Webhooks.

Also works with GitLab: see Add a repository and Set up GitLab CI.

Install

  • Install script: Downloads the release binary, checks its minisign signature and SHA-256, and writes ~/.local/bin/writ.
  • Container image: ghcr.io/mr-karan/writ:0.1.8 bundles writ and OpenTofu 1.13.9 for team servers.
  • Nix: nix run github:mr-karan/writ -- version, plus nixosModules.writ-serve for a NixOS host with Postgres.
  • From source: Go 1.27.3+ and just (just build writes bin/writ).
  • Release binaries: Static binaries for Linux and macOS on amd64 and arm64. macOS binaries are cross-built on Linux and haven't been tested on macOS.

See Install for commands and verification steps.

Supported platforms and limits

  • OpenTofu only. Writ runs OpenTofu 1.13.9 exclusively and doesn't run Terraform. Each stack has one state, with no tofu workspace.
  • GitHub and GitLab. GitHub (github.com or GitHub Enterprise Server, landing in the first release after v0.1.8; see CHANGELOG.md) and GitLab are the remote Git hosts Writ reads with a read-only token; there is no GitHub App yet. writ ci github and writ ci gitlab write the CI config (writ serve --dev also reads local Git directories).
  • AWS roles only. Built-in role assumption supports AWS IAM roles via STS. Other providers get credentials from provider_env secret files on the server.
  • One node, on Linux. A team writ serve runs as a single process on Linux with namespace isolation. Running a second process against the same database fails the first process's in-flight work.
  • Stand-in test suite. End-to-end tests run real OpenTofu 1.13.9 and real providers against local stand-ins in isolated namespaces; no test contacts a live cloud account.

See Supported platforms and limits for the full list and test coverage.

Documentation

Read the docs at writ.mrkaran.dev/docs or in docs/:

Contributing

Bug reports, design questions, and pull requests are welcome. Read CONTRIBUTING.md before sending a change. Report security issues privately per SECURITY.md.

License

Apache 2.0. proto/tfplugin5.proto and proto/tfplugin6.proto are copied from OpenTofu under MPL 2.0; see NOTICE.

Directories

Path Synopsis
bench
skilleval command
Command skilleval measures what the writ skill does for a coding agent on an OpenTofu repository.
Command skilleval measures what the writ skill does for a coding agent on an OpenTofu repository.
cmd
writ command
Command writ is the Writ CLI.
Command writ is the Writ CLI.
internal
addr
Package addr defines resource addresses: the path from a top-level let to a resource, such as ca_key, site.key, or files["a"].
Package addr defines resource addresses: the path from a top-level let to a resource, such as ca_key, site.key, or files["a"].
agent
Package agent holds what Writ puts into an OpenTofu repository for coding agents: the writ skill, and the section of AGENTS.md that points to it.
Package agent holds what Writ puts into an OpenTofu repository for coding agents: the writ skill, and the section of AGENTS.md that points to it.
archtest
Package archtest holds tests that enforce Writ's package boundaries.
Package archtest holds tests that enforce Writ's package boundaries.
authz
Package authz decides what a principal may do in writ serve.
Package authz decides what a principal may do in writ serve.
awsrole
Package awsrole assumes AWS roles for writ serve's runs and hands the credentials to providers.
Package awsrole assumes AWS roles for writ serve's runs and hands the credentials to providers.
awsrole/ststest
Package ststest is a stand-in for AWS STS in tests.
Package ststest is a stand-in for AWS STS in tests.
cli
Package cli implements the writ commands.
Package cli implements the writ commands.
confine
Package confine reads and writes the files of a stack or a repository, either anywhere on the file system or only beneath one directory.
Package confine reads and writes the files of a stack or a repository, either anywhere on the file system or only beneath one directory.
control
Package control is writ serve's own store: the configs it ran with, their teams and grants, the kept plans, approvals, runs, overrides, sessions, used token ids, an audit row for every API call and decision, and the state OpenTofu stacks keep on writ serve's http backend.
Package control is writ serve's own store: the configs it ran with, their teams and grants, the kept plans, approvals, runs, overrides, sessions, used token ids, an audit row for every API call and decision, and the state OpenTofu stacks keep on writ serve's http backend.
control/controltest
Package controltest opens control databases for tests: a SQLite file in the test's temporary directory always, and a scratch Postgres database when pgtest has a server.
Package controltest opens control databases for tests: a SQLite file in the test's temporary directory always, and a scratch Postgres database when pgtest has a server.
control/pgtest
Package pgtest gives tests a scratch Postgres: a socket-only server in a temporary directory, as just e2e-postgres starts one.
Package pgtest gives tests a scratch Postgres: a socket-only server in a temporary directory, as just e2e-postgres starts one.
diag
Package diag defines source positions and the diagnostics every layer of Writ reports: a class, a span, a message, and an optional fix.
Package diag defines source positions and the diagnostics every layer of Writ reports: a class, a span, a message, and an optional fix.
egress
Package egress decides where an OpenTofu run of writ serve may connect, and is the proxy the run connects through.
Package egress decides where an OpenTofu run of writ serve may connect, and is the proxy the run connects through.
forge
Package forge reads repositories where they are hosted: a project, the head of a branch, the files of a commit, and a file's content by its Git blob id.
Package forge reads repositories where they are hosted: a project, the head of a branch, the files of a commit, and a file's content by its Git blob id.
forge/forgetest
Package forgetest serves stand-ins for GitLab's and GitHub's REST APIs in a test's process.
Package forgetest serves stand-ins for GitLab's and GitHub's REST APIs in a test's process.
importer
Package importer takes over objects that already exist into OpenTofu code.
Package importer takes over objects that already exist into OpenTofu code.
mask
Package mask produces every document that leaves an OpenTofu run: the masked plan document, the rows of the state index, and the run's event streams with secrets swept out.
Package mask produces every document that leaves an OpenTofu run: the masked plan document, the rows of the state index, and the run's event streams with secrets swept out.
mcp
Package mcp serves Writ's control plane to coding agents as tools of the Model Context Protocol, over stdio.
Package mcp serves Writ's control plane to coding agents as tools of the Model Context Protocol, over stdio.
notify
Package notify delivers asynchronous notifications for writ serve events to Slack incoming webhooks and generic JSON webhooks with optional HMAC-SHA256 signing.
Package notify delivers asynchronous notifications for writ serve events to Slack incoming webhooks and generic JSON webhooks with optional HMAC-SHA256 signing.
oidc
Package oidc checks OIDC tokens for writ serve and signs people in with the team's identity provider.
Package oidc checks OIDC tokens for writ serve and signs people in with the team's identity provider.
oidc/oidctest
Package oidctest runs an OIDC issuer for tests: an HTTPS server with a discovery document and a key set, keys generated in the test, and tokens the test signs.
Package oidctest runs an OIDC issuer for tests: an HTTPS server with a discovery document and a key set, keys generated in the test, and tokens the test signs.
policy
Package policy compiles policy sets, Rego rules about OpenTofu plans, and judges one plan at one point with them.
Package policy compiles policy sets, Rego rules about OpenTofu plans, and judges one plan at one point with them.
provider
Package provider owns everything about Terraform provider binaries: finding them in the registry, pinning them in writ.lock, caching their schemas, and running them over the plugin protocol, version 5 or 6.
Package provider owns everything about Terraform provider binaries: finding them in the registry, pinning them in writ.lock, caching their schemas, and running them over the plugin protocol, version 5 or 6.
repo
Package repo turns one commit of a repository into what the control plane plans.
Package repo turns one commit of a repository into what the control plane plans.
runas
Package runas acts as an OS user with no name: it starts a process as that user, does file work as that user, and checks that a started process holds nothing of writ's.
Package runas acts as an OS user with no name: it starts a process as that user, does file work as that user, and checks that a started process holds nothing of writ's.
runner
Package runner runs writ serve's OpenTofu runs as jobs.
Package runner runs writ serve's OpenTofu runs as jobs.
schema
Package schema is Writ's own view of a provider's schema: resource types with Writ types on every attribute, refined by the annotation layer.
Package schema is Writ's own view of a provider's schema: resource types with Writ types on every attribute, refined by the annotation layer.
server
Package server is writ serve: the control plane's REST API over HTTPS.
Package server is writ serve: the control plane's REST API over HTTPS.
servetest
Package servetest starts a dev control plane inside a test's process: the real server.Server, which runs no OpenTofu, on an httptest server, with its control database in SQLite in the test's temporary directory.
Package servetest starts a dev control plane inside a test's process: the real server.Server, which runs no OpenTofu, on an httptest server, with its control database in SQLite in the test's temporary directory.
sqldb
Package sqldb owns Writ's SQL drivers: it opens SQLite files and Postgres databases behind one type, rewrites the ? placeholders that every statement is written with into Postgres's $n, and turns driver errors into an *IOError that holds no connection detail.
Package sqldb owns Writ's SQL drivers: it opens SQLite files and Postgres databases behind one type, rewrites the ? placeholders that every statement is written with into Postgres's $n, and turns driver errors into an *IOError that holds no connection detail.
tfcode
Package tfcode reads and writes the OpenTofu code of one stack for writ import: it reads the providers a stack requires and configures, and the names it declares, and it writes literals as HCL tokens.
Package tfcode reads and writes the OpenTofu code of one stack for writ import: it reads the providers a stack requires and configures, and the names it declares, and it writes literals as HCL tokens.
tfplugin6
Package tfplugin6 will hold the Go code generated from proto/tfplugin6.proto by `just proto` (protoc-gen-go and protoc-gen-go-grpc).
Package tfplugin6 will hold the Go code generated from proto/tfplugin6.proto by `just proto` (protoc-gen-go and protoc-gen-go-grpc).
tfstate
Package tfstate serves OpenTofu's http state backend to the runs of writ serve.
Package tfstate serves OpenTofu's http state backend to the runs of writ serve.
tofu
Package tofu runs OpenTofu for one stack: init, a saved plan, its JSON, and the apply of a saved plan, each run in a scratch directory of its own, with bounded time and output, and as the run's own uid when it has one.
Package tofu runs OpenTofu for one stack: init, a saved plan, its JSON, and the apply of a saved plan, each run in a scratch directory of its own, with bounded time and output, and as the run's own uid when it has one.
types
Package types is the type model of provider schemas: scalars, lists, maps, records, string-literal unions, typed references (Id, Pem, Arn, and Name), resource types, and the secret taint.
Package types is the type model of provider schemas: scalars, lists, maps, records, string-literal unions, typed references (Id, Pem, Arn, and Name), resource types, and the secret taint.
ui
Package ui is the control UI: the HTML pages that writ serve renders under /ui/ for people signed in with the team's identity provider.
Package ui is the control UI: the HTML pages that writ serve renders under /ui/ for people signed in with the team's identity provider.
value
Package value is the value model of the importer and the provider client.
Package value is the value model of the importer and the provider client.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL