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
- Variables
- func Literal(s string) string
- func Ref(r *Resource, attr string) string
- func VarRef(name string) string
- type App
- type Backend
- type Document
- type Encryption
- type Manifest
- type ManifestProvider
- type ManifestStack
- type Provider
- type ProviderRelease
- type Resource
- type S3Backend
- type Stack
- func (s *Stack) AddResource(r *Resource) *Resource
- func (s *Stack) Bootstrap()
- func (s *Stack) Claim(namespace, id string, r *Resource)
- func (s *Stack) Claimed(namespace, id string) bool
- func (s *Stack) Credentials(names ...string)
- func (s *Stack) Encrypt(e Encryption)
- func (s *Stack) Import(to *Resource, id string)
- func (s *Stack) Note(key string, value any)
- func (s *Stack) RequireProvider(p Provider)
- func (s *Stack) Resources() []*Resource
- func (s *Stack) SetBackend(b Backend)
- func (s *Stack) Variable(name string, v Variable)
- type Variable
- type ZipPin
Constants ¶
const DefaultOutDir = ".yawn"
DefaultOutDir is the synth output folder. It is built in CI and never committed.
const ManifestVersion = 1
ManifestVersion is the manifest.json schema version. Consumers must refuse versions they do not understand.
Variables ¶
var KitVersion = "code.yawn.dev/john/cdk@v0.3.0-dev.19"
KitVersion identifies this library in manifests. Set by releases.
Functions ¶
func Literal ¶
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.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is the root of a construct tree. Create one per program.
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 ¶
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.
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.
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 (*Stack) AddResource ¶
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 ¶
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) Credentials ¶
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) RequireProvider ¶
RequireProvider declares a provider. Repeating a name must agree exactly.
func (*Stack) SetBackend ¶
SetBackend sets the state backend. Synth refuses a stack without one.
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.