ghoten

module
v1.12.2 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: MPL-2.0

README

Ghoten

Name origin: Ghoten blends GhitHub and OpenTofu, with a nod to Goten from Dragon Ball Z.

Test Release

An OpenTofu fork with a native ORAS backend for OCI registry state storage.

Ghoten adds a first-class oras backend that speaks the OCI distribution protocol directly. Use an OCI-compatible registry — such as GitHub Container Registry (GHCR) — as the durable store for your infrastructure state, without external HTTP backends or third-party wrappers.

Upstream: Ghoten tracks OpenTofu and carries only the additions required for the ORAS backend. All standard OpenTofu functionality is preserved.


Key Features

  • Native OCI storage — State, locks, and versions stored as OCI artifacts via ORAS
  • Atomic locking — Generation semantics prevent concurrent lock holders
  • Stale lock cleanup (TTL) — Crashed-process locks auto-cleared on next acquisition
  • State versioning — Historical snapshots with async background retention cleanup
  • Gzip compression — Optional state compression before pushing
  • Rate limiting & retry — Token-bucket limiter + exponential backoff for transient errors
  • GHCR deletion fallback — Falls back to GitHub Packages API when OCI DELETE returns 405
  • Docker credential helpers — Reuses Docker config with caching and singleflight deduplication
  • OpenTelemetry tracing — All OCI HTTP calls instrumented via otelhttp
  • Client-side encryption — Combine with OpenTofu state encryption

Installation

# Build from source
git clone https://github.com/vmvarela/ghoten.git && cd ghoten
make build

# Or pull Docker images
docker pull ghcr.io/vmvarela/ghoten:<version>          # Alpine (git/bash/openssh)
docker pull ghcr.io/vmvarela/ghoten:<version>-minimal   # Scratch (binary only)

Pre-built binaries for 17 platform combinations are available on the Releases page.


GitHub Action

Run Ghoten in your workflows with zero configuration — the action installs the binary, authenticates to GHCR, initializes the ORAS backend, and runs your command with PR comments and Job Summaries out of the box.

Your HCL only needs an empty backend block — the action injects repository, compression, lock_ttl, and max_versions automatically:

terraform {
  backend "oras" {}
}
Quick Start
on: pull_request

jobs:
  plan:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
      pull-requests: write
    steps:
      - uses: actions/checkout@v6
      - uses: vmvarela/ghoten@v1

The action will install Ghoten, authenticate to GHCR, init with the ORAS backend (ghcr.io/<owner>/tf-state.<repo>), run ghoten plan, post a PR comment, and generate a Job Summary.

Plan on PR, Apply on Merge
name: Infrastructure
on:
  pull_request:
  push:
    branches: [main]

jobs:
  plan:
    if: github.event_name == 'pull_request'
    runs-on: ubuntu-latest
    permissions: { contents: read, packages: write, pull-requests: write }
    steps:
      - uses: actions/checkout@v6
      - uses: vmvarela/ghoten@v1

  apply:
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    permissions: { contents: read, packages: write }
    steps:
      - uses: actions/checkout@v6
      - uses: vmvarela/ghoten@v1
        with:
          command: apply
Inputs
Input Default Description
command plan plan, apply, destroy, fmt, validate
working-directory . Path to HCL configuration files
workspace default Terraform workspace
var-file Path to a .tfvars file
variables Newline-separated key=value pairs
backend-repository ghcr.io/<owner>/tf-state.<repo> ORAS backend OCI repository
backend-config Additional -backend-config key=value pairs
github-token ${{ github.token }} Token for GHCR auth and PR comments
comment-on-pr true Post output as PR comment
add-summary true Generate Job Summary
args Additional CLI arguments
init-args Additional arguments for ghoten init
auto-init true Automatically run ghoten init
compression gzip State compression: none or gzip
lock-ttl 300 Lock TTL in seconds
max-versions 10 State versions to retain
fmt-check false Use -check mode for fmt
version (auto) Ghoten version to install
Outputs
Output Description
exitcode Exit code of the command
stdout Full command output
plan-has-changes true/false — whether plan detected changes
plan-file Path to binary plan file (when command=plan)
fmt-result true/false — whether fmt found differences
More Examples
# Format check
- uses: vmvarela/ghoten@v1
  with: { command: fmt, fmt-check: true }

# With variables
- uses: vmvarela/ghoten@v1
  with:
    command: plan
    var-file: prod.tfvars
    variables: |
      region=eu-west-1
      environment=production

# Custom backend repository
- uses: vmvarela/ghoten@v1
  with:
    command: plan
    backend-repository: ghcr.io/myorg/custom-state-repo

# Plan → Apply in same job
- uses: vmvarela/ghoten@v1
  id: plan
  with: { command: plan }
- uses: vmvarela/ghoten@v1
  if: steps.plan.outputs.plan-has-changes == 'true'
  with: { command: apply }
Permissions
Permission Required for
contents: read Repository checkout
packages: write ORAS backend (read/write/delete state on GHCR)
pull-requests: write PR comments (optional)

packages: write covers version retention cleanup. The separate delete:packages permission is only needed to delete entire packages from GHCR.


ORAS Backend

Configuration
Parameter Type Default Env Var Description
repository string "" TF_BACKEND_ORAS_REPOSITORY OCI repository (<registry>/<repo>). Required.
compression string "none" none or gzip
insecure bool false Skip TLS verification
ca_file string "" PEM-encoded CA bundle path
retry_max int 2 TF_BACKEND_ORAS_RETRY_MAX Retries for transient errors
retry_wait_min int 1 TF_BACKEND_ORAS_RETRY_WAIT_MIN Min backoff (seconds)
retry_wait_max int 30 TF_BACKEND_ORAS_RETRY_WAIT_MAX Max backoff (seconds)
lock_ttl int 0 TF_BACKEND_ORAS_LOCK_TTL Lock TTL (seconds). > 0 enables stale-lock clearing
rate_limit int 0 TF_BACKEND_ORAS_RATE_LIMIT Max requests/sec. 0 disables
rate_limit_burst int 0 TF_BACKEND_ORAS_RATE_LIMIT_BURST Burst size
max_versions int 0 State versions to retain. 0 disables
Usage Examples

With the GitHub Action — just declare an empty backend; the action provides everything via env vars and -backend-config:

terraform {
  backend "oras" {}
}

Standalone — minimal:

terraform {
  backend "oras" {
    repository = "ghcr.io/acme/infra-state"
  }
}

Standalone — production-ready:

terraform {
  backend "oras" {
    repository   = "ghcr.io/myorg/infra-state"
    compression  = "gzip"
    lock_ttl     = 300
    max_versions = 10
  }

  encryption {
    key_provider "pbkdf2" "main" {
      passphrase = var.state_passphrase
    }
    method "aes_gcm" "main" {
      key_provider = key_provider.pbkdf2.main
    }
    state { method = method.aes_gcm.main }
    plan  { method = method.aes_gcm.main }
  }
}

Tip: For production, prefer a KMS-backed key provider (AWS KMS, GCP KMS, etc.) over PBKDF2.

Authentication

Credentials are discovered in order:

  1. Docker credential helpers — Docker config / credential store (cached, singleflight-deduplicated)
  2. CLI host credentials — OpenTofu/Terraform login tokens (ghoten login)
How State Is Stored

Tags act as stable references inside the OCI repository:

Purpose Tag pattern
State state-<workspace>
Lock locked-<workspace>
Version state-<workspace>-v<N>

If the workspace name is not a valid OCI tag, a ws-<sha256> form is used instead, with the real name persisted in OCI annotations.

Wire format details

State objects (ORAS manifest v1.1):

  • artifactType: application/vnd.terraform.state.v1
  • Layer: application/vnd.terraform.statefile.v1 (or +gzip)
  • Annotations: org.terraform.workspace, org.terraform.state.updated_at

Lock objects:

  • artifactType: application/vnd.terraform.lock.v1
  • Annotations: org.terraform.workspace, org.terraform.lock.id, org.terraform.lock.info, org.terraform.lock.generation
Security
  • Enable client-side encryption — encrypts state before it leaves your machine
  • Keep the repository private with least-privilege tokens
  • Prefer registries with encryption at rest and audit trails

Note: Primarily tested against GHCR. Other OCI registries should work but are not yet validated.


Testing

go test ./...                                        # Full suite
go test ./internal/backend/remote-state/oras/...     # ORAS backend (in-memory fake registry)

Troubleshooting

Problem Solution
"unauthorized" / "denied" Verify docker login <registry>. For GHCR: read:packages + write:packages (+ delete:packages if retention enabled)
Lock stuck after crash Set lock_ttl = 300 — next run auto-clears it. Or delete locked-<workspace> tag manually
Version deletion fails on GHCR Backend falls back to GitHub Packages API automatically. Ensure delete:packages permission
Debug output TF_LOG=DEBUG ghoten plan

Contributing

Security

Report vulnerabilities via GitHub Security Advisories. See SECURITY.md.

License

Mozilla Public License 2.0

Directories

Path Synopsis
cmd
ghoten command
internal
addrs
Package addrs contains types that represent "addresses", which are references to specific objects within a Ghoten configuration or state.
Package addrs contains types that represent "addresses", which are references to specific objects within a Ghoten configuration or state.
backend
Package backend provides interfaces that the CLI uses to interact with Ghoten.
Package backend provides interfaces that the CLI uses to interact with Ghoten.
backend/init
Package init contains the list of backends that can be initialized and basic helper functions for initializing those backends.
Package init contains the list of backends that can be initialized and basic helper functions for initializing those backends.
backend/remote-state/gcs
Package gcs implements remote storage of state on Google Cloud Storage (GCS).
Package gcs implements remote storage of state on Google Cloud Storage (GCS).
checks
Package checks contains the models for representing various kinds of declarative condition checks that can be defined in a Ghoten module and then evaluated and reported by Ghoten Core during plan and apply operations.
Package checks contains the models for representing various kinds of declarative condition checks that can be defined in a Ghoten module and then evaluated and reported by Ghoten Core during plan and apply operations.
command/cliconfig
Package cliconfig has the types representing and the logic to load CLI-level configuration settings.
Package cliconfig has the types representing and the logic to load CLI-level configuration settings.
command/cliconfig/ociauthconfig
Package ociauthconfig contains types used for describing OCI authentication settings, and helpers for discovering such settings from container engine configuration files as described in https://github.com/containers/image/blob/main/docs/containers-auth.json.5.md .
Package ociauthconfig contains types used for describing OCI authentication settings, and helpers for discovering such settings from container engine configuration files as described in https://github.com/containers/image/blob/main/docs/containers-auth.json.5.md .
command/cliconfig/svcauthconfig
Package svcauthconfig contains some helper functions and types to support the cliconfig package's use of github.com/opentofu/svchost/svcauth, which is our mechanism for representing the policy for authenticating to Ghoten-native services such as implementations Ghoten's provider registry protocol.
Package svcauthconfig contains some helper functions and types to support the cliconfig package's use of github.com/opentofu/svchost/svcauth, which is our mechanism for representing the policy for authenticating to Ghoten-native services such as implementations Ghoten's provider registry protocol.
command/clistate
Package state exposes common helpers for working with state from the CLI.
Package state exposes common helpers for working with state from the CLI.
command/e2etest
Package e2etest contains a set of tests that run against a real Ghoten binary, compiled on the fly at the start of the test run.
Package e2etest contains a set of tests that run against a real Ghoten binary, compiled on the fly at the start of the test run.
command/e2etest/fakeocireg
Package fakeocireg provides a minimal, read-only implementation of the OCI Distribution protocol that interacts with a local filesystem directory.
Package fakeocireg provides a minimal, read-only implementation of the OCI Distribution protocol that interacts with a local filesystem directory.
command/format
Package format contains helpers for formatting various Ghoten structures for human-readable output.
Package format contains helpers for formatting various Ghoten structures for human-readable output.
command/jsonchecks
Package jsonchecks implements the common JSON representation of check results/statuses that we use across both the JSON plan and JSON state representations.
Package jsonchecks implements the common JSON representation of check results/statuses that we use across both the JSON plan and JSON state representations.
command/jsonconfig
Package jsonconfig implements methods for outputting a configuration snapshot in machine-readable json format
Package jsonconfig implements methods for outputting a configuration snapshot in machine-readable json format
command/jsonentities
Package jsonentities contains the entities for representing a few common resources used around the json* packages.
Package jsonentities contains the entities for representing a few common resources used around the json* packages.
command/jsonformat/computed
Package computed contains types that represent the computed diffs for Ghoten blocks, attributes, and outputs.
Package computed contains types that represent the computed diffs for Ghoten blocks, attributes, and outputs.
command/jsonformat/structured
Package structured contains the structured representation of the JSON changes returned by the jsonplan package.
Package structured contains the structured representation of the JSON changes returned by the jsonplan package.
command/jsonplan
Package jsonplan implements methods for outputting a plan in a machine-readable json format
Package jsonplan implements methods for outputting a plan in a machine-readable json format
command/jsonprovider
Package jsonprovider contains types and functions to marshal Ghoten provider schemas into a json formatted output.
Package jsonprovider contains types and functions to marshal Ghoten provider schemas into a json formatted output.
command/jsonstate
Package jsonstate implements methods for outputting a state in a machine-readable json format
Package jsonstate implements methods for outputting a state in a machine-readable json format
command/workdir
Package workdir models the various local artifacts and state we keep inside a Ghoten "working directory".
Package workdir models the various local artifacts and state we keep inside a Ghoten "working directory".
configs
Package configs contains types that represent Ghoten configurations and the different elements thereof.
Package configs contains types that represent Ghoten configurations and the different elements thereof.
configs/configload
Package configload knows how to install modules into the .terraform/modules directory and to load modules from those installed locations.
Package configload knows how to install modules into the .terraform/modules directory and to load modules from those installed locations.
configs/configschema
Package configschema contains types for describing the expected structure of a configuration block whose shape is not known until runtime.
Package configschema contains types for describing the expected structure of a configuration block whose shape is not known until runtime.
dag
depsfile
Package depsfile contains the logic for reading and writing Ghoten's dependency lock and development override configuration files.
Package depsfile contains the logic for reading and writing Ghoten's dependency lock and development override configuration files.
e2e
encryption/keyprovider/pbkdf2
Package pbkdf2 contains a key provider that takes a passphrase and emits a PBKDF2 hash of the configured length.
Package pbkdf2 contains a key provider that takes a passphrase and emits a PBKDF2 hash of the configured length.
encryption/keyprovider/static
Package static contains a key provider that emits a static key.
Package static contains a key provider that emits a static key.
encryption/keyprovider/xor
Package xor contains a key provider that combines two other keys.
Package xor contains a key provider that combines two other keys.
engine/internal/exec
Package exec contains the models and main interface used for apply phase execution.
Package exec contains the models and main interface used for apply phase execution.
engine/internal/execgraph/execgraphproto
Package execgraphproto contains just the protocol buffers models we use for marshaling and unmarshaling execution graphs.
Package execgraphproto contains just the protocol buffers models we use for marshaling and unmarshaling execution graphs.
engine/planning
Package planning implements a planning engine for Ghoten, which takes a prior state and a configuration instance (which can be evaluated to produce a desired state) and proposes a set of changes to make to bring the remote system closer to convergence with the desired state.
Package planning implements a planning engine for Ghoten, which takes a prior state and a configuration instance (which can be evaluated to produce a desired state) and proposes a set of changes to make to bring the remote system closer to convergence with the desired state.
experiments
Package experiments contains the models and logic for opt-in experiments that can be activated for a particular Ghoten module.
Package experiments contains the models and logic for opt-in experiments that can be activated for a particular Ghoten module.
genconfig
Package genconfig implements config generation from provided state values.
Package genconfig implements config generation from provided state values.
getmodules
Package getmodules contains the low-level functionality for fetching remote module packages.
Package getmodules contains the low-level functionality for fetching remote module packages.
getproviders
Package getproviders is the lowest-level provider automatic installation functionality.
Package getproviders is the lowest-level provider automatic installation functionality.
initwd
Package initwd contains various helper functions used by the "tofu init" command to initialize a working directory.
Package initwd contains various helper functions used by the "tofu init" command to initialize a working directory.
ipaddr
Package ipaddr is a fork of a subset of the Go standard "net" package which retains parsing behaviors from Go 1.16 or earlier.
Package ipaddr is a fork of a subset of the Go standard "net" package which retains parsing behaviors from Go 1.16 or earlier.
lang
Package lang deals with the runtime aspects of Ghoten's configuration language, with concerns such as expression evaluation.
Package lang deals with the runtime aspects of Ghoten's configuration language, with concerns such as expression evaluation.
lang/blocktoattr
Package blocktoattr includes some helper functions that can perform preprocessing on a HCL body where a configschema.Block schema is available in order to allow list and set attributes defined in the schema to be optionally written by the user as block syntax.
Package blocktoattr includes some helper functions that can perform preprocessing on a HCL body where a configschema.Block schema is available in order to allow list and set attributes defined in the schema to be optionally written by the user as block syntax.
lang/eval
Package eval aims to encapsulate the details of evaluating the objects in an overall configuration, including all of the expressions written inside their declarations, in a way that can be reused across various different phases of execution.
Package eval aims to encapsulate the details of evaluating the objects in an overall configuration, including all of the expressions written inside their declarations, in a way that can be reused across various different phases of execution.
lang/eval/internal/ghoten2024
Package tofu2024 contains the "module compiler" implementation for the first edition of the Ghoten language, established with Ghoten v1.6 in 2024 and then gradually evolved in backward-compatible ways.
Package tofu2024 contains the "module compiler" implementation for the first edition of the Ghoten language, established with Ghoten v1.6 in 2024 and then gradually evolved in backward-compatible ways.
lang/exprs
Package exprs contains supporting code for expression evaluation.
Package exprs contains supporting code for expression evaluation.
lang/globalref
Package globalref is home to some analysis algorithms that aim to answer questions about references between objects and object attributes across an entire configuration.
Package globalref is home to some analysis algorithms that aim to answer questions about references between objects and object attributes across an entire configuration.
lang/grapheval
Package grapheval contains some low-level helpers for coordinating interdependent work happening across different parts of the system, including detection and reporting of self-dependency problems that would otherwise cause a deadlock.
Package grapheval contains some low-level helpers for coordinating interdependent work happening across different parts of the system, including detection and reporting of self-dependency problems that would otherwise cause a deadlock.
lang/lint
Package lint contains a collection of helpers for performing "lint-like" checks to try to detect configuration constructs that are valid but nonetheless very likely to be a mistake.
Package lint contains a collection of helpers for performing "lint-like" checks to try to detect configuration constructs that are valid but nonetheless very likely to be a mistake.
lang/types
Package types contains non-standard cty types used only within Ghoten.
Package types contains non-standard cty types used only within Ghoten.
legacy/hcl2shim
Package hcl2shim contains a small number of "shimming" utilities that the other packages under internal/legacy use to adapt from HCL 2 concepts to legacy concepts.
Package hcl2shim contains a small number of "shimming" utilities that the other packages under internal/legacy use to adapt from HCL 2 concepts to legacy concepts.
legacy/helper/acctest
Package acctest contains for Ghoten Acceptance Tests
Package acctest contains for Ghoten Acceptance Tests
legacy/helper/schema
Package schema is a legacy package that used to represent the SDK, which is now its own library external to Ghoten Core https://github.com/hashicorp/terraform-plugin-sdk Some of it is still used by Ghoten's remote state backends, but this entire package should be removed in the future.
Package schema is a legacy package that used to represent the SDK, which is now its own library external to Ghoten Core https://github.com/hashicorp/terraform-plugin-sdk Some of it is still used by Ghoten's remote state backends, but this entire package should be removed in the future.
modsdir
Package modsdir is an internal package containing the model types used to represent the manifest of modules in a local modules cache directory.
Package modsdir is an internal package containing the model types used to represent the manifest of modules in a local modules cache directory.
plans
Package plans contains the types that are used to represent Ghoten plans.
Package plans contains the types that are used to represent Ghoten plans.
plans/internal/planproto
Package planproto is home to the Go stubs generated from the tfplan protobuf schema.
Package planproto is home to the Go stubs generated from the tfplan protobuf schema.
plans/objchange
Package objchange deals with the business logic of taking a prior state value and a config value and producing a proposed new merged value, along with other related rules in this domain.
Package objchange deals with the business logic of taking a prior state value and a config value and producing a proposed new merged value, along with other related rules in this domain.
plans/planfile
Package planfile deals with the file format used to serialize plans to disk and then deserialize them back into memory later.
Package planfile deals with the file format used to serialize plans to disk and then deserialize them back into memory later.
plugin/mock_proto
Package mock_tfplugin5 is a generated GoMock package.
Package mock_tfplugin5 is a generated GoMock package.
plugin6/mock_proto
Package mock_tfplugin6 is a generated GoMock package.
Package mock_tfplugin6 is a generated GoMock package.
provider-simple
simple provider a minimal provider implementation for testing
simple provider a minimal provider implementation for testing
provider-simple-v6
simple provider a minimal provider implementation for testing
simple provider a minimal provider implementation for testing
providercache
Package providercache contains the logic for auto-installing providers from packages obtained elsewhere, and for managing the local directories that serve as global or single-configuration caches of those auto-installed providers.
Package providercache contains the logic for auto-installing providers from packages obtained elsewhere, and for managing the local directories that serve as global or single-configuration caches of those auto-installed providers.
providers
Package providers contains the interface and primary types required to implement a Ghoten resource provider.
Package providers contains the interface and primary types required to implement a Ghoten resource provider.
provisioners
Package provisioners contains the interface and primary types to implement a Ghoten resource provisioner.
Package provisioners contains the interface and primary types to implement a Ghoten resource provisioner.
repl
Package repl provides the structs and functions necessary to run REPL for Ghoten.
Package repl provides the structs and functions necessary to run REPL for Ghoten.
replacefile
Package replacefile is a small helper package focused directly at the problem of atomically "renaming" one file over another one.
Package replacefile is a small helper package focused directly at the problem of atomically "renaming" one file over another one.
states
Package states contains the types that are used to represent Ghoten states.
Package states contains the types that are used to represent Ghoten states.
states/statefile
Package statefile deals with the file format used to serialize states for persistent storage and then deserialize them into memory again later.
Package statefile deals with the file format used to serialize states for persistent storage and then deserialize them into memory again later.
states/statemgr
Package statemgr defines the interfaces and some supporting functionality for "state managers", which are components responsible for writing state to some persistent storage and then later retrieving it.
Package statemgr defines the interfaces and some supporting functionality for "state managers", which are components responsible for writing state to some persistent storage and then later retrieving it.
terminal
Package terminal encapsulates some platform-specific logic for detecting if we're running in a terminal and, if so, properly configuring that terminal to meet the assumptions that the rest of Ghoten makes.
Package terminal encapsulates some platform-specific logic for detecting if we're running in a terminal and, if so, properly configuring that terminal to meet the assumptions that the rest of Ghoten makes.
tfdiags
Package tfdiags is a utility package for representing errors and warnings in a manner that allows us to produce good messages for the user.
Package tfdiags is a utility package for representing errors and warnings in a manner that allows us to produce good messages for the user.
tools
protobuf-compile command
protobuf-compile is a helper tool for running protoc against all of the .proto files in this repository using specific versions of protoc and protoc-gen-go, to ensure consistent results across all development environments.
protobuf-compile is a helper tool for running protoc against all of the .proto files in this repository using specific versions of protoc and protoc-gen-go, to ensure consistent results across all development environments.
selected-go-version command
selected-go-version determines which version of Go is currently selected in the go.mod file.
selected-go-version determines which version of Go is currently selected in the go.mod file.
The version package provides a location to set the release versions for all packages to consume, without creating import cycles.
The version package provides a location to set the release versions for all packages to consume, without creating import cycles.

Jump to

Keyboard shortcuts

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