A Terraform / OpenTofu provider that builds container images and filesystem
artifacts from a Dockerfile using BuildKit
directly over its gRPC API — without driving the Docker CLI, the Docker
daemon as a build mechanism, or local-exec.
It speaks to a local or remote buildkitd, can auto-discover the BuildKit
embedded in OrbStack / Docker Desktop / Colima, and can optionally supervise an
embedded rootless buildkitd on Linux.
buildkit_image— build and push multi-platform images to one or more registries in a single build. Build args, labels, build secrets, SSH agent forwarding, registry/local/gha cache import & export, and SBOM + provenance attestations.buildkit_artifact— build a Dockerfile and extract a file (as a zip) or a directory tree from the built stage onto the host filesystem. Ideal for producing deployment packages (e.g. AWS Lambda zips) with nodocker cpand nolocal-exec.buildkit_context— dockerignore-aware SHA256 of a build context, for use as a stable, plan-time idempotency key.buildkit_registry_image/buildkit_images— resolve or query images already in a registry.- Endpoint discovery — explicit address,
BUILDKIT_HOST, the Docker-engine embedded BuildKit/grpc, local sockets, or an embedded rootless buildkitd. - Registry auth — explicit
registry_authblocks and/or the host Docker config (~/.docker/config.json) with credential helpers. - Built on the Terraform Plugin Framework (protocol 6); works with Terraform and OpenTofu.
| Capability | this provider | RutledgePaulV/buildkit |
kreuzwerker/docker |
|---|---|---|---|
| Build + push images via BuildKit | yes | yes | via daemon |
| Multi-platform images | yes | yes | limited |
| Build secrets / SSH forwarding | yes | yes | limited |
| SBOM / provenance attestations | yes | no | no |
| Cache import/export (registry/local/gha) | yes | no | limited |
| Extract a file/dir artifact to the host | yes | no | no |
| Endpoint auto-discovery | yes | no | n/a |
| Embedded rootless buildkitd (Linux) | yes | no | no |
| Docker config.json + credential helpers | yes | no | yes |
| Plugin Framework (protocol 6) | yes | SDKv2 (5) | SDKv2 (5) |
terraform {
required_providers {
buildkit = {
source = "cruxstack/buildkit"
version = "~> 1.0"
}
}
}
provider "buildkit" {}resource "buildkit_image" "app" {
context = "${path.module}/app"
dockerfile = "Dockerfile"
platforms = ["linux/amd64", "linux/arm64"]
publish {
registry = "ghcr.io"
repository = "org/app"
tags = ["latest"]
}
}resource "buildkit_artifact" "lambda" {
build_context = "${path.module}/app"
target = "package"
artifact_src_path = "/tmp/package.zip"
artifact_src_type = "zip"
artifact_dst_path = "${path.module}/dist/package.zip"
}
resource "aws_lambda_function" "this" {
filename = buildkit_artifact.lambda.artifact_path
source_code_hash = buildkit_artifact.lambda.artifact_sha256
# ...
}The two resources differ on terraform destroy:
buildkit_imageis non-destructive: destroying it only drops the resource from state. Pushed images are left untouched in the registry.buildkit_artifactremoves the produced file/directory from the host on destroy.
A Linux container runtime is required to execute a Dockerfile's RUN steps, so
the provider needs a buildkitd to talk to. It is resolved in this order:
buildkit_address(provider config) —tcp://,unix://, or connection helpers likedocker-container://.BUILDKIT_HOSTenvironment variable.- (auto-discovery) Docker-engine embedded BuildKit via the daemon
/grpcendpoint (OrbStack / Docker Desktop / Colima). - (auto-discovery) Conventional local
buildkitdsockets. - (opt-in, Linux)
embedded_buildkitd = true— supervise abuildkitdbinary found on PATH for the lifetime of the provider.
Set buildkit_autodiscover = false to require an explicit address /
BUILDKIT_HOST (recommended for hermetic CI).
Pushing images requires a
buildkitdwhose worker can export images (a standalonemoby/buildkitdaemon, or a containerd-image-store worker). The Docker-engine/grpcBuildKit used by Docker Desktop does not support theimageexporter; use it forbuildkit_artifactand local builds, and a standalone daemon for pushing.
provider "buildkit" {
# explicit credentials (take precedence per-host)
registry_auth {
address = "ghcr.io"
username = "my-user"
password = var.ghcr_token
}
# also consult ~/.docker/config.json + credential helpers (default true)
docker_config = true
}Generated documentation lives under docs/ and on the Terraform and
OpenTofu registries:
- Resources:
buildkit_image,buildkit_artifact - Data sources:
buildkit_context,buildkit_registry_image,buildkit_images
See CONTRIBUTING.md. Common tasks:
make build # build the provider
make test # unit tests
make testacc # acceptance tests (TF_ACC=1 + a BuildKit endpoint)
make docs # regenerate docs/