arguments

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultParallelism = 10

DefaultParallelism is the limit OpenTofu places on total parallel operations as it walks the dependency graph.

View Source
const DefaultStateFilename = "terraform.tfstate"

DefaultStateFilename is the default filename used for the state file.

Variables

This section is empty.

Functions

func OpenJSONIntoFile

func OpenJSONIntoFile(jsonIntoFlag string) (*os.File, func(), tfdiags.Diagnostics)

Types

type Apply

type Apply struct {
	// State, Operation, and Vars are the common extended flags
	State     *State
	Operation *Operation
	Vars      *Vars

	// AutoApprove skips the manual verification step for the apply operation.
	AutoApprove bool

	// PlanPath contains an optional path to a stored plan file
	PlanPath string

	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions

	// ShowSensitive is used to display the value of variables marked as sensitive.
	ShowSensitive bool

	// SuppressForgetErrorsDuringDestroy suppresses the error that occurs when a
	// destroy operation completes successfully but leaves forgotten instances behind.
	SuppressForgetErrorsDuringDestroy bool

	// Verbose asks a command to print detail it would otherwise summarize.
	// See [Plan.Verbose] for what it is for and why it lives on Apply
	// directly rather than behind a shared, every-command flag: "-verbose"
	// already names an unrelated flag on "choudoufu test" and "choudoufu
	// graph" parsed ahead of a shared flag set's own turn.
	Verbose bool
}

Apply represents the command-line arguments for the apply command.

func ParseApply

func ParseApply(args []string) (*Apply, func(), tfdiags.Diagnostics)

ParseApply processes CLI arguments, returning an Apply value, a closer function, and errors. If errors are encountered, an Apply value is still returned representing the best effort interpretation of the arguments.

func ParseApplyDestroy

func ParseApplyDestroy(args []string) (*Apply, func(), tfdiags.Diagnostics)

ParseApplyDestroy is a special case of ParseApply that deals with the "tofu destroy" command, which is effectively an alias for "tofu apply -destroy".

type Backend

type Backend struct {
	// IgnoreRemoteVersion is used with commands which write state to allow users to write remote
	// state even if the remote and local OpenTofu versions don't match.
	IgnoreRemoteVersion bool
	// ForceInitCopy suppresses confirmation for copying state data during init.
	ForceInitCopy bool
	// Reconfigure forces init to ignore any stored configuration.
	Reconfigure bool
	// MigrateState confirms the user wishes to migrate from the prior backend configuration to a new configuration.
	MigrateState bool
}

func (*Backend) AddIgnoreRemoteVersionFlag

func (b *Backend) AddIgnoreRemoteVersionFlag(f *flag.FlagSet)

func (*Backend) AddMigrationFlags

func (b *Backend) AddMigrationFlags(f *flag.FlagSet)

type Console

type Console struct {
	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions
	// Vars holds and provides information for the flags related to variables that a user can give into the process
	Vars *Vars
	// State is used for the state related flags
	State *State
}

Console represents the command-line arguments for the console command.

func ParseConsole

func ParseConsole(args []string) (*Console, func(), tfdiags.Diagnostics)

ParseConsole processes CLI arguments, returning a Console value, a closer function, and errors. If errors are encountered, a Console value is still returned representing the best effort interpretation of the arguments.

type DeprecationWarningLevel

type DeprecationWarningLevel uint8

DeprecationWarningLevel defines different levels of deprecation warnings that can be used by the user to control what type of warnings it wants to see

const (
	// DeprecationWarningLevelAll shows all deprecation warnings for outputs and variables, where no filtering is applied.
	DeprecationWarningLevelAll DeprecationWarningLevel = iota
	// DeprecationWarningLevelLocal shows only the deprecation warnings for the outputs and variables that are coming from
	// modules that are referenced with a relative path (aka local module).
	DeprecationWarningLevelLocal
	// DeprecationWarningLevelNone disables any deprecation warnings, filtering out any diagnostic that was generated about
	// this.
	DeprecationWarningLevelNone
)

func ParseDeprecatedWarningLevel

func ParseDeprecatedWarningLevel(s string) DeprecationWarningLevel

ParseDeprecatedWarningLevel gets in a string and returns a DeprecationWarningLevel. Since these warnings are not critical to the system, this method is returning no error when the warn level identifier is missing a mapping. Instead, it falls back on returning the level that will write all the deprecation warnings.

func (DeprecationWarningLevel) String

func (i DeprecationWarningLevel) String() string

type Fmt

type Fmt struct {
	// Paths contains the file paths that the formatter will handle.
	// When no arguments given to the command, it will use the current directory.
	// If the first argument is -, it will read the content to format from [os.Stdin].
	Paths []string

	// List controls the output of the formatted list. If disabled, it will not print the
	// names of the formatted files.
	List bool
	// Write controls if the formatter should write the content back to the check file or not.
	Write bool
	// Diff tells to the formatter to print the diff between the before and after formatting
	// process.
	Diff bool
	// Check can be used to instruct the command to return a non-zero error code if it finds
	// any file that is not properly formatted.
	Check bool
	// Recursive indicates that the formatting should be done recursive through all the
	// subdirectories.
	Recursive bool

	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions
}

Fmt represents the command-line arguments for the fmt command.

func ParseFmt

func ParseFmt(args []string) (*Fmt, func(), tfdiags.Diagnostics)

ParseFmt processes CLI arguments, returning a Fmt value, a closer function, and errors. If errors are encountered, a Fmt value is still returned representing the best effort interpretation of the arguments.

type Get

type Get struct {
	// Update is the flag that can be used to upgrade the version of the modules.
	Update bool
	// TestsDirectory indicates the path where the tests are stored
	TestsDirectory string

	// Vars holds and provides information for the flags related to variables that a user can give into the process
	Vars *Vars
	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions
}

Get represents the command-line arguments for the get command.

func ParseGet

func ParseGet(args []string) (*Get, func(), tfdiags.Diagnostics)

ParseGet processes CLI arguments, returning a Get value, a closer function, and errors. If errors are encountered, a Get value is still returned representing the best effort interpretation of the arguments.

type Graph

type Graph struct {
	// DrawCycles highlights any cycles in the graph with colored edges.
	DrawCycles bool
	// GraphType specifies the type of graph to output (plan, plan-refresh-only, plan-destroy, or apply).
	GraphType string
	// ModuleDepth specifies the depth of modules to show in the output.
	ModuleDepth int
	// Verbose enables verbose output.
	Verbose bool
	// PlanPath specifies the path to a plan file to render the graph from.
	PlanPath string

	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions

	// Vars holds and provides information for the flags related to variables that a user can give into the process
	Vars *Vars
}

Graph represents the command-line arguments for the graph command.

func ParseGraph

func ParseGraph(args []string) (*Graph, func(), tfdiags.Diagnostics)

ParseGraph processes CLI arguments, returning a Graph value, a closer function, and errors. If errors are encountered, a Graph value is still returned representing the best effort interpretation of the arguments.

type Import

type Import struct {
	// ResourceAddress is the absolute resource address that the user is required to provide to indicate
	// on which configuration resource the state of the resource needs to be imported.
	ResourceAddress string
	// ResourceID is the platform provided ID of the resource to be imported.
	ResourceID string
	// ConfigPath is the path to the directory where the configuration containing the ResourceAddress is
	// accessible.
	ConfigPath string
	// Parallelism is the limit of concurrent operation as OpenTofu walks the graph
	Parallelism int

	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions
	// State, Backend and Vars are the common extended flags
	State   *State
	Backend *Backend
	Vars    *Vars
}

Import represents the command-line arguments for the import command.

func ParseImport

func ParseImport(args []string, wd *workdir.Dir) (*Import, func(), tfdiags.Diagnostics)

ParseImport processes CLI arguments, returning an Import value, a closer function, and errors. If errors are encountered, an Import value is still returned representing the best effort interpretation of the arguments.

type Init

type Init struct {
	// Copy the contents of the given module into the target directory before initialisation
	FlagFromModule string
	// Lockfile operation mode. Currently only "readonly" is valid.
	FlagLockfile string
	// Set the OpenTofu test directory. When set, the
	// test command will search for test files in the current directory and
	// in the one specified by the flag.
	TestsDirectory string
	// When set to false, disables modules downloading for the current configuration
	FlagGet bool
	// Install the latest module and provider versions allowed within configured constraints, overriding the
	// default behavior of selecting exactly the version recorded in the dependency lockfile.
	FlagUpgrade bool
	// Directory containing plugin binaries. This overrides all default search paths for plugins, and prevents the
	// automatic installation of plugins. This flag can be used multiple times.
	FlagPluginPath flags.FlagStringSlice
	// Configuration to be merged with what is in the configuration file's 'backend' block. This can be
	// either a path to an HCL file with key/value assignments (same format as terraform.tfvars) or a
	// 'key=value' format, and can be specified multiple times. The backend type must be in the configuration itself.
	FlagConfigExtra flags.RawFlags
	// Disable backend or cloud backend initialization for this configuration and use what was previously
	// initialized instead. This and the FlagCloud cannot be toggled in the same time.
	FlagBackend bool
	FlagCloud   bool

	// Bools indicating that the FlagBackend and FlagCloud have been found into the arguments list of the
	// process.
	BackendFlagSet bool
	CloudFlagSet   bool

	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions

	// Vars holds and provides information for the flags related to variables that a user can give into the process
	Vars *Vars
	// Backend holds and providers information for the flags related to the backend operations, like locking
	// locking timeout, force migration, etc.
	Backend *Backend
	// State is used for the state related flags
	State *State
}

Init represents the command-line arguments for the init command.

func ParseInit

func ParseInit(args []string) (*Init, func(), tfdiags.Diagnostics)

ParseInit processes CLI arguments, returning an Init value, a closer function, and errors. If errors are encountered, an Init value is still returned representing the best effort interpretation of the arguments.

type LiveImport added in v0.3.0

type LiveImport struct {
	// StatePath is the tfstate file to read, once, read-only. Required:
	// there is no default the way -state defaults to terraform.tfstate for
	// state-backed commands, because reading one by accident is exactly what
	// this command's whole design refuses to do.
	StatePath string

	// Estate names the estate this run would stamp. Required: unlike
	// live-plan and live-mv, there is no configuration for this command to
	// derive it from - the state file being imported may belong to a
	// configuration that has never heard of markers at all.
	Estate string

	// Approve turns the run from a read-only ratification into one that also
	// stamps: without it, the report prints and nothing is written; with it,
	// every VERIFIED or DRIFTED resource from that same report is stamped.
	Approve bool
}

LiveImport represents the command-line arguments for the live-import command.

func ParseLiveImport added in v0.3.0

func ParseLiveImport(args []string) (*LiveImport, tfdiags.Diagnostics)

ParseLiveImport processes CLI arguments, returning a LiveImport value and errors. If errors are encountered, a LiveImport value is still returned representing the best effort interpretation of the arguments.

type LiveMv

type LiveMv struct {
	// RawOldAddr is the address the live resource carries now, and
	// RawNewAddr is the one this run writes onto it. Both are unparsed here;
	// the command parses them as resource instance addresses, which is where
	// the diagnostic about a malformed one belongs.
	RawOldAddr string
	RawNewAddr string

	// Estate names the estate that owns the resource. Empty means the flag
	// was absent, and the name is derived from the configuration instead -
	// from a live block, or from the tofu-estate tags the configuration
	// itself stamps. Unlike live-plan, this command cannot run without one.
	Estate string

	// DryRun makes every check and reports what would be rewritten, without
	// writing.
	DryRun bool

	// AllowMissingConfig permits a destination address the configuration does
	// not declare, for a rename whose configuration edit has not happened yet.
	AllowMissingConfig bool
}

LiveMv represents the command-line arguments for the live-mv command.

func ParseLiveMv

func ParseLiveMv(args []string) (*LiveMv, tfdiags.Diagnostics)

ParseLiveMv processes CLI arguments, returning a LiveMv value and errors. If errors are encountered, a LiveMv value is still returned representing the best effort interpretation of the arguments.

There is no closer and no ViewOptions here, unlike most of this package. This command's view is configured from ParseView in the ordinary way, so the -no-color and -compact-warnings it accepts are gone from the arguments before this parser sees them, and there is nothing to close.

Options come before the two addresses, because the flag set stops at the first operand the way every other command's does.

type LivePlan

type LivePlan struct {
	// Plan is the stock plan argument set, embedded so that -target, -var,
	// -var-file, -refresh and the rest parse and behave identically. Anything
	// live-plan cannot honor is rejected by the command after parsing, rather
	// than removed from the flag set here, so that an operator who passes one
	// is told so instead of being ignored.
	*Plan

	// Estate names the estate whose ownership markers this run looks for. An
	// empty value means the flag was absent, which is not an error: the name
	// is then derived from the configuration, and a run that cannot derive it
	// degrades rather than fails. It is an error only when the configuration
	// has a live block, since the block names the estate itself; the command
	// makes that check, because it needs a loaded configuration to make it.
	Estate string
}

LivePlan represents the command-line arguments for the live-plan command, which is the plan command's whole option set plus -estate.

func ParseLivePlan

func ParseLivePlan(args []string) (*LivePlan, func(), tfdiags.Diagnostics)

ParseLivePlan processes CLI arguments, returning a LivePlan value, a closer function, and errors. If errors are encountered, a LivePlan value is still returned representing the best effort interpretation of the arguments.

-estate is registered on the plan command's own flag set rather than added to Plan, which would make it an option of "choudoufu plan" as well: a flag naming a stateless concept on the command that has state files. Registering it here keeps the stock plan surface exactly as it was, and still gets -estate the parsing every other option has - end-of-flags handling, the -estate=NAME and -estate NAME forms, and a real error for a flag that is not one.

type Login

type Login struct {
	// Host represents the host that OpenTofu will try to login to
	Host string

	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions
	// Vars and State are the common extended flags
	Vars  *Vars
	State *State
}

Login represents the command-line arguments for the login command.

func ParseLogin

func ParseLogin(args []string) (*Login, func(), tfdiags.Diagnostics)

ParseLogin processes CLI arguments, returning a Login value, a closer function, and errors. If errors are encountered, a Login value is still returned representing the best effort interpretation of the arguments.

type Logout

type Logout struct {
	// Host represents the host that OpenTofu will try to log out of
	Host string

	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions
	// Vars holds and provides information for the flags related to variables that a user can give into the process
	Vars *Vars
}

Logout represents the command-line arguments for the logout command.

func ParseLogout

func ParseLogout(args []string) (*Logout, func(), tfdiags.Diagnostics)

ParseLogout processes CLI arguments, returning a Logout value, a closer function, and errors. If errors are encountered, a Logout value is still returned representing the best effort interpretation of the arguments.

type MetadataFunctions

type MetadataFunctions struct {
	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions
}

MetadataFunctions represents the command-line arguments for the "metadata functions" command.

func ParseMetadataFunctions

func ParseMetadataFunctions(args []string) (*MetadataFunctions, func(), tfdiags.Diagnostics)

ParseMetadataFunctions processes CLI arguments, returning a MetadataFunctions value, a closer function, and errors. If errors are encountered, a MetadataFunctions value is still returned representing the best effort interpretation of the arguments.

type Operation

type Operation struct {
	// PlanMode selects one of the mutually-exclusive planning modes that
	// decides the overall goal of a plan operation. This field is relevant
	// only for an operation that produces a plan.
	PlanMode plans.Mode

	// Parallelism is the limit OpenTofu places on total parallel operations
	// as it walks the dependency graph.
	Parallelism int

	// Refresh controls whether or not the operation should refresh existing
	// state before proceeding. Default is true.
	Refresh bool

	// Targets allow limiting an operation to a set of resource addresses and
	// their dependencies.
	Targets []addrs.Targetable

	// Excludes allow limiting an operation to execute on all resources other
	// than a set of excluded resource addresses and resources dependent on them.
	Excludes []addrs.Targetable

	// ForceReplace addresses cause OpenTofu to force a particular set of
	// resource instances to generate "replace" actions in any plan where they
	// would normally have generated "no-op" or "update" actions.
	//
	// This is currently limited to specific instances because typical uses
	// of replace are associated with only specific remote objects that the
	// user has somehow learned to be malfunctioning, in which case it
	// would be unusual and potentially dangerous to replace everything under
	// a module all at once. We could potentially loosen this later if we
	// learn a use-case for broader matching.
	ForceReplace []addrs.AbsResourceInstance
	// contains filtered or unexported fields
}

Operation describes arguments which are used to configure how a OpenTofu operation such as a plan or apply executes.

func (*Operation) Parse

func (o *Operation) Parse() tfdiags.Diagnostics

Parse must be called on Operation after initial flag parse. This processes the raw target flags into addrs.Targetable values, returning diagnostics if invalid.

type Output

type Output struct {
	// Name identifies which root module output to show.  If empty, show all
	// outputs.
	Name string
	// ShowSensitive is used to display the value of variables marked as sensitive.
	ShowSensitive bool

	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions
	// Vars and State are the common extended flags
	Vars  *Vars
	State *State
}

Output represents the command-line arguments for the output command.

func ParseOutput

func ParseOutput(args []string) (*Output, func(), tfdiags.Diagnostics)

ParseOutput processes CLI arguments, returning an Output value, a closer function, and errors. If errors are encountered, an Output value is still returned representing the best effort interpretation of the arguments.

type Plan

type Plan struct {
	// State, Operation, and Vars are the common extended flags
	State     *State
	Operation *Operation
	Vars      *Vars

	// DetailedExitCode enables different exit codes for error, success with
	// changes, and success with no changes.
	DetailedExitCode bool

	// OutPath contains an optional path to store the plan file
	OutPath string

	// GenerateConfigPath tells OpenTofu that config should be generated for
	// unmatched import target paths and which path the generated file should
	// be written to.
	GenerateConfigPath string

	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions

	// ShowSensitive is used to display the value of variables marked as sensitive.
	ShowSensitive bool

	// Verbose asks a command to print detail it would otherwise summarize.
	// Live resource markers is the first consumer: the "Not swept for
	// removal" section's full type-by-type breakdown, collapsed to a
	// one-line count by default (GitHub issue #78, "First plan drowns a
	// small estate in the not-swept type list"). It lives on Plan itself,
	// not behind the [parsePlan] extraFlags hook the way -estate is (see
	// that hook's own comment), because -verbose does nothing to a stock
	// plan rather than naming a stateless-only concept, and because it also
	// needs to reach "choudoufu apply" against a live block
	// (arguments.Apply.Verbose), where -estate has no equivalent need
	// (arguments.Apply has none either).
	Verbose bool
}

Plan represents the command-line arguments for the plan command.

func ParsePlan

func ParsePlan(args []string) (*Plan, func(), tfdiags.Diagnostics)

ParsePlan processes CLI arguments, returning a Plan value, a closer function, and errors. If errors are encountered, a Plan value is still returned representing the best effort interpretation of the arguments.

type Providers

type Providers struct {
	// TestsDirectory indicates the path where the tests are stored
	TestsDirectory string

	// Vars holds and provides information for the flags related to variables that a user can give into the process
	Vars *Vars
	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions
}

Providers represents the command-line arguments for the providers command.

func ParseProviders

func ParseProviders(args []string) (*Providers, func(), tfdiags.Diagnostics)

ParseProviders processes CLI arguments, returning a Providers value, a closer function, and errors. If errors are encountered, a Providers value is still returned representing the best effort interpretation of the arguments.

type ProvidersLock

type ProvidersLock struct {
	// Providers are the source addresses of the providers that are requested to be updated
	Providers []string
	// OptPlatforms contains the platforms that the user requested for the locks to be updated for.
	// Having this empty, only the checksum for the host platform will be updated, but the user
	// can use this to update the hashes for other platforms too.
	OptPlatforms flags.FlagStringSlice
	// FsMirrorDir represents a path from where OpenTofu should check for providers instead to reach
	// out for the registry.
	FsMirrorDir string
	// NetMirrorURL represents a URL to a mirrored registry from where OpenTofu should check for
	// providers instead to reach out for the registry.
	NetMirrorURL string
	// OciMirrorTemplate represents a URI-style template string that evaluates to an OCI repository address
	// to use for the providers.
	OciMirrorTemplate string

	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions
	// Vars holds and provides information for the flags related to variables that a user can give into the process
	Vars *Vars
}

ProvidersLock represents the command-line arguments for the 'providers lock' command.

func ParseProvidersLock

func ParseProvidersLock(args []string) (*ProvidersLock, func(), tfdiags.Diagnostics)

ParseProvidersLock processes CLI arguments, returning a ProvidersLock value, a closer function, and errors. If errors are encountered, a ProvidersLock value is still returned representing the best effort interpretation of the arguments.

type ProvidersMirror

type ProvidersMirror struct {
	// Directory is the directory where the copies of the providers will be stored
	Directory string
	// OptPlatforms contains the platforms that the user requested to have the providers
	// copy for
	OptPlatforms flags.FlagStringSlice

	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions
	// Vars holds and provides information for the flags related to variables that a user can give into the process
	Vars *Vars
}

ProvidersMirror represents the command-line arguments for the 'providers lock' command.

func ParseProvidersMirror

func ParseProvidersMirror(args []string) (*ProvidersMirror, func(), tfdiags.Diagnostics)

ParseProvidersMirror processes CLI arguments, returning a ProvidersMirror value, a closer function, and errors. If errors are encountered, a ProvidersMirror value is still returned representing the best effort interpretation of the arguments.

type ProvidersSchema

type ProvidersSchema struct {
	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions

	// Vars holds and provides information for the flags related to variables that a user can give into the process
	Vars *Vars
}

ProvidersSchema represents the command-line arguments for the 'providers schema' command.

func ParseProvidersSchema

func ParseProvidersSchema(args []string) (*ProvidersSchema, func(), tfdiags.Diagnostics)

ParseProvidersSchema processes CLI arguments, returning a ProvidersSchema value, a closer function, and errors. If errors are encountered, a ProvidersSchema value is still returned representing the best effort interpretation of the arguments.

type Refresh

type Refresh struct {
	// State, Operation, and Vars are the common extended flags
	State     *State
	Operation *Operation
	Vars      *Vars

	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions
}

Refresh represents the command-line arguments for the apply command.

func ParseRefresh

func ParseRefresh(args []string) (*Refresh, func(), tfdiags.Diagnostics)

ParseRefresh processes CLI arguments, returning a Refresh value, a closer function, and errors. If errors are encountered, a Refresh value is still returned representing the best effort interpretation of the arguments.

type Show

type Show struct {
	// TargetType and TargetArg together describe the object that was
	// requested to be shown.
	//
	// The meaning of TargetArg varies depending on TargetType. Refer to
	// the documentation for each [ShowTargetType] constant for details.
	TargetType ShowTargetType
	TargetArg  string

	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions

	Vars *Vars

	// ShowSensitive is used to display the value of variables marked as sensitive.
	ShowSensitive bool
}

Show represents the command-line arguments for the show command.

func ParseShow

func ParseShow(args []string) (*Show, func(), tfdiags.Diagnostics)

ParseShow processes CLI arguments, returning a Show value, a closer function, and errors. If errors are encountered, a Show value is still returned representing the best effort interpretation of the arguments.

type ShowTargetType

type ShowTargetType int

ShowTargetType represents the type of object that is requested to be shown by the "tofu show" command.

const (
	// ShowUnknownType is the zero value of [ShowTargetType], and represents
	// that the target type is ambiguous and so must be inferred by the
	// caller based on the [Show.TargetArg] value.
	ShowUnknownType ShowTargetType = iota

	// ShowState represents a request to show the latest state snapshot.
	//
	// This target type does not use [Show.TargetArg].
	ShowState

	// ShowPlan represents a request to show a plan loaded from a saved
	// plan file.
	//
	// For this target type, [Show.TargetArg] is the plan file to load.
	ShowPlan

	// ShowConfig represents a request to show the current configuration.
	//
	// This target type does not use [Show.TargetArg].
	ShowConfig

	// ShowModule represents a request to show just one module in isolation,
	// without requiring any of its dependencies to be installed.
	//
	// For this target type, [Show.TargetArg] is a path to the directory
	// containing the module.
	ShowModule
)

func (ShowTargetType) String

func (i ShowTargetType) String() string

type State

type State struct {
	// Lock controls whether or not the state manager is used to lock state
	// during operations.
	Lock bool

	// LockTimeout allows setting a time limit on acquiring the state lock.
	// The default is 0, meaning no limit.
	LockTimeout time.Duration

	// StatePath specifies a non-default location for the state file. The
	// default value is blank, which is interpreted as "terraform.tfstate".
	// Represents the local path where state is read from.
	StatePath string

	// StateOutPath specifies a different path to write the final state file.
	// The default value is blank, which results in state being written back to
	// StatePath.
	StateOutPath string

	// BackupPath specifies the path where a backup copy of the state file will
	// be stored before the new state is written. The default value is blank,
	// which is interpreted as StateOutPath + ".backup" or, in some cases, the backup
	// is skipped altogether.
	BackupPath string
}

State describes arguments which are used to define how OpenTofu interacts with state.

func (*State) AddBackupFlag

func (s *State) AddBackupFlag(f *flag.FlagSet, defVal string)

AddBackupFlag exists strictly because the default value can get a different value in some commands.

func (*State) AddStateInFlag

func (s *State) AddStateInFlag(f *flag.FlagSet, defVal string)

AddStateInFlag exists strictly because the default value can get a different value in some commands.

type StateList

type StateList struct {
	// LookupId restricts output to paths with a resource having the specified ID.
	LookupId string
	// InstancesRawAddr is a list of raw addresses of the resources that are requested
	// to be listed.
	InstancesRawAddr []string

	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions

	// Vars and State are the common extended flags
	Vars  *Vars
	State *State
}

StateList represents the command-line arguments for the 'state list' command.

func ParseStateList

func ParseStateList(args []string) (*StateList, func(), tfdiags.Diagnostics)

ParseStateList processes CLI arguments, returning a StateList value, a closer function, and errors. If errors are encountered, a StateList value is still returned representing the best effort interpretation of the arguments.

type StateMv

type StateMv struct {
	// RawSrcAddr represents a resources address that is requested by the user to be moved
	RawSrcAddr string
	// RawDestAddr represents a resources address that is requested by the user to be used to move the
	// resource into
	RawDestAddr string
	// DryRun just validates that the arguments provided are valid and will output the possible outcome.
	// When running in this mode, the state will suffer no change.
	DryRun bool
	// BackupPathOut can be used by the user to configure where to save the backup file of the state file.
	BackupPathOut string

	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions

	// Vars, Backend and State are the common extended flags
	Vars    *Vars
	Backend *Backend
	State   *State
}

StateMv represents the command-line arguments for the 'state mv' command.

func ParseStateMv

func ParseStateMv(args []string) (*StateMv, func(), tfdiags.Diagnostics)

ParseStateMv processes CLI arguments, returning a StateMv value, a closer function, and errors. If errors are encountered, a StateMv value is still returned representing the best effort interpretation of the arguments.

type StatePull

type StatePull struct {
	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions

	// Vars are the common extended flags
	Vars *Vars
}

StatePull represents the command-line arguments for the 'state pull' command.

func ParseStatePull

func ParseStatePull(args []string) (*StatePull, func(), tfdiags.Diagnostics)

ParseStatePull processes CLI arguments, returning a StatePull value, a closer function, and errors. If errors are encountered, a StatePull value is still returned representing the best effort interpretation of the arguments.

type StatePush

type StatePush struct {
	// StateSrc represents the source of the state that wants to be pushed.
	// This can be a file name/file path, or it can be "-" when the state should be read from [os.Stdin].
	StateSrc string
	// Force will try to forcefully push the state remotely. This will happen only if the backend supports it.
	Force bool
	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions

	// Vars, Backend and State are the common extended flags
	Vars    *Vars
	Backend *Backend
	State   *State
}

StatePush represents the command-line arguments for the 'state push' command.

func ParseStatePush

func ParseStatePush(args []string) (*StatePush, func(), tfdiags.Diagnostics)

ParseStatePush processes CLI arguments, returning a StatePush value, a closer function, and errors. If errors are encountered, a StatePush value is still returned representing the best effort interpretation of the arguments.

type StateReplaceProvider

type StateReplaceProvider struct {
	// RawSrcAddr represents a provider address that is requested by the user to be moved
	RawSrcAddr string
	// RawDestAddr represents a provider address that is requested by the user to be used to move the
	// provider into
	RawDestAddr string
	// AutoApprove is an option that the user can configure to skip the confirmation step of the replacement
	// process.
	AutoApprove bool

	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions

	// Vars, Backend and State are the common extended flags
	Vars    *Vars
	Backend *Backend
	State   *State
}

StateReplaceProvider represents the command-line arguments for the 'state replace-provider' command.

func ParseReplaceProvider

func ParseReplaceProvider(args []string) (*StateReplaceProvider, func(), tfdiags.Diagnostics)

ParseReplaceProvider processes CLI arguments, returning a StateReplaceProvider value, a closer function, and errors. If errors are encountered, a StateReplaceProvider value is still returned representing the best effort interpretation of the arguments.

type StateRm

type StateRm struct {
	// TargetAddrs represents the raw resource addresses to be removed from the state
	TargetAddrs []string
	// DryRun just validates that the arguments provided are valid and will output the possible outcome.
	// When running in this mode, the state will suffer no change.
	DryRun bool

	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions

	// Vars, Backend and State are the common extended flags
	Vars    *Vars
	Backend *Backend
	State   *State
}

StateRm represents the command-line arguments for the 'state rm' command.

func ParseStateRm

func ParseStateRm(args []string) (*StateRm, func(), tfdiags.Diagnostics)

ParseStateRm processes CLI arguments, returning a StateRm value, a closer function, and errors. If errors are encountered, a StateRm value is still returned representing the best effort interpretation of the arguments.

type StateShow

type StateShow struct {
	// TargetRawAddr represents the raw resource address of the resource requested to have the state shown for.
	TargetRawAddr string
	// ShowSensitive forces the show command to print also the sensitive values of the targeted resource.
	// This applies only to the [views.StateHuman] since the [views.StateJSON] shows the sensitive values
	// all the time.
	ShowSensitive bool

	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions

	// Vars and State are the common extended flags
	Vars  *Vars
	State *State
}

StateShow represents the command-line arguments for the 'state show' command.

func ParseStateShow

func ParseStateShow(args []string) (*StateShow, func(), tfdiags.Diagnostics)

ParseStateShow processes CLI arguments, returning a StateShow value, a closer function, and errors. If errors are encountered, a StateShow value is still returned representing the best effort interpretation of the arguments.

type Taint

type Taint struct {
	// TargetAddress is the resource address that is requested to be marked as tainted.
	TargetAddress addrs.AbsResourceInstance
	// AllowMissing can be set to "true" to write a warning instead of an error and to return exit code 0
	// when the TargetAddress points to a missing resource.
	AllowMissing bool

	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions

	// Vars holds and provides information for the flags related to variables that a user can give into the process
	Vars *Vars

	// State is used for the state related flags
	State *State
	// Backend is used strictly for the ignore remote version flag
	Backend *Backend
}

Taint represents the command-line arguments for the taint and untaint commands.

func ParseTaint

func ParseTaint(isTaint bool, args []string) (*Taint, func(), tfdiags.Diagnostics)

ParseTaint processes CLI arguments, returning a Taint value, a closer function, and errors. If errors are encountered, a Taint value is still returned representing the best effort interpretation of the arguments.

type Test

type Test struct {
	// Filter contains a list of test files to execute. If empty, all test files
	// will be executed.
	Filter []string

	// TestDirectory allows the user to override the directory that the test
	// command will use to discover test files, defaults to "tests". Regardless
	// of the value here, test files within the configuration directory will
	// always be discovered.
	TestDirectory string

	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions

	// You can specify common variables for all tests from the command line.
	Vars *Vars

	// Verbose tells the test command to print out the plan either in
	// human-readable format or JSON for each run step depending on the
	// ViewType.
	Verbose bool
}

Test represents the command-line arguments for the test command.

func ParseTest

func ParseTest(args []string) (*Test, func(), tfdiags.Diagnostics)

type Unlock

type Unlock struct {
	// LockID is the ID of the lock that the user has to provide.
	LockID string
	// Force disables the confirmation prompt
	Force bool

	// Vars holds and provides information for the flags related to variables that a user can give into the process
	Vars *Vars
	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions
}

Unlock represents the command-line arguments for the unlock command.

func ParseUnlock

func ParseUnlock(args []string) (*Unlock, func(), tfdiags.Diagnostics)

ParseUnlock processes CLI arguments, returning a Unlock value, a closer function, and errors. If errors are encountered, a Unlock value is still returned representing the best effort interpretation of the arguments.

type Validate

type Validate struct {
	// Path is the directory containing the configuration to be validated. If
	// unspecified, validate will use the current directory.
	Path string

	// TestDirectory is the directory containing any test files that should be
	// validated alongside the main configuration. Should be relative to the
	// Path.
	TestDirectory string

	// NoTests indicates that OpenTofu should not validate any test files
	// included with the module.
	NoTests bool

	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions

	Vars *Vars
}

Validate represents the command-line arguments for the validate command.

func ParseValidate

func ParseValidate(args []string) (*Validate, func(), tfdiags.Diagnostics)

ParseValidate processes CLI arguments, returning a Validate value, a closer function, and errors. If errors are encountered, a Validate value is still returned representing the best effort interpretation of the arguments.

type Vars

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

Vars describes arguments which specify non-default variable values. This interface is unfortunately obscure, because the order of the CLI arguments determines the final value of the gathered variables. In future it might be desirable for the arguments package to handle the gathering of variables directly, returning a map of variable values.

func (*Vars) All

func (v *Vars) All() []flags.RawFlag

func (*Vars) Empty

func (v *Vars) Empty() bool

type Version

type Version struct {
	// ViewOptions specifies which view options to use
	ViewOptions ViewOptions
}

Version represents the command-line arguments for the version command.

func ParseVersion

func ParseVersion(args []string) (*Version, func(), tfdiags.Diagnostics)

ParseVersion processes CLI arguments, returning a Version value, a closer function, and errors. If errors are encountered, a Version value is still returned representing the best effort interpretation of the arguments.

type View

type View struct {
	// NoColor is used to disable the use of terminal color codes in all
	// output.
	NoColor bool

	// CompactWarnings is used to coalesce duplicate warnings, to reduce the
	// level of noise when multiple instances of the same warning are raised
	// for a configuration.
	CompactWarnings     bool
	ConsolidateWarnings bool
	ConsolidateErrors   bool

	// Concise is used to reduce the level of noise in the output and display
	// only the important details.
	Concise bool

	// ModuleDeprecationWarnLvl is used to filter out deprecation warnings for outputs and variables as requested by the user.
	ModuleDeprecationWarnLvl DeprecationWarningLevel

	// ShowSensitive is used to display the value of variables marked as sensitive.
	ShowSensitive bool
}

View represents the global command-line arguments which configure the view.

func ParseView

func ParseView(args []string) (*View, []string)

ParseView processes CLI arguments, returning a View value and a possibly-modified slice of arguments. If any of the supported flags are found, they will be removed from the slice.

type ViewOptions

type ViewOptions struct {

	// ViewType specifies which output format to use
	ViewType ViewType

	// InputEnabled is used to disable interactive input for unspecified
	// variable and backend config values. Default is true.
	InputEnabled bool

	// Optional stream to write json data to
	JSONInto *os.File
	// contains filtered or unexported fields
}

ViewOptions contains all of the information nessesary for constructing a view from raw CLI arguments. This replaced most of the direct usage of ViewType when the -json-into flag was introduced. In practice, this allows a much more nuanced set of data to be presented to the view constructors.

func (*ViewOptions) AddFlags

func (v *ViewOptions) AddFlags(cmdFlags *flag.FlagSet, input bool)

func (*ViewOptions) AddGranularFlags

func (v *ViewOptions) AddGranularFlags(cmdFlags *flag.FlagSet, input bool, jsonInto bool)

AddGranularFlags registers view-related flags on cmdFlags. Use input=true to register the -input flag and jsonInto=true to register the -json-into flag. Commands that only support -json (not -json-into) should pass jsonInto=false.

func (*ViewOptions) Parse

func (v *ViewOptions) Parse() (func(), tfdiags.Diagnostics)

type ViewType

type ViewType rune

ViewType represents which view layer to use for a given command. Not all commands will support all view types, and validation that the type is supported should happen in the view constructor.

const (
	ViewNone  ViewType = 0
	ViewHuman ViewType = 'H'
	ViewJSON  ViewType = 'J'
	ViewRaw   ViewType = 'R'
)

func (ViewType) String

func (vt ViewType) String() string

type Workspace

type Workspace struct {
	// ViewOptions contains the options that allows the user to configure different types of outputs
	// from the current command.
	ViewOptions ViewOptions
}

func ParseWorkspace

func ParseWorkspace(args []string) (*Workspace, func(), tfdiags.Diagnostics)

type WorkspaceDelete

type WorkspaceDelete struct {
	// WorkspaceName represents the name of the workspace that the user wants to be selected.
	WorkspaceName string

	// Force allows the user to forcefully delete a workspace removing the still existing resources
	// from the OpenTofu's management.
	Force bool

	// ViewOptions contains the options that allows the user to configure different types of outputs
	// from the current command.
	ViewOptions ViewOptions

	// Vars and State are the common extended flags
	Vars  *Vars
	State *State
}

func ParseWorkspaceDelete

func ParseWorkspaceDelete(args []string) (*WorkspaceDelete, func(), tfdiags.Diagnostics)

type WorkspaceList

type WorkspaceList struct {
	// ViewOptions contains the options that allows the user to configure different types of outputs
	// from the current command.
	ViewOptions ViewOptions

	// Vars holds the information that might be needed to be given through `-var`/`-var-file`.
	Vars *Vars
}

func ParseWorkspaceList

func ParseWorkspaceList(args []string) (*WorkspaceList, func(), tfdiags.Diagnostics)

type WorkspaceNew

type WorkspaceNew struct {
	// Workspace represents the name of the workspace that the user wants to be selected.
	WorkspaceName string

	// ViewOptions contains the options that allows the user to configure different types of outputs
	// from the current command.
	ViewOptions ViewOptions

	// Vars and State are the common extended flags
	Vars  *Vars
	State *State
}

func ParseWorkspaceNew

func ParseWorkspaceNew(args []string) (*WorkspaceNew, func(), tfdiags.Diagnostics)

type WorkspaceSelect

type WorkspaceSelect struct {
	// Workspace represents the name of the workspace that the user wants to be selected.
	WorkspaceName string
	// CreateIfMissing is a flag that the user can set to "true" to force the creation of the workspace
	// in case it's missing from the current list of workspaces.
	CreateIfMissing bool

	// ViewOptions contains the options that allows the user to configure different types of outputs
	// from the current command.
	ViewOptions ViewOptions

	// Vars holds the information that might be needed to be given through `-var`/`-var-file`.
	Vars *Vars
}

func ParseWorkspaceSelect

func ParseWorkspaceSelect(args []string) (*WorkspaceSelect, func(), tfdiags.Diagnostics)

type WorkspaceShow

type WorkspaceShow struct {
	// ViewOptions contains the options that allows the user to configure different types of outputs
	// from the current command.
	ViewOptions ViewOptions

	// Vars holds the information that might be needed to be given through `-var`/`-var-file`.
	Vars *Vars
}

func ParseWorkspaceShow

func ParseWorkspaceShow(args []string) (*WorkspaceShow, func(), tfdiags.Diagnostics)

Jump to

Keyboard shortcuts

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