core

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package core is the construct model of the yawn kit. An App holds Stacks, a Stack holds Resources, and Synth writes everything to an output folder (.yawn/ by default) as plain OpenTofu configuration plus manifest.json.

Synth never touches the network or reads credentials, and its output is a pure function of the program: the same program always writes the same bytes.

Index

Constants

View Source
const DefaultOutDir = ".yawn"

DefaultOutDir is the synth output folder. It is built in CI and never committed.

View Source
const ManifestVersion = 1

ManifestVersion is the manifest.json schema version. Consumers must refuse versions they do not understand.

Variables

View Source
var KitVersion = "code.yawn.dev/john/cdk@v0.3.0-dev.19"

KitVersion identifies this library in manifests. Set by releases.

Functions

func Literal

func Literal(s string) string

Literal escapes s so OpenTofu keeps it verbatim. In the JSON syntax every string is a template: "${...}" and "%{...}" are evaluated. Literal doubles the introducers ("$${", "%%{"), which OpenTofu turns back into "${"/"%{", so scripts and JSON payloads containing shell "${var}" survive unchanged. Never wrap a Ref or VarRef.

func Ref

func Ref(r *Resource, attr string) string

Ref returns an OpenTofu reference to another resource's attribute, for use as an attribute value (it is written as "${type.name.attr}").

func VarRef

func VarRef(name string) string

VarRef returns a reference to a stack variable.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

App is the root of a construct tree. Create one per program.

func NewApp

func NewApp() *App

NewApp returns an empty App.

func (*App) Attach

func (a *App) Attach(name string, d Document)

Attach adds a data document written as <out>/<name> by Synth.

func (*App) Render

func (a *App) Render() (map[string][]byte, error)

Render returns the output files (path -> bytes) without writing them.

func (*App) Stacks

func (a *App) Stacks() []*Stack

Stacks returns the stacks in creation order.

func (*App) Synth

func (a *App) Synth(dir string) (*Manifest, error)

Synth validates the app and writes it to dir (DefaultOutDir if empty). The directory is replaced atomically: it either holds the previous output or the complete new output, never a mix.

func (*App) Validate

func (a *App) Validate() error

Validate checks every stack. Synth calls it; tests may call it directly.

type Backend

type Backend interface {
	// Block returns the backend type and its static configuration for a stack.
	// It must not contain credentials.
	Block(stackID string) (kind string, config map[string]any)
}

Backend is a stack's state backend.

type Document

type Document interface {
	JSON() ([]byte, error)
}

Document is non-OpenTofu data synthesized next to the stacks, for example fleet.json. It must be data only: no secrets, no expressions.

type Encryption

type Encryption struct {
	// PassphraseVariable names the sensitive variable holding the passphrase.
	PassphraseVariable string
}

Encryption enables OpenTofu client-side encryption of state and plans with a PBKDF2 passphrase taken from a sensitive variable. Encryption is enforced: OpenTofu refuses to write state or plans unencrypted.

type Manifest

type Manifest struct {
	Version int             `json:"manifest_version"`
	Kit     string          `json:"kit"`
	Stacks  []ManifestStack `json:"stacks"`
	// Documents are attached data files, e.g. fleet.json.
	Documents []string `json:"documents,omitempty"`
}

Manifest is the typed summary written to <out>/manifest.json. It is data only: consumers read it without running any repository code.

type ManifestProvider

type ManifestProvider struct {
	Source  string          `json:"source"`
	Version string          `json:"version"`
	Release ProviderRelease `json:"release"`
}

ManifestProvider pins a provider so CD can install exactly these zips.

type ManifestStack

type ManifestStack struct {
	ID        string             `json:"id"`
	Dir       string             `json:"dir"`
	Providers []ManifestProvider `json:"providers"`
	Resources []string           `json:"resources"`
	Imports   map[string]string  `json:"imports,omitempty"`
	Variables []string           `json:"variables"`
	Encrypted bool               `json:"encrypted"`
	// Bootstrap stacks can also be deployed by `yawn bootstrap`.
	Bootstrap bool `json:"bootstrap,omitempty"`
	// Credentials are the environment variable names the stack needs.
	Credentials []string       `json:"credentials,omitempty"`
	Notes       map[string]any `json:"notes,omitempty"`
}

ManifestStack describes one synthesized stack.

type Provider

type Provider struct {
	// Name is the local name, e.g. "forgejo".
	Name string
	// Source is the full address, e.g. "registry.opentofu.org/svalabs/forgejo".
	Source string
	// Version is exact; ranges are refused.
	Version string
	// Release pins the per-platform zips. Required: synth writes the lock file
	// from it, so OpenTofu verifies every download against these hashes.
	Release ProviderRelease
	// Config is the provider block. Credentials must come from the environment.
	Config map[string]any
}

Provider is a pinned OpenTofu provider.

type ProviderRelease

type ProviderRelease struct {
	// BaseURL is the HTTPS download directory, ending in "/".
	BaseURL string `json:"base_url"`
	// Zips maps a platform ("linux_amd64") to its pinned zip.
	Zips map[string]ZipPin `json:"zips"`
}

ProviderRelease pins a provider's per-platform zips. Providers from a public registry (registry.opentofu.org) are downloaded by OpenTofu itself and only need the hashes; BaseURL is optional for them and used by `yawn providers` to fill an offline filesystem mirror.

type Resource

type Resource struct {
	Type  string
	Name  string
	Attrs map[string]any
	// PreventDestroy makes OpenTofu refuse any plan that destroys this resource.
	PreventDestroy bool
	// IgnoreChanges lists attributes OpenTofu must not reconcile.
	IgnoreChanges []string
}

Resource is one OpenTofu resource.

func (*Resource) Address

func (r *Resource) Address() string

Address returns "type.name".

type S3Backend

type S3Backend struct {
	// Endpoint is the HTTPS S3 endpoint, e.g. "https://s3.yawn.dev".
	Endpoint string
	// Bucket holds the state objects.
	Bucket string
	// Region is passed through; S3-compatible stores usually accept any value.
	Region string
	// Prefix is prepended to every state key, e.g. "arch/" gives
	// "arch/<stack>/terraform.tfstate".
	Prefix string
}

S3Backend stores state in an S3-compatible bucket (for example VersityGW at s3.yawn.dev) with native S3 locking: a conditional PutObject on a .tflock object, so no DynamoDB is needed. Credentials never appear in the output; OpenTofu reads AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY from the environment. Pair it with Stack.Encrypt so the bucket only holds ciphertext.

func (S3Backend) Block

func (b S3Backend) Block(stackID string) (string, map[string]any)

Block implements Backend.

type Stack

type Stack struct {
	ID string
	// contains filtered or unexported fields
}

Stack is one OpenTofu root module: one state, one plan, one apply.

func NewStack

func NewStack(app *App, id string) *Stack

NewStack adds a stack. IDs are lowercase and unique within the app.

func (*Stack) AddResource

func (s *Stack) AddResource(r *Resource) *Resource

AddResource adds a resource. Addresses are unique within a stack.

func (*Stack) Bootstrap

func (s *Stack) Bootstrap()

Bootstrap marks a stack that the deploy control plane depends on (xyOps, the deployer, Forgejo, runners). It still deploys through the normal hand-off, and it can also be deployed from a trusted machine with `yawn bootstrap <stack>` when the control plane itself is broken. Only bootstrap stacks are accepted by that command.

func (*Stack) Claim

func (s *Stack) Claim(namespace, id string, r *Resource)

Claim records that r owns the remote object id in namespace (for example "xyops/event"). Remote IDs must be unique per namespace across every stack in the app: two stacks managing one object would fight over it, and two resources creating the same id collide at apply time. Claim panics on a duplicate, naming both owners.

func (*Stack) Claimed

func (s *Stack) Claimed(namespace, id string) bool

Claimed reports whether some stack in the app manages namespace/id.

func (*Stack) Credentials

func (s *Stack) Credentials(names ...string)

Credentials names the environment variables the stack needs at plan and apply time (provider and backend credentials). Names only; values never appear in the output. `yawn bootstrap` refuses to start unless every one is set, and passes nothing else from the caller's environment.

func (*Stack) Encrypt

func (s *Stack) Encrypt(e Encryption)

Encrypt enables enforced client-side encryption of state and plans.

func (*Stack) Import

func (s *Stack) Import(to *Resource, id string)

Import adopts an existing object, so the plan shows only real differences.

func (*Stack) Note

func (s *Stack) Note(key string, value any)

Note attaches typed, non-secret data to the stack's manifest entry.

func (*Stack) RequireProvider

func (s *Stack) RequireProvider(p Provider)

RequireProvider declares a provider. Repeating a name must agree exactly.

func (*Stack) Resources

func (s *Stack) Resources() []*Resource

Resources returns the stack's resources in creation order.

func (*Stack) SetBackend

func (s *Stack) SetBackend(b Backend)

SetBackend sets the state backend. Synth refuses a stack without one.

func (*Stack) Variable

func (s *Stack) Variable(name string, v Variable)

Variable declares a plan-time input.

type Variable

type Variable struct {
	Type        string
	Sensitive   bool
	Description string
	// Ephemeral values are never written to state or saved plans. Use it for
	// every secret input: the state passphrase, API tokens, and values fed to
	// write-only attributes such as xyops_secret.fields_wo.
	Ephemeral bool
}

Variable is a plan-time input. Its value is never written to the output.

type ZipPin

type ZipPin struct {
	File   string `json:"file"`
	SHA256 string `json:"sha256"`
	H1     string `json:"h1"`
}

ZipPin pins one platform zip by SHA-256 and by OpenTofu's h1 hash.

Jump to

Keyboard shortcuts

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