config

package
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package config loads and validates the HCL policy file (.tfstackplan.hcl), resolving classification presets+rules into a single ordered rule list while preserving source declaration order.

Index

Constants

View Source
const (
	ScopeReport = "report" // CI runner: execution lifecycle events, logs, gates, claims
	ScopeRead   = "read"   // read-only: execution state/events, claims listing
	ScopeAdmin  = "admin"  // operator surgery: claim release (and future admin verbs)
)

API scopes grantable to an api_auth principal. Each /api/* route on the server accepts a subset of these (any-of). Validated at config load so a typo'd scope fails at startup, not as runtime 403s.

View Source
const DefaultFilename = ".tfstackplan.hcl"

DefaultFilename is auto-discovered in the working directory.

Variables

This section is empty.

Functions

func Discover

func Discover(dir string) (string, bool)

Discover returns the path to the nearest DefaultFilename at or above dir, searching up to (and including) the repo root. The repo root is the first ancestor containing a `.git` entry; the search never ascends past it, so a stray config above the repo is not picked up. Without a `.git` ancestor the search runs to the filesystem root.

Walking up is what lets a command run from a subdir (e.g. `run apply --dir stacks/<tier>`) auto-discover a repo-root `.tfstackplan.hcl` without an explicit `--config`.

Types

type APIAuthConfig added in v0.21.0

type APIAuthConfig struct {
	Audience       string   // expected OIDC audience (default: public_base_url)
	ExtraAudiences []string // additional accepted audiences (e.g. the gcloud ADC client id, for user tokens)
	Principals     []APIAuthPrincipal
}

APIAuthConfig configures Google OIDC bearer auth for /api/*: which token audiences are accepted and the identity → scope allowlist. It is the only /api/* auth — the legacy shared-secret HS256 path was removed once every caller migrated to OIDC.

type APIAuthPrincipal added in v0.21.0

type APIAuthPrincipal struct {
	Email  string
	Scopes []string
}

APIAuthPrincipal maps one verified caller identity (an email — service account or user) to the API scopes it holds.

type AllowBlock added in v0.43.0

type AllowBlock struct {
	Unit    string   `hcl:"unit"`
	Key     string   `hcl:"key"`
	Envs    []string `hcl:"envs"`
	Reason  string   `hcl:"reason"`
	Expires string   `hcl:"expires,optional"`
}

AllowBlock is one `allow {}` exception: a reviewed, justified duplicate value for a given (unit, key) across the listed envs. Reason is mandatory so every exception carries an auditable justification.

type ApprovalConfig added in v0.6.0

type ApprovalConfig struct {
	Backend       string // the block label, e.g. "gcp-pam"
	Location      string
	Duration      string
	RequesterPool []string
}

ApprovalConfig is the `approval "<backend>" {}` sub-block. Entitlement ids per class come from the top-level `class` blocks, not here.

type CacheConfig added in v0.18.0

type CacheConfig struct {
	Bucket  string
	Prefix  string
	Version string
}

CacheConfig holds the resolved caching fallback settings.

type ClassBinding added in v0.6.0

type ClassBinding struct {
	Name             string
	Backend          string
	Entitlement      string
	EntitlementScope string
	Required         bool
}

ClassBinding is a `class "<name>" {}` block: binds a classification class to an approval backend + entitlement, and whether it gates (required).

type Classification

type Classification struct {
	Default model.Class
	Rules   []classify.Rule
}

Classification holds the resolved, ordered rules and the fallback class.

type Config

type Config struct {
	Classification *Classification // nil when no classification block present
	Diff           DiffConfig
	Links          *LinksConfig         // nil when no links block present
	Server         *ServerConfig        // nil when no server block (the default/unlabeled one)
	Servers        []ServerConfig       // all parsed server blocks (including labeled ones)
	Serve          *ServeConfig         // nil when no serve block (added in a later task)
	UI             *UIConfig            // nil when no ui block (the central UI face)
	Classes        []ClassBinding       // class "<name>" {} bindings
	Progress       *ProgressConfig      // nil when no progress block (falls back to built-in fracs)
	Cache          *CacheConfig         // nil when no cache block present
	EnvUniqueness  *EnvUniquenessConfig // nil when no env_uniqueness block present
}

Config is the parsed policy file.

func Load

func Load(path string) (*Config, error)

Load parses and validates the HCL file at path.

type DiffConfig

type DiffConfig struct {
	Detect            bool
	MaxAttributeLines int // 0 = no cap
	Overrides         []DiffOverride
}

DiffConfig holds diff defaults and per-attribute overrides.

func (DiffConfig) Resolve

func (d DiffConfig) Resolve(resourceType, attr string) string

Resolve returns the differ kind ("" = auto) for a resource type + attribute.

type DiffOverride

type DiffOverride struct {
	TypePattern *regexp.Regexp
	Attribute   string
	Differ      string
}

DiffOverride forces a differ for a (resource type, attribute) pair.

type EnvBlock added in v0.43.0

type EnvBlock struct {
	Name string `hcl:"name,label"`
	Tier string `hcl:"tier"`
}

EnvBlock is one `environment "<name>" { tier = "<tier>" }` block: declares an environment and the tier it belongs to (e.g. "dev" is "nonprod").

type EnvUniquenessConfig added in v0.43.0

type EnvUniquenessConfig struct {
	ProtectedTier   string              `hcl:"protected_tier,optional"`
	ProjectTemplate string              `hcl:"project_token_template,optional"`
	Environments    []EnvBlock          `hcl:"environment,block"`
	Source          *SourceBlock        `hcl:"source,block"`
	ExtraEnvTokens  map[string][]string `hcl:"extra_env_tokens,optional"`
	ExtraScopedSegs []string            `hcl:"extra_scoped_segments,optional"`
	ExtraKeyPats    []string            `hcl:"extra_key_patterns,optional"`
	Allows          []AllowBlock        `hcl:"allow,block"`
}

EnvUniquenessConfig is the `env_uniqueness {}` block: config for the generic per-environment-value duplication lint. It declares the known environments (and which tier each belongs to), where to read per-env input values from, and any reviewed exceptions (`allow` blocks) that should not be flagged.

type ExecutorConfig added in v0.22.0

type ExecutorConfig struct {
	Backend  string // the block label, e.g. "cloudbuild"
	Project  string
	Region   string
	Triggers map[string]string // run kind ("plan"/"apply") → trigger name
}

ExecutorConfig is the `executor "<backend>" {}` sub-block: the CI backend serve drives when it triggers runs itself (webhook → build). Only "cloudbuild" is implemented; the trigger definitions stay terraform-managed, serve runs them by name.

type GitHubAppConfig added in v0.6.0

type GitHubAppConfig struct {
	AppID          string
	InstallationID string
	PrivateKeyPath string
}

GitHubAppConfig is the `github_app {}` sub-block.

type HeaderLink struct {
	Label string
	URL   string
}

HeaderLink is one templated report-header link.

type LinksConfig added in v0.3.0

type LinksConfig struct {
	Resource string
	Stack    string
	Header   []HeaderLink
}

LinksConfig holds URL templates for header / stack / resource links.

type ObjectsConfig added in v0.6.0

type ObjectsConfig struct {
	Backend string // "gcs"
	Bucket  string
	Prefix  string
}

ObjectsConfig configures the log-offload object store (currently GCS).

type PhaseWeight added in v0.16.0

type PhaseWeight struct {
	Phase  events.Phase
	Weight float64
}

PhaseWeight is one phase's slice of the bar. Weight defaults per phase (see defaultPhaseWeight) when omitted; relative within an operation's set.

type ProgressConfig added in v0.16.0

type ProgressConfig struct {
	Plan  []PhaseWeight
	Apply []PhaseWeight
}

ProgressConfig declares, per operation, the ordered weighted lifecycle phases the run will emit. Serve uses it to render a single full-progress bar across exactly those phases (ticking phases sub-fill their band by completed/total). Absent => serve falls back to its built-in fractions.

func (*ProgressConfig) For added in v0.16.0

func (pc *ProgressConfig) For(kind string) []PhaseWeight

For returns the ordered weighted phases for kind ("plan"/"apply"), or nil.

type PubSubConfig added in v0.6.0

type PubSubConfig struct {
	Audience       string // expected OIDC audience (default: <public_base_url>/pubsub/push)
	ServiceAccount string // the push subscription's OIDC service-account email
}

PubSubConfig configures the Pub/Sub push ingestion endpoint.

type ServeConfig added in v0.6.0

type ServeConfig struct {
	DBPath                 string
	PublicBaseURL          string
	GitHubWebhookSecretEnv string // env var name holding the GitHub webhook HMAC secret
	// UIBaseURL is the central UI service's external base URL. Check-run
	// details and approval links point there ("" leaves them unset — the
	// check-run body still carries everything). The UI's tier names must
	// match the serve environments for its /t/<tier>/e/<id> routes.
	UIBaseURL string
	GitHubApp *GitHubAppConfig
	Approval  *ApprovalConfig
	LogsDir   string
	Objects   *ObjectsConfig
	PubSub    *PubSubConfig
	APIAuth   *APIAuthConfig
	Executor  *ExecutorConfig
}

ServeConfig is the `serve {}` block: the control-plane server runtime config.

type ServerConfig added in v0.6.0

type ServerConfig struct {
	Name        string
	URL         string
	Environment string
}

ServerConfig is the `server {}` block: where the control-plane server lives and which environment this repo's CI reports to. Used by `run` (CI) and `serve`.

type SourceBlock added in v0.43.0

type SourceBlock struct {
	Glob             string `hcl:"glob,optional"`
	EnvironmentsPath string `hcl:"environments_path,optional"`
	InputsPath       string `hcl:"inputs_path,optional"`
	TierInput        string `hcl:"tier_input,optional"`
}

SourceBlock is the `source {}` sub-block: where per-stack instance manifests live (Glob) and which config paths inside them carry the environment name / input values the lint compares.

type UIConfig added in v0.25.0

type UIConfig struct {
	PublicBaseURL    string // external base URL (OAuth redirect URI = <base>/auth/callback)
	SessionSecretEnv string // env var name holding the session-cookie encryption secret
	// GitHubWebhookSecretEnv names the env var holding the GitHub App's
	// webhook secret. The UI is the App's single webhook ingress: it verifies
	// GitHub's HMAC here and relays deliveries to the tiers under its own
	// Google OIDC identity — the App secret exists nowhere else.
	GitHubWebhookSecretEnv string
	Tiers                  []UITierConfig
	OAuth                  *UIOAuthConfig
}

UIConfig is the top-level `ui {}` block: the central UI service — a stateless aggregator over the tier serves with its own Google login.

type UIOAuthConfig added in v0.25.0

type UIOAuthConfig struct {
	ClientID        string
	ClientSecretEnv string
	AllowedDomain   string // required Workspace domain (the id_token `hd` claim)
	// QuotaProject is sent as x-goog-user-project on user-token GCP API calls
	// (PAM approve/deny): user credentials attribute quota to the OAuth
	// client's project, which must have the called API enabled. Empty sends
	// no header.
	QuotaProject string
}

UIOAuthConfig is the `oauth {}` sub-block: the Google OAuth client the UI logs users in with (authorization-code flow, Workspace-internal client). The client secret rides an env var (name here, value in the deployment's secret store) like every other secret in this config.

type UITierConfig added in v0.25.0

type UITierConfig struct {
	Name     string
	URL      string
	Audience string
}

UITierConfig is one `tier "<name>" {}` block: a tier serve the central UI aggregates. The UI backend authenticates to it with Google OIDC ID tokens minted for Audience (default: the tier URL — the audience the tier's api_auth block accepts by convention).

Jump to

Keyboard shortcuts

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