cdk

module
v0.3.0-dev.5 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT

README

john/cdk

A small, strongly typed Go kit for infrastructure as code, in the style of the AWS CDK. Programs build an App of Stacks of Resources; Synth writes plain OpenTofu configuration to .yawn/. OpenTofu still does all planning, applying and state.

  • Library, not a service. Repositories depend on this module and own their programs. john/arch runs them in CD.
  • .yawn/ is built in CI only. It is gitignored and never committed.
  • Standard library only. No third-party Go dependencies.
  • Deterministic. The same program always writes the same bytes.
  • Nothing left to defaults. Constructs write every setting explicitly.
app := core.NewApp()
stack := core.NewStack(app, "repos")
stack.RequireProvider(forgejo.Provider("https://code.yawn.dev"))
stack.SetBackend(core.S3Backend{Endpoint: "https://s3.yawn.dev", Bucket: "tofu-state", Prefix: "arch/"})
stack.Variable("state_passphrase", core.Variable{Sensitive: true, Ephemeral: true})
stack.Encrypt(core.Encryption{PassphraseVariable: "state_passphrase"})

repo := forgejo.NewRepository(stack, "corn", forgejo.RepositoryProps{
	Owner: "john", Name: "corn", Visibility: forgejo.Public, DefaultBranch: "main",
	Features: forgejo.Features{Issues: true, PullRequests: true, Releases: true, Actions: true},
	Merge: forgejo.MergeOptions{MergeCommits: true, Squash: true, Default: forgejo.Merge,
		DefaultUpdate: forgejo.UpdateMerge, DeleteBranchAfterMerge: true},
	Import: true,
})
repo.Protect(stack, forgejo.ProtectionProps{Branch: "main", RequiredChecks: []string{"CI / checks (pull_request)"}, Import: true})

app.Synth("") // writes .yawn/

See examples/repos for a complete program.

Packages

Package Provides
core App, Stack, Resource, Provider, Synth, manifest.json, enforced state encryption, S3Backend, attached data documents
forgejo NewRepository, Protect, Provider (pinned svalabs/forgejo 1.7.0), UnreadSettings
fleet Which Proxmox container runs which service (fleet.json), identity checks and drift reports for push deploys
oidc Verifies Forgejo Actions ID tokens (RS256, JWKS, claim policy, replay guard)
cmd/yawn providers, oidc-verify, fleet-check, fleet-diff

Design: deploy control plane, also published to the repository wiki on each release.

.yawn/ layout

.yawn/
  manifest.json            # typed, data-only summary (stacks, providers, resources, imports, notes)
  <stack>/main.tf.json     # the stack's OpenTofu configuration
  <stack>/encryption.tf    # enforced client-side encryption of state and plans
  <stack>/.terraform.lock.hcl  # provider hashes from the release pins
  fleet.json               # optional attached document: the declared fleet

manifest.json is data only, so a consumer such as john/arch can read it without running repository code. Its manifest_version is 1; consumers must refuse versions they do not understand.

Safety rules

  • Repositories are never deleted. prevent_destroy is set, and a forced destroy archives the repository instead.
  • No hidden defaults. Every writable provider attribute is either written or listed as creation-only. A test compares the constructs against the provider's schema, so a provider upgrade that adds a setting fails the build until the construct handles it.
  • Mandatory choices. Visibility must be chosen, and a protected branch must have at least one required check.
  • Exact provider pins. Exact versions, HTTPS release URLs, and SHA-256 plus OpenTofu h1 hashes. yawn providers checks both hashes, and the generated lock file makes OpenTofu check them again.
  • No secrets in output or state. Credentials come from the environment (FORGEJO_API_TOKEN, AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY, TF_VAR_*). Literal values for token, password or secret settings are refused, and the state passphrase must be an ephemeral variable so it never reaches a plan.
  • Unread settings are explicit. svalabs/forgejo does not read some repository settings back, so UI changes to them are invisible to plans; forgejo.UnreadSettings lists them for a separate drift check.
  • Atomic synth. A failed synth leaves the previous .yawn/ untouched.

Running a stack

go run ./your/program                          # writes .yawn/
go run code.yawn.dev/john/cdk/cmd/yawn@v0.3.0-dev.1 providers
export TF_CLI_CONFIG_FILE=$PWD/.yawn/.providers/tofurc
cd .yawn/<stack> && tofu init && tofu plan

Development

Go 1.27.4 and OpenTofu 1.13.9 are pinned in .forgejo/scripts/tools.py. .forgejo/scripts/check.sh TOOLS runs gofmt, vet, tests, govulncheck, then synthesizes the example and validates it with OpenTofu against the real pinned provider. Update golden files with go test ./core -update and review the diff.

History

v0.2.0-dev.1 targeted Gitea through a fork of its provider and Gitea's state registry. Forgejo has neither, so 0.3.0 moves to svalabs/forgejo and S3 state; the gitea package is removed.

Up to v0.1.0-dev.1 this repository held HCL modules (Caddy edge, SSO, oauth2-proxy, Peekaping status sites). They had no consumers and are retired from main; the tag keeps them.

Releases

Versioned with john/release: change VERSION and CHANGELOG.md in a PR, and merging tags the commit. Consumers pin a tag in go.mod.

Directories

Path Synopsis
cmd
yawn command
Command yawn works with synthesized .yawn/ output and the deploy control plane described in the design doc (wiki/design/deploy-control-plane.md).
Command yawn works with synthesized .yawn/ output and the deploy control plane described in the design doc (wiki/design/deploy-control-plane.md).
Package core is the construct model of the yawn kit.
Package core is the construct model of the yawn kit.
examples
repos command
Example: adopt one existing Forgejo repository and protect its main branch.
Example: adopt one existing Forgejo repository and protect its main branch.
Package fleet declares, in code, which Proxmox container runs which service, so a push deploy job can prove it is touching the right container and a nightly check can catch the fleet drifting away from the code.
Package fleet declares, in code, which Proxmox container runs which service, so a push deploy job can prove it is touching the right container and a nightly check can catch the fleet drifting away from the code.
Package forgejo provides constructs for Forgejo repositories and branch protection, synthesized for the community OpenTofu provider svalabs/forgejo (registry.opentofu.org/svalabs/forgejo).
Package forgejo provides constructs for Forgejo repositories and branch protection, synthesized for the community OpenTofu provider svalabs/forgejo (registry.opentofu.org/svalabs/forgejo).
internal
install
Package install puts pinned provider zips into an OpenTofu filesystem mirror.
Package install puts pinned provider zips into an OpenTofu filesystem mirror.
Package oidc verifies Forgejo Actions ID tokens so an xyOps deploy job can trust "this is john/ops, push to main, run N, commit X" without CI holding any xyOps credential.
Package oidc verifies Forgejo Actions ID tokens so an xyOps deploy job can trust "this is john/ops, push to main, run N, commit X" without CI holding any xyOps credential.

Jump to

Keyboard shortcuts

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