terraform

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MPL-2.0 Imports: 24 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action added in v0.9.0

type Action int

Action enumerates the kinds of changes a plan can produce for a single resource. ActionUnknown is reserved for inputs that don't correspond to any operator-visible change (terraform "noop"/"read" or unrecognised action strings) and is dropped from rendered resource lists.

const (
	ActionUnknown Action = iota
	ActionCreate
	ActionUpdate
	ActionDelete
	ActionReplace
)

type ComponentFailure added in v0.9.0

type ComponentFailure struct {
	ID  string
	Err error
}

ComponentFailure is a per-component error captured during continue-on-error destroy. ID is the terraform component's blueprint identifier; Err is the terraform destroy error that the operator can use to diagnose.

type DestroyAttributeDrift added in v0.9.1

type DestroyAttributeDrift struct {
	Address   string
	Attribute string
	State     string
	Config    string
}

DestroyAttributeDrift names one destroy-behavior attribute whose config value disagrees with what terraform has recorded in state for a resource. State is the value plan -destroy will actually use; Config is what the current .tf declares.

type DestroyOutcome added in v0.9.0

type DestroyOutcome struct {
	Destroyed []string
	Skipped   []string
	Failed    []ComponentFailure
}

DestroyOutcome tallies what a single terraform destroy pass produced. Destroyed lists component IDs whose terraform destroy ran to completion; Skipped lists component IDs whose state was empty (no-op); Failed lists per-component failures collected when continue-on-error is true. Aggregate cross-layer concerns (terraform deferral, kustomize counts) live on the provisioner-layer result type, not here.

type MockStack

type MockStack struct {
	UpFunc                          func(blueprint *blueprintv1alpha1.Blueprint, onApply ...func(ctx context.Context, id string) (bool, error)) (bool, error)
	MigrateStateFunc                func(blueprint *blueprintv1alpha1.Blueprint) ([]string, error)
	MigrateComponentStateFunc       func(blueprint *blueprintv1alpha1.Blueprint, componentID string) error
	HasRemoteStateFunc              func(blueprint *blueprintv1alpha1.Blueprint, componentID string) (bool, error)
	HasLocalStateWithResourcesFunc  func(componentID string) (bool, error)
	InitComponentFunc               func(blueprint *blueprintv1alpha1.Blueprint, componentID string) error
	RemoveLocalStateFunc            func(componentID string) error
	ListLocalStateComponentIDsFunc  func() ([]string, error)
	LocalStateSnapshotFunc          func(componentID string) (*StateSnapshot, error)
	StateSnapshotFunc               func(blueprint *blueprintv1alpha1.Blueprint, componentID string) (*StateSnapshot, error)
	BackendPointerTypeFunc          func(componentID string) (string, error)
	PostApplyFunc                   func(fns ...func(ctx context.Context, id string) error)
	DestroyAllFunc                  func(blueprint *blueprintv1alpha1.Blueprint, continueOnError bool, excludeIDs ...string) (DestroyOutcome, error)
	PlanFunc                        func(blueprint *blueprintv1alpha1.Blueprint, componentID string) error
	PlanAllFunc                     func(blueprint *blueprintv1alpha1.Blueprint) error
	PlanJSONFunc                    func(blueprint *blueprintv1alpha1.Blueprint, componentID string) error
	PlanAllJSONFunc                 func(blueprint *blueprintv1alpha1.Blueprint) error
	PlanResourceChangesJSONFunc     func(blueprint *blueprintv1alpha1.Blueprint, componentID string) error
	PlanAllResourceChangesJSONFunc  func(blueprint *blueprintv1alpha1.Blueprint) error
	ApplyFunc                       func(blueprint *blueprintv1alpha1.Blueprint, componentID string) error
	DestroyFunc                     func(blueprint *blueprintv1alpha1.Blueprint, componentID string) (bool, error)
	PlanSummaryFunc                 func(blueprint *blueprintv1alpha1.Blueprint) []TerraformComponentPlan
	PlanComponentSummaryFunc        func(blueprint *blueprintv1alpha1.Blueprint, componentID string) TerraformComponentPlan
	PlanDestroySummaryFunc          func(blueprint *blueprintv1alpha1.Blueprint) []TerraformComponentPlan
	PlanDestroyComponentSummaryFunc func(blueprint *blueprintv1alpha1.Blueprint, componentID string) TerraformComponentPlan
}

MockStack is a mock implementation of the Stack interface for testing.

func NewMockStack

func NewMockStack() *MockStack

NewMockStack creates a new mock stack.

func (*MockStack) Apply added in v0.9.0

func (m *MockStack) Apply(_ context.Context, blueprint *blueprintv1alpha1.Blueprint, componentID string) error

Apply is a mock implementation of the Apply method.

func (*MockStack) BackendPointerType added in v0.10.0

func (m *MockStack) BackendPointerType(componentID string) (string, error)

BackendPointerType is a mock implementation of the BackendPointerType method.

func (*MockStack) Destroy added in v0.9.0

func (m *MockStack) Destroy(_ context.Context, blueprint *blueprintv1alpha1.Blueprint, componentID string) (bool, error)

Destroy is a mock implementation of the Destroy method.

func (*MockStack) DestroyAll added in v0.9.0

func (m *MockStack) DestroyAll(_ context.Context, blueprint *blueprintv1alpha1.Blueprint, continueOnError bool, excludeIDs ...string) (DestroyOutcome, error)

DestroyAll is a mock implementation of the DestroyAll method.

func (*MockStack) HasLocalStateWithResources added in v0.9.0

func (m *MockStack) HasLocalStateWithResources(componentID string) (bool, error)

HasLocalStateWithResources is a mock implementation of the HasLocalStateWithResources method.

func (*MockStack) HasRemoteState added in v0.9.0

func (m *MockStack) HasRemoteState(blueprint *blueprintv1alpha1.Blueprint, componentID string) (bool, error)

HasRemoteState is a mock implementation of the HasRemoteState method.

func (*MockStack) InitComponent added in v0.9.0

func (m *MockStack) InitComponent(blueprint *blueprintv1alpha1.Blueprint, componentID string) error

InitComponent is a mock implementation of the InitComponent method.

func (*MockStack) ListLocalStateComponentIDs added in v0.9.1

func (m *MockStack) ListLocalStateComponentIDs() ([]string, error)

ListLocalStateComponentIDs is a mock implementation of the ListLocalStateComponentIDs method.

func (*MockStack) LocalStateSnapshot added in v0.10.0

func (m *MockStack) LocalStateSnapshot(componentID string) (*StateSnapshot, error)

LocalStateSnapshot is a mock implementation of the LocalStateSnapshot method.

func (*MockStack) MigrateComponentState added in v0.9.0

func (m *MockStack) MigrateComponentState(blueprint *blueprintv1alpha1.Blueprint, componentID string) error

MigrateComponentState is a mock implementation of the MigrateComponentState method.

func (*MockStack) MigrateState added in v0.9.0

func (m *MockStack) MigrateState(_ context.Context, blueprint *blueprintv1alpha1.Blueprint) ([]string, error)

MigrateState is a mock implementation of the MigrateState method.

func (*MockStack) Plan added in v0.9.0

func (m *MockStack) Plan(blueprint *blueprintv1alpha1.Blueprint, componentID string) error

Plan is a mock implementation of the Plan method.

func (*MockStack) PlanAll added in v0.9.0

func (m *MockStack) PlanAll(blueprint *blueprintv1alpha1.Blueprint) error

PlanAll is a mock implementation of the PlanAll method.

func (*MockStack) PlanAllJSON added in v0.9.0

func (m *MockStack) PlanAllJSON(blueprint *blueprintv1alpha1.Blueprint) error

PlanAllJSON is a mock implementation of the PlanAllJSON method.

func (*MockStack) PlanAllResourceChangesJSON added in v0.9.1

func (m *MockStack) PlanAllResourceChangesJSON(blueprint *blueprintv1alpha1.Blueprint) error

PlanAllResourceChangesJSON is a mock implementation of the PlanAllResourceChangesJSON method.

func (*MockStack) PlanComponentSummary added in v0.9.0

func (m *MockStack) PlanComponentSummary(blueprint *blueprintv1alpha1.Blueprint, componentID string) TerraformComponentPlan

PlanComponentSummary is a mock implementation of the PlanComponentSummary method.

func (*MockStack) PlanDestroyComponentSummary added in v0.9.0

func (m *MockStack) PlanDestroyComponentSummary(blueprint *blueprintv1alpha1.Blueprint, componentID string) TerraformComponentPlan

PlanDestroyComponentSummary is a mock implementation of the PlanDestroyComponentSummary method.

func (*MockStack) PlanDestroySummary added in v0.9.0

func (m *MockStack) PlanDestroySummary(blueprint *blueprintv1alpha1.Blueprint) []TerraformComponentPlan

PlanDestroySummary is a mock implementation of the PlanDestroySummary method.

func (*MockStack) PlanJSON added in v0.9.0

func (m *MockStack) PlanJSON(blueprint *blueprintv1alpha1.Blueprint, componentID string) error

PlanJSON is a mock implementation of the PlanJSON method.

func (*MockStack) PlanResourceChangesJSON added in v0.9.1

func (m *MockStack) PlanResourceChangesJSON(blueprint *blueprintv1alpha1.Blueprint, componentID string) error

PlanResourceChangesJSON is a mock implementation of the PlanResourceChangesJSON method.

func (*MockStack) PlanSummary added in v0.9.0

func (m *MockStack) PlanSummary(blueprint *blueprintv1alpha1.Blueprint) []TerraformComponentPlan

PlanSummary is a mock implementation of the PlanSummary method.

func (*MockStack) PostApply added in v0.9.0

func (m *MockStack) PostApply(fns ...func(ctx context.Context, id string) error)

PostApply is a mock implementation of the PostApply method.

func (*MockStack) RemoveLocalState added in v0.9.0

func (m *MockStack) RemoveLocalState(componentID string) error

RemoveLocalState is a mock implementation of the RemoveLocalState method.

func (*MockStack) StateSnapshot added in v0.10.0

func (m *MockStack) StateSnapshot(blueprint *blueprintv1alpha1.Blueprint, componentID string) (*StateSnapshot, error)

StateSnapshot is a mock implementation of the StateSnapshot method.

func (*MockStack) Up

func (m *MockStack) Up(_ context.Context, blueprint *blueprintv1alpha1.Blueprint, onApply ...func(ctx context.Context, id string) (bool, error)) (bool, error)

Up is a mock implementation of the Up method.

type ResourceChange added in v0.9.0

type ResourceChange struct {
	Address string
	Action  Action
}

ResourceChange identifies one resource changed by a plan along with its action. Address is the terraform resource address with the leading "module.main." wrapper stripped, since every Windsor component wraps its resources in a single module and the prefix would otherwise be repeated noise on every line.

type Shims

type Shims struct {
	shims.Shims
	Chdir     func(dir string) error
	TimeSleep func(d time.Duration)
}

Shims holds the shared system call primitives and the terraform stack shims.

func NewShims

func NewShims() *Shims

NewShims returns a Shims with every field set to its real implementation.

type Stack

type Stack interface {
	Up(ctx context.Context, blueprint *blueprintv1alpha1.Blueprint, onApply ...func(ctx context.Context, id string) (bool, error)) (bool, error)
	MigrateState(ctx context.Context, blueprint *blueprintv1alpha1.Blueprint) ([]string, error)
	MigrateComponentState(blueprint *blueprintv1alpha1.Blueprint, componentID string) error
	HasRemoteState(blueprint *blueprintv1alpha1.Blueprint, componentID string) (bool, error)
	HasLocalStateWithResources(componentID string) (bool, error)
	InitComponent(blueprint *blueprintv1alpha1.Blueprint, componentID string) error
	RemoveLocalState(componentID string) error
	ListLocalStateComponentIDs() ([]string, error)
	LocalStateSnapshot(componentID string) (*StateSnapshot, error)
	StateSnapshot(blueprint *blueprintv1alpha1.Blueprint, componentID string) (*StateSnapshot, error)
	BackendPointerType(componentID string) (string, error)
	PostApply(fns ...func(ctx context.Context, id string) error)
	DestroyAll(ctx context.Context, blueprint *blueprintv1alpha1.Blueprint, continueOnError bool, excludeIDs ...string) (DestroyOutcome, error)
	Plan(blueprint *blueprintv1alpha1.Blueprint, componentID string) error
	PlanAll(blueprint *blueprintv1alpha1.Blueprint) error
	PlanJSON(blueprint *blueprintv1alpha1.Blueprint, componentID string) error
	PlanAllJSON(blueprint *blueprintv1alpha1.Blueprint) error
	PlanResourceChangesJSON(blueprint *blueprintv1alpha1.Blueprint, componentID string) error
	PlanAllResourceChangesJSON(blueprint *blueprintv1alpha1.Blueprint) error
	Apply(ctx context.Context, blueprint *blueprintv1alpha1.Blueprint, componentID string) error
	Destroy(ctx context.Context, blueprint *blueprintv1alpha1.Blueprint, componentID string) (bool, error)
	PlanSummary(blueprint *blueprintv1alpha1.Blueprint) []TerraformComponentPlan
	PlanComponentSummary(blueprint *blueprintv1alpha1.Blueprint, componentID string) TerraformComponentPlan
	PlanDestroySummary(blueprint *blueprintv1alpha1.Blueprint) []TerraformComponentPlan
	PlanDestroyComponentSummary(blueprint *blueprintv1alpha1.Blueprint, componentID string) TerraformComponentPlan
}

Stack defines the interface for Terraform stack operations. Both the Stack struct and MockStack implement this interface.

onApply hooks return (haltAfter, err). A non-nil err is a real failure and aborts the loop the same as before. haltAfter=true means the component apply succeeded but subsequent components should NOT be applied — used to defer privileged host configuration to an explicit 'windsor configure network' invocation by the operator. Stack.Up returns (halted bool, err error); halted=true indicates a clean stop, not a failure.

func NewStack

func NewStack(rt *runtime.Runtime, opts ...*TerraformStack) Stack

NewStack creates a new stack of components.

type StateSnapshot added in v0.10.0

type StateSnapshot struct {
	Lineage   string
	Serial    int64
	Resources int
	Digest    string
}

StateSnapshot is the identity, the size, and the content of one terraform state. Lineage and Serial come from the state file. Resources counts the resource entries at the top level of the state file. Digest is a hash of the resources and the outputs. It does not change when terraform gives a copy of the state a new lineage or serial.

type TerraformComponentPlan added in v0.9.0

type TerraformComponentPlan struct {
	ComponentID string
	Path        string
	Add         int
	Change      int
	Destroy     int
	NoChanges   bool
	IsNew       bool
	Resources   []ResourceChange
	// Protected lists resource addresses that terraform reports cannot be
	// destroyed because their config sets `lifecycle { prevent_destroy = true }`.
	// Populated only on destroy-plan paths; nil on apply-plan paths.
	// Informational — cmd/destroy.go surfaces these as a stderr warning so the
	// operator knows terraform will halt the destroy partway. The wrapper does
	// not refuse: half-completed destroys orphan more state than letting the
	// operator see the addresses and decide. Module authors who want a hard
	// gate should consume TF_VAR_operation / TF_VAR_ephemeral and design the
	// destroy contract in HCL.
	Protected []string
	// DriftedAttributes lists destroy-behavior attributes (see destroyBehaviorAttributes)
	// whose config value disagrees with state on a resource this plan will destroy.
	// plan -destroy never re-diffs these against config, so a stale state value would
	// otherwise persist silently through destroy. Populated only on destroy-plan paths.
	// Best-effort: a failure detecting drift never fails the plan, so this can be nil
	// even when drift exists.
	DriftedAttributes []DestroyAttributeDrift
	Err               error
}

TerraformComponentPlan holds the plan result for a single Terraform component. ComponentID is the unique identifier (Name when set, else Path). Path carries the component's blueprint Path field (e.g., "cluster/aws-eks") so renderers can show the underlying module location alongside or instead of the short ID. Add, Change, and Destroy reflect terraform's "to add / to change / to destroy" counts. NoChanges is true when terraform reports no changes. IsNew is true when no state exists for the component in the configured backend — the component has never been applied. Resources is the per-resource change list extracted from the plan output; it is empty when IsNew is true, when the plan errored, or when terraform reports no changes. Err is non-nil when the component's init or plan step failed; subsequent layers may still be attempted.

IsNew supersedes the count fields: when IsNew is true, terraform plan is not executed (it would either misreport "all creates" or fail reading dependent upstream state), so Add/Change/Destroy are zero and NoChanges is false. JSON consumers detecting "pending work" must check IsNew alongside the counts — `IsNew || Add+Change+Destroy > 0` rather than counts alone.

IsNew has two operator-facing meanings depending on which producer populated the struct, and the struct itself does not carry a mode flag — callers route this disambiguation. Apply-side producers (PlanSummary, PlanComponentSummary) set IsNew when the component has never been applied, rendered as "(new)". Destroy-side producers (PlanDestroySummary, PlanDestroyComponentSummary) set IsNew when there is no state to destroy, rendered as "(no state)". Renderers must therefore route apply and destroy results through distinct formatters — calling the apply-side formatter on a destroy-side result would emit "(new)" for a component that has nothing to tear down, which is misleading.

type TerraformStack

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

TerraformStack manages Terraform infrastructure components by initializing and applying Terraform configurations. It processes components in order, generating terraform arguments, running Terraform init, plan, and apply operations. Progress and non-blocking warnings go to the presenter in the context of each operation.

func (*TerraformStack) Apply added in v0.9.0

func (s *TerraformStack) Apply(ctx context.Context, blueprint *blueprintv1alpha1.Blueprint, componentID string) error

Apply runs terraform init, plan, and apply for the component with the given ID. It returns an error if a terraform command fails. A component that is not in the blueprint, or a component directory that does not exist, returns an error with a remediation hint.

func (*TerraformStack) BackendPointerType added in v0.10.0

func (s *TerraformStack) BackendPointerType(componentID string) (string, error)

BackendPointerType returns the backend type that the backend pointer of the component records. The pointer is the file that terraform init writes to TF_DATA_DIR. It returns "" when the pointer does not exist or does not parse.

func (*TerraformStack) Destroy added in v0.9.0

func (s *TerraformStack) Destroy(ctx context.Context, blueprint *blueprintv1alpha1.Blueprint, componentID string) (bool, error)

Destroy tears down a single component idempotently: init → pre-refresh state check → refresh → post-refresh state check → destroy, skipping the rest when state is empty at either check. Returns (true, nil) when skipped, (false, nil) on success, (false, err) on failure. Destroy-mode config (S3 force_destroy, etc.) is honored via TF_VAR_operation; no prep-apply is run because that could recreate resources refresh just dropped.

The whole sequence is wrapped in presenter.Track("Destroying <path>") so the visible label matches the bulk DestroyAll loop body — mixing this method into the per-component destroy dance (which calls bulk DestroyAll for non-backend components and this method for backend) would otherwise produce inconsistent "Destroying X" / "Destroying terraform for X" lines side by side. The terraform destroy exec runs silently inside the spinner for the same reason: the bulk loop is silent, so single-component Destroy must be too. Destroy is bounded by destroyIdleTimeout/destroyAbsoluteTimeout and retried via execTerraformDestroyWithRetry; refresh by refreshBeforeDestroy.

func (*TerraformStack) DestroyAll added in v0.9.0

func (s *TerraformStack) DestroyAll(ctx context.Context, blueprint *blueprintv1alpha1.Blueprint, continueOnError bool, excludeIDs ...string) (DestroyOutcome, error)

DestroyAll destroys components in reverse dependency order. For each component, it runs init, checks state, refreshes, checks state again, then destroys, skipping the rest of the flow once state is empty.

  • Destroy=false: skips the component, but still clears its backend pointer.
  • excludeIDs: skips the component entirely. The cmd layer uses this to destroy the backend component last, after migrating its state to local.
  • continueOnError=true: collects each error in DestroyOutcome.Failed and continues.
  • continueOnError=false: stops at the first error and returns a partial DestroyOutcome.

Each destroy is bounded by destroyIdleTimeout/destroyAbsoluteTimeout and retried via execTerraformDestroyWithRetry; each refresh by refreshBeforeDestroy.

func (*TerraformStack) HasLocalStateWithResources added in v0.9.0

func (s *TerraformStack) HasLocalStateWithResources(componentID string) (bool, error)

HasLocalStateWithResources reports whether the per-component local state file exists and contains at least one resource entry. Reads the file as JSON; no terraform invocation. Missing files report (false, nil).

func (*TerraformStack) HasRemoteState added in v0.9.0

func (s *TerraformStack) HasRemoteState(blueprint *blueprintv1alpha1.Blueprint, componentID string) (bool, error)

HasRemoteState reports whether the named component has non-empty terraform state in the currently-configured backend. Runs init + `terraform show -json`; callers must invoke before any in-memory backend override.

func (*TerraformStack) InitComponent added in v0.9.0

func (s *TerraformStack) InitComponent(blueprint *blueprintv1alpha1.Blueprint, componentID string) error

InitComponent runs `terraform init` for one component using the currently- configured backend; no -migrate-state, no plan, no apply.

func (*TerraformStack) ListLocalStateComponentIDs added in v0.9.1

func (s *TerraformStack) ListLocalStateComponentIDs() ([]string, error)

ListLocalStateComponentIDs returns every componentID with local Terraform state on disk, whether or not it is still declared in the active blueprint. Thin passthrough: TerraformProvider owns the on-disk .tfstate layout.

func (*TerraformStack) LocalStateSnapshot added in v0.10.0

func (s *TerraformStack) LocalStateSnapshot(componentID string) (*StateSnapshot, error)

LocalStateSnapshot reads the local state file of the component. It returns nil and no error when the file does not exist. It runs no terraform command.

func (*TerraformStack) MigrateComponentState added in v0.9.0

func (s *TerraformStack) MigrateComponentState(blueprint *blueprintv1alpha1.Blueprint, componentID string) error

MigrateComponentState runs terraform init -migrate-state -force-copy for one component. It moves the state of the component to the configured backend. windsor bootstrap calls it after it applies the backend component with a local backend. It returns an error if the blueprint is nil or a terraform command fails. A component that is not in the blueprint, or a component directory that does not exist, returns an error with a remediation hint.

func (*TerraformStack) MigrateState added in v0.9.0

func (s *TerraformStack) MigrateState(ctx context.Context, blueprint *blueprintv1alpha1.Blueprint) ([]string, error)

MigrateState runs `terraform init -migrate-state -force-copy` per component to move state to the currently configured backend. Components whose directories don't exist on disk are skipped and their IDs returned in the skipped slice, paired with any error so callers see both what migrated and what didn't. Stops on the first failure; safe to retry.

func (*TerraformStack) Plan added in v0.9.0

func (s *TerraformStack) Plan(blueprint *blueprintv1alpha1.Blueprint, componentID string) error

Plan runs terraform init and plan for a single component identified by componentID. It resolves the component from the blueprint, sets up the environment, and executes init then plan without applying any changes. Returns an error if the component is not found, the directory does not exist, or any terraform operation fails.

func (*TerraformStack) PlanAll added in v0.9.0

func (s *TerraformStack) PlanAll(blueprint *blueprintv1alpha1.Blueprint) error

PlanAll runs terraform init and plan for every enabled component in the blueprint, streaming output directly to stdout. Stops on the first error. Returns an error if blueprint is nil or any component's init or plan step fails.

func (*TerraformStack) PlanAllJSON added in v0.9.0

func (s *TerraformStack) PlanAllJSON(blueprint *blueprintv1alpha1.Blueprint) error

PlanAllJSON runs terraform init and plan -json for every enabled component in the blueprint, streaming machine-readable JSON lines to stdout. Stops on the first error. Returns an error if blueprint is nil or any component's init or plan step fails.

func (*TerraformStack) PlanAllResourceChangesJSON added in v0.9.1

func (s *TerraformStack) PlanAllResourceChangesJSON(blueprint *blueprintv1alpha1.Blueprint) error

PlanAllResourceChangesJSON runs terraform init, plan, and show -json for every enabled component in the blueprint, streaming each component's plan document directly to stdout. Stops on the first error. Returns an error if blueprint is nil or any component's terraform operation fails.

func (*TerraformStack) PlanComponentSummary added in v0.9.0

func (s *TerraformStack) PlanComponentSummary(blueprint *blueprintv1alpha1.Blueprint, componentID string) TerraformComponentPlan

PlanComponentSummary runs terraform init and plan for one component and returns its plan result. It resolves only that component from the blueprint, so it plans no other component. It puts a failure in the Err field of the result, as PlanSummary does. A component that is not in the blueprint sets Err with a remediation hint.

func (*TerraformStack) PlanDestroyComponentSummary added in v0.9.0

func (s *TerraformStack) PlanDestroyComponentSummary(blueprint *blueprintv1alpha1.Blueprint, componentID string) TerraformComponentPlan

PlanDestroyComponentSummary runs terraform init and plan -destroy for one component. It returns the plan result of the component, and puts a failure in the Err field of the result. A component that is not in the blueprint sets Err with a remediation hint. A component with destroy set to false also sets Err with a hint, because Teardown skips that component.

func (*TerraformStack) PlanDestroySummary added in v0.9.0

func (s *TerraformStack) PlanDestroySummary(blueprint *blueprintv1alpha1.Blueprint) []TerraformComponentPlan

PlanDestroySummary runs terraform init and `plan -destroy` for every component in the blueprint that is not pinned with Destroy=false, capturing the destroy counts and the per-resource list rather than printing them. Components with Destroy=false are filtered out so the rendered plan matches what Teardown would actually destroy — including them would lie. As with PlanSummary, errors are recorded per-component and the summary continues so callers receive partial results for independent layers. Returns nil if blueprint is nil or projectRoot is unset.

func (*TerraformStack) PlanJSON added in v0.9.0

func (s *TerraformStack) PlanJSON(blueprint *blueprintv1alpha1.Blueprint, componentID string) error

PlanJSON runs terraform init and plan -json for a single component identified by componentID, streaming machine-readable JSON lines to stdout. Returns an error if the component is not found, the directory does not exist, or any terraform operation fails.

func (*TerraformStack) PlanResourceChangesJSON added in v0.9.1

func (s *TerraformStack) PlanResourceChangesJSON(blueprint *blueprintv1alpha1.Blueprint, componentID string) error

PlanResourceChangesJSON runs terraform init, plan, and show -json for a single component identified by componentID, printing the resulting plan document to stdout. Returns an error if the component is not found, the directory does not exist, or any terraform operation fails.

func (*TerraformStack) PlanSummary added in v0.9.0

PlanSummary runs terraform init and plan for every enabled component in the blueprint, capturing output to parse add/change/destroy counts rather than printing them. Errors are recorded per-component; the summary continues even if a component fails, so callers receive partial results for independent layers. Returns nil if blueprint is nil.

func (*TerraformStack) PostApply added in v0.9.0

func (s *TerraformStack) PostApply(fns ...func(ctx context.Context, id string) error)

PostApply registers hooks to run after each component's WithProgress block completes (i.e. after Done is printed). Hooks are consumed and cleared at the start of the next Up call so they are not retained.

func (*TerraformStack) RemoveLocalState added in v0.9.0

func (s *TerraformStack) RemoveLocalState(componentID string) error

RemoveLocalState removes the per-component local state file (and its .backup sibling) under the windsor scratch path. Missing files are tolerated.

func (*TerraformStack) StateSnapshot added in v0.10.0

func (s *TerraformStack) StateSnapshot(blueprint *blueprintv1alpha1.Blueprint, componentID string) (*StateSnapshot, error)

StateSnapshot reads the state of the component from the configured backend with terraform state pull. It runs a read-only init first, so it moves no state. It returns nil and no error when the backend holds no state for the component.

func (*TerraformStack) Up

func (s *TerraformStack) Up(ctx context.Context, blueprint *blueprintv1alpha1.Blueprint, onApply ...func(ctx context.Context, id string) (bool, error)) (bool, error)

Up runs terraform init, plan, and apply for each component in order. It removes the backend override files after all components finish, so terraform_output() works between components. The onApply hooks run inside each spinner. The PostApply hooks run after each Done line, and Up clears them. A hook can return halted=true to stop the apply after its component with no error. A missing component directory returns an error with a remediation hint.

Jump to

Keyboard shortcuts

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