terramate

package
v0.46.7 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package terramate provides Terramate execution capabilities for Day 2 operations. Terramate enables drift detection, change sets, and orchestrated deployments.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BinaryName

func BinaryName() string

BinaryName returns the Terramate executable name for the current platform.

func CreateRootConfig

func CreateRootConfig(projectName string) string

CreateRootConfig creates a root terramate.tm.hcl configuration

func CreateStackConfig

func CreateStackConfig(path, name, description string) string

CreateStackConfig creates a terramate.tm.hcl configuration file

func DefaultBinary

func DefaultBinary() string

DefaultBinary resolves the Terramate binary used by regular execution. Missing release packaging resolves to an impossible path so host PATH cannot mask an incomplete StackKit package.

func PackagedBinaryPath

func PackagedBinaryPath() (string, bool)

PackagedBinaryPath returns the StackKit-packaged Terramate binary path. It intentionally does not fall back to PATH: advanced mode must prove the StackKit release package contains its own lifecycle toolchain.

Types

type Change

type Change struct {
	ResourceType string `json:"resourceType"`
	ResourceName string `json:"resourceName"`
	Action       string `json:"action"` // "create", "update", "delete", "no-op"
	Details      string `json:"details,omitempty"`
}

Change represents a detected change

type DriftResult

type DriftResult struct {
	HasDrift  bool          `json:"hasDrift"`
	Stacks    []StackDrift  `json:"stacks"`
	CheckedAt time.Time     `json:"checkedAt"`
	Duration  time.Duration `json:"duration"`
}

DriftResult represents the result of drift detection

type Executor

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

Executor handles Terramate command execution

func NewExecutor

func NewExecutor(opts ...ExecutorOption) *Executor

NewExecutor creates a new Terramate executor

func (*Executor) DetectDrift

func (e *Executor) DetectDrift(ctx context.Context) (*DriftResult, error)

DetectDrift runs drift detection across all stacks

func (*Executor) Generate

func (e *Executor) Generate(ctx context.Context) (*Result, error)

Generate generates code from Terramate configurations

func (*Executor) Init

func (e *Executor) Init(ctx context.Context) (*Result, error)

Init initializes Terramate in the workspace

func (*Executor) IsInstalled

func (e *Executor) IsInstalled() bool

IsInstalled checks if Terramate is installed

func (*Executor) List

func (e *Executor) List(ctx context.Context) ([]Stack, error)

List lists all stacks

func (*Executor) ListChanged

func (e *Executor) ListChanged(ctx context.Context) ([]Stack, error)

ListChanged lists stacks with changes (for change detection)

func (*Executor) ListRunOrder added in v0.46.5

func (e *Executor) ListRunOrder(ctx context.Context, tags string) ([]string, error)

ListRunOrder returns the stack directories, relative to the project root, that match tags in the order `terramate run` would execute them. It never consults Git change detection.

func (*Executor) Output

func (e *Executor) Output(ctx context.Context) (*Result, error)

Output gets outputs from all stacks

func (*Executor) Refresh

func (e *Executor) Refresh(ctx context.Context) (*Result, error)

Refresh runs tofu refresh on all stacks

func (*Executor) RunApply

func (e *Executor) RunApply(ctx context.Context, autoApprove bool) (*Result, error)

RunApply runs tofu apply on all stacks

func (*Executor) RunDestroy

func (e *Executor) RunDestroy(ctx context.Context, autoApprove bool) (*Result, error)

RunDestroy runs tofu destroy on all stacks

func (*Executor) RunInit

func (e *Executor) RunInit(ctx context.Context) (*Result, error)

RunInit runs tofu init on all stacks

func (*Executor) RunPlan

func (e *Executor) RunPlan(ctx context.Context) (*Result, error)

RunPlan runs tofu plan on all stacks

func (*Executor) RunStackTofu added in v0.46.5

func (e *Executor) RunStackTofu(ctx context.Context, tags string, args ...string) (*Result, error)

RunStackTofu runs `terramate run --no-recursive` in the working directory, which must be one stack directory, so exactly that stack runs the packaged OpenTofu binary with args. Terramate reports every failing command with exit code 1; the returned Result carries the exit code of the OpenTofu process itself (for example 2 from `plan -detailed-exitcode`). An error is returned only when Terramate failed without a command exit status.

func (*Executor) Version

func (e *Executor) Version(ctx context.Context) (string, error)

Version returns the Terramate version

type ExecutorOption

type ExecutorOption func(*Executor)

ExecutorOption configures the Executor

func WithBinary

func WithBinary(binary string) ExecutorOption

WithBinary sets the terramate binary path

func WithChangeDetection

func WithChangeDetection(enabled bool) ExecutorOption

WithChangeDetection enables Git-based change detection

func WithEnv added in v0.46.5

func WithEnv(values ...string) ExecutorOption

WithEnv appends environment values for Terramate and the commands it runs. Later values win over inherited ones.

func WithParallelism

func WithParallelism(p int) ExecutorOption

WithParallelism sets the parallelism level

func WithTimeout

func WithTimeout(timeout time.Duration) ExecutorOption

WithTimeout sets the execution timeout

func WithTofuBinary

func WithTofuBinary(binary string) ExecutorOption

WithTofuBinary sets the OpenTofu binary for terramate run

func WithWorkDir

func WithWorkDir(dir string) ExecutorOption

WithWorkDir sets the working directory

func WithoutInheritedEnv added in v0.46.5

func WithoutInheritedEnv(names ...string) ExecutorOption

WithoutInheritedEnv drops the named variables from the inherited process environment before WithEnv values are appended, so no host OpenTofu CLI override reaches a stack run.

type Result

type Result struct {
	Success  bool          `json:"success"`
	ExitCode int           `json:"exitCode"`
	Stdout   string        `json:"stdout"`
	Stderr   string        `json:"stderr"`
	Duration time.Duration `json:"duration"`
}

Result represents the result of a terramate command

type Stack

type Stack struct {
	ID          string            `json:"id"`
	Name        string            `json:"name"`
	Description string            `json:"description,omitempty"`
	Path        string            `json:"path"`
	Tags        []string          `json:"tags,omitempty"`
	Metadata    map[string]string `json:"metadata,omitempty"`
}

Stack represents a Terramate stack

type StackDrift

type StackDrift struct {
	Path     string   `json:"path"`
	Name     string   `json:"name"`
	HasDrift bool     `json:"hasDrift"`
	Changes  []Change `json:"changes,omitempty"`
	Error    string   `json:"error,omitempty"`
}

StackDrift represents drift in a single stack

Jump to

Keyboard shortcuts

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