provisioner

package
v1.222.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const CanonicalLockFilename = ".terraform.lock.hcl"

CanonicalLockFilename is Terraform's fixed dependency lock filename. It is the only lock name terraform/tofu read; Atmos treats it as scratch for ephemeral/vendored components and keeps the committed truth in the per-instance file (see InstanceLockFilename).

View Source
const HookEventBeforeTerraformInit = HookEvent("before.terraform.init")

HookEventBeforeTerraformInit is the hook event for before terraform init.

View Source
const LockFilePerm = 0o644

LockFilePerm is the permission for committed/restored lock files (non-sensitive).

Variables

View Source
var ErrUnsupportedProvisionerType = errors.New("unsupported provisioner type")

Error types for provisioning operations.

Functions

func DeleteBackendWithParams

func DeleteBackendWithParams(params *DeleteBackendParams) error

DeleteBackendWithParams deletes a backend using a params struct.

func DescribeBackend

func DescribeBackend(atmosConfig *schema.AtmosConfiguration, component string, opts interface{}) error

DescribeBackend returns the backend configuration from stack.

func ExecuteProvisioners

func ExecuteProvisioners(
	ctx context.Context,
	event HookEvent,
	atmosConfig *schema.AtmosConfiguration,
	componentConfig map[string]any,
	authContext *schema.AuthContext,
	execCtx ...*TerraformExecContext,
) error

ExecuteProvisioners executes all provisioners registered for a specific hook event. Returns an error if any provisioner fails (fail-fast behavior).

The execCtx is optional: events that run a terraform subcommand (e.g. after.terraform.init) pass a single *TerraformExecContext; before-events and callers without one pass nothing. It is variadic so the many existing call sites that have no execution context need no change.

func InstanceKey

func InstanceKey(componentConfig map[string]any) string

InstanceKey derives a filesystem-safe identifier for a (stack, component) instance from its component config, matching the <stack>-<component> scheme used elsewhere (e.g. workdir.BuildPath). It is the disambiguator for per-instance lock files so that divergent stacks of one Terraform root module never collide.

func InstanceLockFilename

func InstanceLockFilename(componentConfig map[string]any) string

InstanceLockFilename returns the per-instance lock filename for an instance, e.g. ".dev-vpc.terraform.lock.hcl". The leading dot keeps it hidden alongside the canonical .terraform.lock.hcl; for ephemeral/vendored components the canonical file is treated as scratch while this per-instance file is the committed source of truth.

func ListBackends

func ListBackends(atmosConfig *schema.AtmosConfiguration, opts interface{}) error

ListBackends lists all backends in a stack.

func LockCoordPath

func LockCoordPath(lockPath string) string

LockCoordPath maps a lock-file path to a stable, machine-local coordination path (under the temp dir, keyed by the absolute lock path) so the advisory flock sidecar never lands in — and pollutes — a committed component directory.

func ProvisionWithParams

func ProvisionWithParams(params *ProvisionParams) error

Provision provisions infrastructure resources using a params struct. It validates the provisioner type, loads component configuration, and executes the provisioner.

func RegisterProvisioner

func RegisterProvisioner(p Provisioner) error

RegisterProvisioner registers a provisioner for a specific hook event. Provisioners self-declare when they should run by specifying a hook event. Returns an error if Func is nil or HookEvent is empty.

func RestorePerInstanceLock

func RestorePerInstanceLock(srcDir, workingDir string, componentConfig map[string]any) error

RestorePerInstanceLock seeds workingDir's canonical .terraform.lock.hcl from the committed per-instance lock (.<stack>-<component>.terraform.lock.hcl) in srcDir, when one exists, so terraform init honors the instance's pinned providers and hashes. It is the pre-init counterpart to the after.terraform.init persist step. A missing per-instance lock is a no-op (first run for this instance). The write is serialized with a file lock.

Types

type DeleteBackendParams

type DeleteBackendParams struct {
	AtmosConfig       *schema.AtmosConfiguration
	Component         string
	Stack             string
	Force             bool
	DescribeComponent ExecuteDescribeComponentFunc
	AuthContext       *schema.AuthContext
}

DeleteBackendParams contains parameters for the DeleteBackend function.

type ExecuteDescribeComponentFunc

type ExecuteDescribeComponentFunc func(
	component string,
	stack string,
) (map[string]any, error)

ExecuteDescribeComponentFunc is a function that describes a component from a stack. This allows us to inject the describe component logic without circular dependencies.

type HookEvent

type HookEvent string

HookEvent represents when a provisioner should run. This is a string type alias compatible with pkg/hooks.HookEvent to avoid circular dependencies. Use pkg/hooks.HookEvent constants (e.g., hooks.BeforeTerraformInit) when registering provisioners.

type ProvisionParams

type ProvisionParams struct {
	AtmosConfig       *schema.AtmosConfiguration
	ProvisionerType   string
	Component         string
	Stack             string
	DescribeComponent ExecuteDescribeComponentFunc
	AuthContext       *schema.AuthContext
}

ProvisionParams contains parameters for the Provision function.

type Provisioner

type Provisioner struct {
	// Type is the provisioner type (e.g., "backend", "component").
	Type string

	// HookEvent declares when this provisioner should run.
	// Must not be empty; use pkg/hooks.HookEvent constants.
	HookEvent HookEvent

	// Func is the provisioning function to execute.
	// Must not be nil.
	Func ProvisionerFunc
}

Provisioner represents a self-registering provisioner. All fields are validated at registration time by RegisterProvisioner.

func GetProvisionersForEvent

func GetProvisionersForEvent(event HookEvent) []Provisioner

GetProvisionersForEvent returns all provisioners registered for a specific hook event.

type ProvisionerFunc

type ProvisionerFunc func(
	ctx context.Context,
	atmosConfig *schema.AtmosConfiguration,
	componentConfig map[string]any,
	authContext *schema.AuthContext,
	execCtx *TerraformExecContext,
) error

ProvisionerFunc is a function that provisions infrastructure. It receives the Atmos configuration, component configuration, auth context, and an optional terraform execution context (nil unless the dispatching event provides one). Returns an error if provisioning fails.

type TerraformExecContext

type TerraformExecContext struct {
	// Run executes a terraform/tofu subcommand (args after the binary, e.g.
	// {"providers","lock","-platform=linux_amd64"}) with the live env, RC, and workdir.
	Run func(args []string) error
	// WorkingDir is the resolved component/workdir path the subcommand runs in.
	WorkingDir string
}

TerraformExecContext carries the live execution environment for provisioners that must run a terraform/tofu subcommand against the same working directory, binary, RC, and environment as the triggering command (e.g. the post-init providers-lock hook). It is nil for events where no subprocess context is available (e.g. before.terraform.init, whose provisioners use in-process SDKs). It lives here, with the runner closure built in the exec layer, so pkg/provisioner does not need to import internal/exec (a cycle).

Directories

Path Synopsis
Package lock provides the built-in after.terraform.init provisioner that keeps .terraform.lock.hcl complete across all configured platforms.
Package lock provides the built-in after.terraform.init provisioner that keeps .terraform.lock.hcl complete across all configured platforms.
Package source provides just-in-time (JIT) vendoring of component sources from source configuration in stack manifests.
Package source provides just-in-time (JIT) vendoring of component sources from source configuration in stack manifests.
cmd
Package cmd provides reusable CLI command builders for source provisioning.
Package cmd provides reusable CLI command builders for source provisioning.

Jump to

Keyboard shortcuts

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