Skip to content

feat!: replace docker artifact packager with cruxstack/buildkit provider - #9

Merged
sgtoj merged 1 commit into
mainfrom
feat/buildkit-artifact-provider
May 29, 2026
Merged

feat!: replace docker artifact packager with cruxstack/buildkit provider#9
sgtoj merged 1 commit into
mainfrom
feat/buildkit-artifact-provider

Conversation

@sgtoj

@sgtoj sgtoj commented May 29, 2026

Copy link
Copy Markdown
Member

Summary

Replaces the bot_artifact module (github.com/cruxstack/terraform-docker-artifact-packager) with the cruxstack/buildkit Terraform provider. The Lambda deployment package is now built from the Dockerfile via BuildKit's gRPC API instead of driving the Docker CLI/daemon through a module.

Warning

This is a major version bump when merged to main. Do not merge until the release is planned.

Changes

  • Add the cruxstack/buildkit provider to required_providers (>= 0.0.1).
  • Replace module.bot_artifact with a buildkit_artifact resource plus a buildkit_context data source. The context digest is wired into the resource triggers so rebuilds happen on content change; bot_force_rebuild_id remains supported as an additional trigger.
  • Point the Lambda at buildkit_artifact.bot.artifact_path and restore source_code_hash via buildkit_artifact.bot.artifact_sha256.
  • Preserve build args (BOT_VERSION, BOT_REPO), build target (package), and the source path (/tmp/package.zip) so the produced package is equivalent.
  • Gitignore .terraform.lock.hcl (root and nested) since this is a reusable module and consumers generate their own lock files.
  • Update README prerequisites/build description to reference BuildKit and the provider's endpoint discovery; correct bot_force_rebuild_id type to string.

State migration (no manual state rm)

Existing deployments had module.bot_artifact in state, backed by providers this module no longer uses (kreuzwerker/docker, hashicorp/archive, hashicorp/null, hashicorp/random). Without handling, removing the module from config makes Terraform/OpenTofu try to destroy those orphaned resources and fail because their providers are no longer configured — requiring a manual terraform state rm module.bot_artifact.

This PR migrates automatically:

  • Adds a removed block for module.bot_artifact with lifecycle { destroy = false }, so the next plan/apply forgets the old module from state without destroying anything.
  • Bumps required_version to >= 1.7 (minimum for removed blocks; works on both Terraform and OpenTofu 1.7+).
  • Temporarily re-declares the docker/archive/null/random providers so init succeeds for upgrading users whose state still references them.

The removed block and the legacy provider declarations are transitional and should be dropped in a follow-up release once consumers have upgraded.

Breaking changes

  • Now requires the cruxstack/buildkit provider and a reachable BuildKit endpoint instead of the terraform-docker-artifact-packager module.
  • Now requires Terraform/OpenTofu >= 1.7 (previously >= 1.3).
  • Consumers must run terraform init / tofu init to install the new provider.
  • A BuildKit endpoint must be available: auto-discovered from Docker Desktop / OrbStack / Colima, via BUILDKIT_HOST, or an embedded rootless buildkitd on Linux.
  • The artifact is now written to a fixed path (dist/package.zip) rather than a hashed filename.

Validation

  • terraform fmt -check on .tf files — clean
  • terraform init -backend=false + terraform validate — success (provider cruxstack/buildkit v0.0.1 installs and config validates)

Notes

  • The provider's README advertises ~> 1.0, but only v0.0.1 is currently published to the registry; the constraint is pinned to >= 0.0.1 accordingly. Bump to ~> 1.0 once a 1.x release is available.

@sgtoj
sgtoj force-pushed the feat/buildkit-artifact-provider branch 2 times, most recently from 2f2ac2c to eba8024 Compare May 29, 2026 11:39
Swap the bot_artifact module (github.com/cruxstack/terraform-docker-artifact-packager)
for the cruxstack/buildkit Terraform provider, which builds the Lambda
deployment package from the Dockerfile via BuildKit's gRPC API rather than
driving the Docker CLI/daemon through a module.

Changes:
- Add the cruxstack/buildkit provider to required_providers (>= 0.0.1).
- Replace module.bot_artifact with a buildkit_artifact resource plus a
  buildkit_context data source. The context digest is wired into the
  resource triggers so rebuilds happen on content change; bot_force_rebuild_id
  remains supported as an additional trigger.
- Point the Lambda at buildkit_artifact.bot.artifact_path and restore
  source_code_hash via buildkit_artifact.bot.artifact_sha256.
- Build args (BOT_VERSION, BOT_REPO), build target (package), and the source
  path (/tmp/package.zip) are preserved, so the produced package is equivalent.
- gitignore .terraform.lock.hcl (root and nested) since this is a reusable
  module and consumers generate their own lock files.
- Update README prerequisites/build description to reference BuildKit and the
  provider's endpoint discovery; correct bot_force_rebuild_id type to string.

State migration (no manual `terraform state rm` required):
- Add a `removed` block for module.bot_artifact with lifecycle.destroy = false
  so existing deployments forget the old module from state on the next
  plan/apply instead of erroring. The old module's resources were backed by
  providers no longer used here (docker, archive, null, random); without this,
  terraform/opentofu tries to destroy orphaned resources and fails because
  those providers are no longer configured.
- Bump required_version to >= 1.7 (minimum for `removed` blocks; satisfied by
  both Terraform and OpenTofu 1.7+).
- Temporarily re-declare the docker/archive/null/random providers so `init`
  succeeds for upgrading users whose state still references them. The `removed`
  block and these legacy provider declarations are transitional and should be
  dropped in a follow-up release once consumers have upgraded.

The buildkit provider auto-discovers the BuildKit endpoint embedded in Docker
Desktop / OrbStack / Colima, honors BUILDKIT_HOST, and can supervise an
embedded rootless buildkitd on Linux.

BREAKING CHANGE: The module now requires the cruxstack/buildkit provider, a
reachable BuildKit endpoint, and Terraform/OpenTofu >= 1.7 (previously >= 1.3).
Run `terraform init` (or `tofu init`) to install the new provider; existing
deployments are migrated automatically via a `removed` block, so no manual
`terraform state rm module.bot_artifact` is needed. A BuildKit endpoint must be
available (Docker Desktop/OrbStack/Colima, BUILDKIT_HOST, or an embedded
buildkitd). The artifact is now written to a fixed path (dist/package.zip)
rather than a hashed filename.
@sgtoj
sgtoj force-pushed the feat/buildkit-artifact-provider branch from eba8024 to 90d97d7 Compare May 29, 2026 11:40
@sgtoj
sgtoj merged commit 2b0928e into main May 29, 2026
2 checks passed
@sgtoj
sgtoj deleted the feat/buildkit-artifact-provider branch May 29, 2026 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant