Documentation
¶
Index ¶
- Constants
- func ActionForMode(mode, event string) (string, error)
- func AppendExecPath(env []string, terraformCommand string) []string
- func AppendPlanVarFile(env []string, varfile string) []string
- func BackendHistoryEnv(backendType string, backend map[string]any) []string
- func BackendHistoryValues(backendType string, backend map[string]any) map[string]string
- func BuildArgs(opts Options) ([]string, error)
- func DefaultConfigHCL(input *DefaultConfigInput) string
- func EnsureDefaultConfig(input *DefaultConfigInput) (string, func(), error)
- func EnsureLocalHistoryDir(componentDir, configPath string, env []string) error
- func EnsureResolved(resolved string) error
- func HasMigrationsDir(componentDir string) bool
- func HistoryEnv(stack, component, workspace string) []string
- func MigrationDirFor(componentDir string) string
- func NoMigrationsToRun(migration, componentDir string) bool
- func StripMigrationDirPrefix(migration, componentDir string) string
- type DefaultConfigInput
- type HistoryValues
- type Options
Constants ¶
const ( ActionPlan = "plan" ActionApply = "apply" ModeDynamic = "dynamic" ModePlan = ActionPlan ModeApply = ActionApply Command = "tfmigrate" ExecPathEnvVar = "TFMIGRATE_EXEC_PATH" // EnvTfCliArgsPlan is honored by terraform/tofu for every `plan` they run. // Tfmigrate verifies migrations by invoking `terraform plan` itself, without // the -var-file argument Atmos normally passes, so the generated varfile is // routed through this variable instead. EnvTfCliArgsPlan = "TF_CLI_ARGS_plan" EnvStack = "ATMOS_STACK" EnvComponent = "ATMOS_COMPONENT" EnvWorkspace = "ATMOS_TERRAFORM_WORKSPACE" EnvHistoryNamespace = "ATMOS_TFMIGRATE_HISTORY_NAMESPACE" EnvHistoryKey = "ATMOS_TFMIGRATE_HISTORY_KEY" EnvHistoryPath = "ATMOS_TFMIGRATE_HISTORY_PATH" EnvHistoryStorage = "ATMOS_TFMIGRATE_HISTORY_STORAGE" EnvHistoryBucket = "ATMOS_TFMIGRATE_HISTORY_BUCKET" EnvHistoryRegion = "ATMOS_TFMIGRATE_HISTORY_REGION" EnvHistoryProfile = "ATMOS_TFMIGRATE_HISTORY_PROFILE" EnvHistoryRoleARN = "ATMOS_TFMIGRATE_HISTORY_ROLE_ARN" EnvHistoryEndpoint = "ATMOS_TFMIGRATE_HISTORY_ENDPOINT" EnvHistoryKMSKeyID = "ATMOS_TFMIGRATE_HISTORY_KMS_KEY_ID" )
const ( // ConfigEnvVar is tfmigrate's own config-path environment variable; when the // user sets it, Atmos must not override their config. ConfigEnvVar = "TFMIGRATE_CONFIG" )
Variables ¶
This section is empty.
Functions ¶
func ActionForMode ¶
ActionForMode resolves a hook mode and lifecycle event to a tfmigrate action.
func AppendExecPath ¶
AppendExecPath adds TFMIGRATE_EXEC_PATH unless it is already configured.
func AppendPlanVarFile ¶
AppendPlanVarFile routes the Atmos-generated varfile to the terraform plan runs tfmigrate performs internally, via TF_CLI_ARGS_plan. Without it, any component with required variables fails tfmigrate's convergence plan with "No value for required variable". Existing TF_CLI_ARGS_plan values (from the component env or the process environment) are preserved and extended.
Varfile must be an absolute path: TF_CLI_ARGS_plan is a single, global env var applied to every `terraform plan` tfmigrate runs internally, and for `migration "multi_state"` that includes a convergence-check plan in a *second* directory (from_dir) as well as the triggering component's own directory (to_dir). An absolute path resolves correctly regardless of which of the two tfmigrate's cwd is. This does not make multi_state fully correct when from_dir/to_dir have materially different variables (the same varfile is applied to both plans, since tfmigrate exposes no way to give the two a different -var-file) - callers with that setup should still set from_skip_plan/to_skip_plan on the migration block.
func BackendHistoryEnv ¶
BackendHistoryEnv exposes Terraform backend values that tfmigrate history storage can reuse from its config file.
func BackendHistoryValues ¶
BackendHistoryValues returns Terraform backend values that tfmigrate history storage can reuse from its config file.
func DefaultConfigHCL ¶
func DefaultConfigHCL(input *DefaultConfigInput) string
DefaultConfigHCL renders the generated tfmigrate configuration.
func EnsureDefaultConfig ¶
func EnsureDefaultConfig(input *DefaultConfigInput) (string, func(), error)
EnsureDefaultConfig makes tfmigrate history mode work with zero user configuration: when the user has not provided a tfmigrate config (no --tfmigrate-config flag or hook config, no .tfmigrate.hcl in the component working directory, no TFMIGRATE_CONFIG), it generates one that reuses the component's Terraform backend as history storage — S3 and GCS backends store history in the same bucket under the namespaced Atmos history key; any other backend falls back to a local history file (next to a local-backend state file when one is configured, so it survives workdir re-provisioning).
Returns the generated config path and a cleanup function, or "" when the user's own configuration should be used untouched.
func EnsureLocalHistoryDir ¶
EnsureLocalHistoryDir creates the parent directory of a tfmigrate local history file so first runs don't fail with "no such file or directory": tfmigrate's local storage writes the history file without creating missing directories, and a failed history save after a successful state push leaves the migration applied but unrecorded, wedging subsequent runs.
The tfmigrate config is parsed best-effort. Any read, parse, or evaluation problem leaves the filesystem untouched and returns nil, keeping tfmigrate itself the source of truth for config errors. Only a failed directory creation is returned as an error.
func EnsureResolved ¶
EnsureResolved verifies that the resolved tfmigrate command points at an installed binary. Toolchain resolution returns the bare command name unchanged when the tool is neither toolchain-managed nor on PATH, which would otherwise surface as a raw exec failure mid-run.
func HasMigrationsDir ¶
HasMigrationsDir reports whether the component has a conventional migrations/ subdirectory. Exported so callers can tell "no migrations authored yet" apart from "migrations exist but none are unapplied" before invoking tfmigrate in zero-config history mode: without a migrations/ dir, MigrationDirFor falls back to the component root, which also holds Atmos's generated backend.tf.json/tfvars.json - letting tfmigrate's history-mode file scan run there makes it try (and fail) to parse those as migrations.
func HistoryEnv ¶
HistoryEnv returns stable per-instance variables for tfmigrate history config. Tfmigrate HCL can reference these through the `env` object, for example: key = "${env.ATMOS_TFMIGRATE_HISTORY_KEY}".
func MigrationDirFor ¶
MigrationDirFor points tfmigrate at the conventional migrations/ directory when the component has one; otherwise the component root. Exported so callers building a `--migration <path>` value can strip a redundant migration_dir-matching prefix before handing it to tfmigrate, which resolves --migration relative to migration_dir itself (see StripMigrationDirPrefix).
func NoMigrationsToRun ¶
NoMigrationsToRun reports whether zero-config history mode has nothing to run for this component: no explicit single-file migration was requested, and no migrations/ directory exists yet to hold any. Callers should skip invoking tfmigrate entirely in this case and report it, rather than let MigrationDirFor's component-root fallback make tfmigrate's history-mode file scan try (and fail) to parse Atmos's own generated files as migrations.
func StripMigrationDirPrefix ¶
StripMigrationDirPrefix removes a leading migration_dir-matching prefix from a user-supplied --migration path, when the zero-config default migration_dir applies (i.e. Atmos generated the tfmigrate config, so Atmos - not the user - controls migration_dir). Without this, a natural-looking path like "migrations/foo.hcl" (which really is the migration file's path relative to the component dir) silently double-prefixes into "migrations/migrations/foo.hcl" once tfmigrate resolves it relative to migration_dir itself, producing a confusing "no such file" error.
Types ¶
type DefaultConfigInput ¶
type DefaultConfigInput struct {
ComponentDir string
BackendType string
Backend map[string]any
History HistoryValues
}
DefaultConfigInput carries the component context needed to generate a default tfmigrate config that inherits the component's Terraform backend as history storage.
type HistoryValues ¶
type HistoryValues struct {
Stack string
Component string
Workspace string
Namespace string
Key string
}
HistoryValues contains stable tfmigrate history identifiers for an Atmos component instance.
func HistoryNames ¶
func HistoryNames(stack, component, workspace string) HistoryValues
HistoryNames returns stable per-instance values for tfmigrate history config.