cdk

module
v0.2.0-dev.1 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(gitea.Provider("https://code.yawn.dev"))
stack.SetBackend(gitea.StateBackend{BaseURL: "https://code.yawn.dev", Owner: "john", Prefix: "arch-"})
stack.Variable("state_passphrase", core.Variable{Sensitive: true})
stack.Encrypt(core.Encryption{PassphraseVariable: "state_passphrase"})

repo := gitea.NewRepository(stack, "corn", gitea.RepositoryProps{
	Owner: "john", Name: "corn", ID: 1, Visibility: gitea.Public, DefaultBranch: "main",
	Features: gitea.Features{Issues: true, Wiki: true, PullRequests: true, Projects: true},
	Merge:    gitea.MergeOptions{MergeCommits: true, Squash: true, Default: gitea.Merge, DeleteBranchAfterMerge: true},
})
repo.Protect(stack, gitea.ProtectionProps{Rule: "main", RequiredChecks: []string{"*"}, 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
gitea NewRepository, Protect, Provider (pinned tofu-provider-gitea), StateBackend (Gitea's OpenTofu state registry)
cmd/yawn yawn providers: installs the pinned provider zips into a filesystem mirror

.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

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. Credentials come from the environment (GITEA_TOKEN, TF_HTTP_USERNAME/TF_HTTP_PASSWORD, TF_VAR_*). Literal values for token, password or secret settings are refused.
  • 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.2.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 .gitea/scripts/tools.py. .gitea/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

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.
Command yawn works with synthesized .yawn/ output.
Package core is the construct model of the yawn kit.
Package core is the construct model of the yawn kit.
examples
repos command
Example: manage one existing repository and protect its main branch.
Example: manage one existing repository and protect its main branch.
Package gitea provides constructs for Gitea repositories and branch protection, synthesized for registry.yawn.dev/john/gitea (john/tofu-provider-gitea).
Package gitea provides constructs for Gitea repositories and branch protection, synthesized for registry.yawn.dev/john/gitea (john/tofu-provider-gitea).
internal
install
Package install puts pinned provider zips into an OpenTofu filesystem mirror.
Package install puts pinned provider zips into an OpenTofu filesystem mirror.

Jump to

Keyboard shortcuts

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