tfexec
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package tfexec exposes functionality for constructing and running TerraformCLI commands. Structured return values use the data types defined in thegithub.com/hashicorp/terraform-json package.
Index¶
- func CleanEnv(dirty map[string]string) map[string]string
- func FormatString(ctx context.Context, execPath string, content string) (string, error)
- func ProhibitedEnv(env map[string]string) []string
- type AllowDeferralOption
- type AllowMissingConfigOption
- type AllowMissingOption
- type ApplyOption
- type BackendConfigOption
- type BackendOption
- type BackupOption
- type BackupOutOption
- type ConfigOption
- type CopyStateOption
- type DestroyFlagOption
- type DestroyOption
- type DirOption
- type DirOrPlanOption
- type DrawCyclesOption
- type DryRunOption
- type ErrManualEnvVar
- type ErrNoSuitableBinary
- type ErrVersionMismatch
- type FSMirrorOption
- type ForceCopyOption
- type ForceOption
- type ForceUnlockOption
- type FormatOption
- type FromModuleOption
- type GenerateConfigOutOption
- type GetCmdOption
- type GetOption
- type GetPluginsOption
- type GraphOption
- type GraphPlanOption
- type GraphTypeOption
- type ImportOption
- type InitOption
- type LockOption
- type LockTimeoutOption
- type NetMirrorOption
- type NextMessage
- type OutOption
- type OutputMeta
- type OutputOption
- type ParallelismOption
- type PlanOption
- type PlatformOption
- type PluginDirOption
- type ProviderOption
- type ProvidersLockOption
- type QueryOption
- type ReattachConfig
- type ReattachConfigAddr
- type ReattachInfo
- type ReattachOption
- type ReconfigureOption
- type RecursiveOption
- type RefreshCmdOption
- type RefreshOnlyOption
- type RefreshOption
- type ReplaceOption
- type ShowOption
- type StateMvCmdOption
- type StateOption
- func State(path string) *StateOptiondeprecated
- type StateOutOption
- type StatePullOption
- type StatePushCmdOption
- type StateRmCmdOption
- type TaintOption
- type TargetOption
- type Terraform
- func (tf *Terraform) Apply(ctx context.Context, opts ...ApplyOption) error
- func (tf *Terraform) ApplyJSON(ctx context.Context, w io.Writer, opts ...ApplyOption) error
- func (tf *Terraform) Destroy(ctx context.Context, opts ...DestroyOption) error
- func (tf *Terraform) DestroyJSON(ctx context.Context, w io.Writer, opts ...DestroyOption) error
- func (tf *Terraform) ExecPath() string
- func (tf *Terraform) ForceUnlock(ctx context.Context, lockID string, opts ...ForceUnlockOption) error
- func (tf *Terraform) Format(ctx context.Context, unformatted io.Reader, formatted io.Writer) error
- func (tf *Terraform) FormatCheck(ctx context.Context, opts ...FormatOption) (bool, []string, error)
- func (tf *Terraform) FormatString(ctx context.Context, content string) (string, error)
- func (tf *Terraform) FormatWrite(ctx context.Context, opts ...FormatOption) error
- func (tf *Terraform) Get(ctx context.Context, opts ...GetCmdOption) error
- func (tf *Terraform) Graph(ctx context.Context, opts ...GraphOption) (string, error)
- func (tf *Terraform) Import(ctx context.Context, address, id string, opts ...ImportOption) error
- func (tf *Terraform) Init(ctx context.Context, opts ...InitOption) error
- func (tf *Terraform) InitJSON(ctx context.Context, w io.Writer, opts ...InitOption) error
- func (tf *Terraform) MetadataFunctions(ctx context.Context) (*tfjson.MetadataFunctions, error)
- func (tf *Terraform) Output(ctx context.Context, opts ...OutputOption) (map[string]OutputMeta, error)
- func (tf *Terraform) Plan(ctx context.Context, opts ...PlanOption) (bool, error)
- func (tf *Terraform) PlanJSON(ctx context.Context, w io.Writer, opts ...PlanOption) (bool, error)
- func (tf *Terraform) ProvidersLock(ctx context.Context, opts ...ProvidersLockOption) error
- func (tf *Terraform) ProvidersSchema(ctx context.Context) (*tfjson.ProviderSchemas, error)
- func (tf *Terraform) QueryJSON(ctx context.Context, opts ...QueryOption) (iter.Seq[NextMessage], error)
- func (tf *Terraform) Refresh(ctx context.Context, opts ...RefreshCmdOption) error
- func (tf *Terraform) RefreshJSON(ctx context.Context, w io.Writer, opts ...RefreshCmdOption) error
- func (tf *Terraform) SetAppendUserAgent(ua string) error
- func (tf *Terraform) SetDisablePluginTLS(disabled bool) error
- func (tf *Terraform) SetEnableLegacyPipeClosing(enabled bool) error
- func (tf *Terraform) SetEnv(env map[string]string) error
- func (tf *Terraform) SetLog(log string) error
- func (tf *Terraform) SetLogCore(logCore string) error
- func (tf *Terraform) SetLogPath(path string) error
- func (tf *Terraform) SetLogProvider(logProvider string) error
- func (tf *Terraform) SetLogger(logger printfer)
- func (tf *Terraform) SetSkipProviderVerify(skip bool) error
- func (tf *Terraform) SetStderr(w io.Writer)
- func (tf *Terraform) SetStdout(w io.Writer)
- func (tf *Terraform) SetWaitDelay(delay time.Duration) error
- func (tf *Terraform) Show(ctx context.Context, opts ...ShowOption) (*tfjson.State, error)
- func (tf *Terraform) ShowPlanFile(ctx context.Context, planPath string, opts ...ShowOption) (*tfjson.Plan, error)
- func (tf *Terraform) ShowPlanFileRaw(ctx context.Context, planPath string, opts ...ShowOption) (string, error)
- func (tf *Terraform) ShowStateFile(ctx context.Context, statePath string, opts ...ShowOption) (*tfjson.State, error)
- func (tf *Terraform) StateMv(ctx context.Context, source string, destination string, ...) error
- func (tf *Terraform) StatePull(ctx context.Context, opts ...StatePullOption) (string, error)
- func (tf *Terraform) StatePush(ctx context.Context, path string, opts ...StatePushCmdOption) error
- func (tf *Terraform) StateRm(ctx context.Context, address string, opts ...StateRmCmdOption) error
- func (tf *Terraform) Taint(ctx context.Context, address string, opts ...TaintOption) error
- func (tf *Terraform) Test(ctx context.Context, w io.Writer, opts ...TestOption) error
- func (tf *Terraform) Untaint(ctx context.Context, address string, opts ...UntaintOption) error
- func (tf *Terraform) Upgrade012(ctx context.Context, opts ...Upgrade012Option) error
- func (tf *Terraform) Upgrade013(ctx context.Context, opts ...Upgrade013Option) error
- func (tf *Terraform) Validate(ctx context.Context) (*tfjson.ValidateOutput, error)
- func (tf *Terraform) Version(ctx context.Context, skipCache bool) (tfVersion *version.Version, providerVersions map[string]*version.Version, ...)
- func (tf *Terraform) WorkingDir() string
- func (tf *Terraform) WorkspaceDelete(ctx context.Context, workspace string, opts ...WorkspaceDeleteCmdOption) error
- func (tf *Terraform) WorkspaceList(ctx context.Context) ([]string, string, error)
- func (tf *Terraform) WorkspaceNew(ctx context.Context, workspace string, opts ...WorkspaceNewCmdOption) error
- func (tf *Terraform) WorkspaceSelect(ctx context.Context, workspace string) error
- func (tf *Terraform) WorkspaceShow(ctx context.Context) (string, error)
- type TestOption
- type TestsDirectoryOption
- type UntaintOption
- type UpdateOption
- type Upgrade012Option
- type Upgrade013Option
- type UpgradeOption
- type UseJSONNumberOption
- type VarFileOption
- type VarOption
- type VerifyPluginsOption
- type WorkspaceDeleteCmdOption
- type WorkspaceNewCmdOption
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
funcCleanEnv¶added inv0.12.0
CleanEnv removes any prohibited environment variables from an environment map.
funcFormatString¶added inv0.11.0
FormatString formats a passed string, given a path to Terraform.
funcProhibitedEnv¶added inv0.12.0
ProhibitedEnv returns a slice of environment variable keys that are not allowedto be set manually from the passed environment.
Types¶
typeAllowDeferralOption¶added inv0.21.0
type AllowDeferralOption struct {// contains filtered or unexported fields}AllowDeferralOption represents the -allow-deferral flag. This flag is only enabled inexperimental builds of Terraform. (alpha or built via source with experiments enabled)
funcAllowDeferral¶added inv0.21.0
func AllowDeferral(allowDeferralbool) *AllowDeferralOption
AllowDeferral represents the -allow-deferral flag. This flag is only enabled inexperimental builds of Terraform. (alpha or built via source with experiments enabled)
typeAllowMissingConfigOption¶
type AllowMissingConfigOption struct {// contains filtered or unexported fields}AllowMissingConfigOption represents the -allow-missing-config flag.
funcAllowMissingConfig¶
func AllowMissingConfig(allowMissingConfigbool) *AllowMissingConfigOption
AllowMissingConfig represents the -allow-missing-config flag.
typeAllowMissingOption¶added inv0.16.0
type AllowMissingOption struct {// contains filtered or unexported fields}AllowMissingOption represents the -allow-missing flag.
funcAllowMissing¶added inv0.16.0
func AllowMissing(allowMissingbool) *AllowMissingOption
AllowMissing represents the -allow-missing flag.
typeApplyOption¶
type ApplyOption interface {// contains filtered or unexported methods}ApplyOption represents options used in the Apply method.
typeBackendConfigOption¶
type BackendConfigOption struct {// contains filtered or unexported fields}BackendConfigOption represents the -backend-config flag.
funcBackendConfig¶
func BackendConfig(backendConfigstring) *BackendConfigOption
BackendConfig represents the -backend-config flag.
typeBackendOption¶
type BackendOption struct {// contains filtered or unexported fields}BackendOption represents the -backend flag.
typeBackupOption¶
type BackupOption struct {// contains filtered or unexported fields}BackupOption represents the -backup flag.
funcDisableBackup¶added inv0.3.0
func DisableBackup() *BackupOption
DisableBackup is a convenience method for Backup("-"), indicating backup state should be disabled.
typeBackupOutOption¶added inv0.12.0
type BackupOutOption struct {// contains filtered or unexported fields}funcBackupOut¶added inv0.12.0
func BackupOut(pathstring) *BackupOutOption
BackupOutOption represents the -backup-out flag.
typeConfigOption¶
type ConfigOption struct {// contains filtered or unexported fields}ConfigOption represents the -config flag.
typeCopyStateOption¶added inv0.8.0
type CopyStateOption struct {// contains filtered or unexported fields}CopyStateOption represents the -state flag for terraform workspace new. This flag is usedto copy an existing state file in to the new workspace.
funcCopyState¶added inv0.8.0
func CopyState(pathstring) *CopyStateOption
CopyState represents the -state flag for terraform workspace new. This flag is usedto copy an existing state file in to the new workspace.
typeDestroyFlagOption¶
type DestroyFlagOption struct {// contains filtered or unexported fields}DestroyFlagOption represents the -destroy flag.
typeDestroyOption¶
type DestroyOption interface {// contains filtered or unexported methods}DestroyOption represents options used in the Destroy method.
typeDirOrPlanOption¶
type DirOrPlanOption struct {// contains filtered or unexported fields}funcDirOrPlan¶
func DirOrPlan(pathstring) *DirOrPlanOption
typeDrawCyclesOption¶added inv0.16.0
type DrawCyclesOption struct {// contains filtered or unexported fields}funcDrawCycles¶added inv0.16.0
func DrawCycles(drawCyclesbool) *DrawCyclesOption
DrawCycles represents the -draw-cycles flag.
typeDryRunOption¶added inv0.12.0
type DryRunOption struct {// contains filtered or unexported fields}typeErrManualEnvVar¶added inv0.4.0
type ErrManualEnvVar struct {Namestring}ErrManualEnvVar is returned when an env var that should be set programatically via an option or methodis set via the manual environment passing functions.
func (*ErrManualEnvVar)Error¶added inv0.4.0
func (err *ErrManualEnvVar) Error()string
typeErrNoSuitableBinary¶
type ErrNoSuitableBinary struct {// contains filtered or unexported fields}func (*ErrNoSuitableBinary)Error¶
func (e *ErrNoSuitableBinary) Error()string
func (*ErrNoSuitableBinary)Unwrap¶added inv0.13.0
func (e *ErrNoSuitableBinary) Unwrap()error
typeErrVersionMismatch¶
ErrVersionMismatch is returned when the detected Terraform version is not compatible with thecommand or flags being used in this invocation.
func (*ErrVersionMismatch)Error¶added inv0.5.0
func (e *ErrVersionMismatch) Error()string
typeFSMirrorOption¶added inv0.15.0
type FSMirrorOption struct {// contains filtered or unexported fields}funcFSMirror¶added inv0.15.0
func FSMirror(fsMirrorstring) *FSMirrorOption
FSMirror represents the -fs-mirror option (path to filesystem mirror directory)
typeForceCopyOption¶
type ForceCopyOption struct {// contains filtered or unexported fields}funcForceCopy¶
func ForceCopy(forceCopybool) *ForceCopyOption
typeForceOption¶added inv0.12.0
type ForceOption struct {// contains filtered or unexported fields}funcForce¶added inv0.12.0
func Force(forcebool) *ForceOption
typeForceUnlockOption¶added inv0.16.0
type ForceUnlockOption interface {// contains filtered or unexported methods}typeFormatOption¶added inv0.11.0
type FormatOption interface {// contains filtered or unexported methods}typeFromModuleOption¶
type FromModuleOption struct {// contains filtered or unexported fields}funcFromModule¶
func FromModule(sourcestring) *FromModuleOption
typeGenerateConfigOutOption¶added inv0.24.0
type GenerateConfigOutOption struct {// contains filtered or unexported fields}funcGenerateConfigOut¶added inv0.24.0
func GenerateConfigOut(pathstring) *GenerateConfigOutOption
typeGetCmdOption¶added inv0.14.0
type GetCmdOption interface {// contains filtered or unexported methods}GetCmdOption represents options used in the Get method.
typeGetPluginsOption¶
type GetPluginsOption struct {// contains filtered or unexported fields}funcGetPlugins¶
func GetPlugins(getPluginsbool) *GetPluginsOption
typeGraphOption¶added inv0.16.0
type GraphOption interface {// contains filtered or unexported methods}typeGraphPlanOption¶added inv0.16.0
type GraphPlanOption struct {// contains filtered or unexported fields}funcGraphPlan¶added inv0.16.0
func GraphPlan(filestring) *GraphPlanOption
GraphPlan represents the -plan flag which is a specified plan file string
typeGraphTypeOption¶added inv0.16.0
type GraphTypeOption struct {// contains filtered or unexported fields}funcGraphType¶added inv0.16.0
func GraphType(graphTypestring) *GraphTypeOption
typeImportOption¶
type ImportOption interface {// contains filtered or unexported methods}ImportOption represents options used in the Import method.
typeInitOption¶
type InitOption interface {// contains filtered or unexported methods}InitOption represents options used in the Init method.
typeLockOption¶
type LockOption struct {// contains filtered or unexported fields}LockOption represents the -lock flag.
typeLockTimeoutOption¶
type LockTimeoutOption struct {// contains filtered or unexported fields}LockTimeoutOption represents the -lock-timeout flag.
funcLockTimeout¶
func LockTimeout(lockTimeoutstring) *LockTimeoutOption
LockTimeout represents the -lock-timeout flag.
typeNetMirrorOption¶added inv0.15.0
type NetMirrorOption struct {// contains filtered or unexported fields}funcNetMirror¶added inv0.15.0
func NetMirror(netMirrorstring) *NetMirrorOption
NetMirror represents the -net-mirror option (base URL of a network mirror)
typeNextMessage¶added inv0.24.0
typeOutputMeta¶
type OutputMeta struct {Sensitivebool `json:"sensitive"`Typejson.RawMessage `json:"type"`Valuejson.RawMessage `json:"value"`}OutputMeta represents the JSON output of 'terraform output -json',which resembles state format version 3 due to a historical accident.Please see hashicorp/terraform/command/output.go.TODO KEM: Should this type be in terraform-json?
typeOutputOption¶
type OutputOption interface {// contains filtered or unexported methods}OutputOption represents options used in the Output method.
typeParallelismOption¶
type ParallelismOption struct {// contains filtered or unexported fields}funcParallelism¶
func Parallelism(nint) *ParallelismOption
typePlanOption¶
type PlanOption interface {// contains filtered or unexported methods}PlanOption represents options used in the Plan method.
typePlatformOption¶added inv0.15.0
type PlatformOption struct {// contains filtered or unexported fields}funcPlatform¶added inv0.15.0
func Platform(platformstring) *PlatformOption
Platform represents the -platform flag which is an os_arch string
typePluginDirOption¶
type PluginDirOption struct {// contains filtered or unexported fields}funcPluginDir¶
func PluginDir(pluginDirstring) *PluginDirOption
typeProviderOption¶added inv0.15.0
type ProviderOption struct {// contains filtered or unexported fields}funcProvider¶added inv0.15.0
func Provider(providersstring) *ProviderOption
Provider represents the positional argument (provider source address)
typeProvidersLockOption¶added inv0.15.0
type ProvidersLockOption interface {// contains filtered or unexported methods}typeQueryOption¶added inv0.24.0
type QueryOption interface {// contains filtered or unexported methods}QueryOption represents options used in the Query method.
typeReattachConfig¶added inv0.9.0
type ReattachConfig struct {ProtocolstringProtocolVersionintPidintTestboolAddrReattachConfigAddr}ReattachConfig holds the information Terraform needs to be able to attachitself to a provider process, so it can drive the process.
typeReattachConfigAddr¶added inv0.9.0
ReattachConfigAddr is a JSON-encoding friendly version of net.Addr.
typeReattachInfo¶added inv0.9.0
type ReattachInfo map[string]ReattachConfig
typeReattachOption¶added inv0.9.0
type ReattachOption struct {// contains filtered or unexported fields}funcReattach¶added inv0.9.0
func Reattach(infoReattachInfo) *ReattachOption
typeReconfigureOption¶
type ReconfigureOption struct {// contains filtered or unexported fields}funcReconfigure¶
func Reconfigure(reconfigurebool) *ReconfigureOption
typeRecursiveOption¶added inv0.11.0
type RecursiveOption struct {// contains filtered or unexported fields}funcRecursive¶added inv0.11.0
func Recursive(rbool) *RecursiveOption
typeRefreshCmdOption¶added inv0.7.0
type RefreshCmdOption interface {// contains filtered or unexported methods}RefreshCmdOption represents options used in the Refresh method.
typeRefreshOnlyOption¶added inv0.19.0
type RefreshOnlyOption struct {// contains filtered or unexported fields}funcRefreshOnly¶added inv0.19.0
func RefreshOnly(refreshOnlybool) *RefreshOnlyOption
typeRefreshOption¶
type RefreshOption struct {// contains filtered or unexported fields}funcRefresh¶
func Refresh(refreshbool) *RefreshOption
typeReplaceOption¶added inv0.15.0
type ReplaceOption struct {// contains filtered or unexported fields}funcReplace¶added inv0.15.0
func Replace(addressstring) *ReplaceOption
typeShowOption¶added inv0.9.0
type ShowOption interface {// contains filtered or unexported methods}typeStateMvCmdOption¶added inv0.12.0
type StateMvCmdOption interface {// contains filtered or unexported methods}StateMvCmdOption represents options used in the Refresh method.
typeStateOption¶
type StateOption struct {// contains filtered or unexported fields} funcStatedeprecated
func State(pathstring) *StateOption
State represents the -state flag.
Deprecated: The -state CLI flag is a legacy flag and should not be used.If you need a different state file for every run, you can instead use thelocal backend.Seehttps://github.com/hashicorp/terraform/issues/25920#issuecomment-676560799
typeStateOutOption¶
type StateOutOption struct {// contains filtered or unexported fields}funcStateOut¶
func StateOut(pathstring) *StateOutOption
typeStatePullOption¶added inv0.17.0
type StatePullOption interface {// contains filtered or unexported methods}typeStatePushCmdOption¶added inv0.17.0
type StatePushCmdOption interface {// contains filtered or unexported methods}StatePushCmdOption represents options used in the Refresh method.
typeStateRmCmdOption¶added inv0.13.0
type StateRmCmdOption interface {// contains filtered or unexported methods}StateRmCmdOption represents options used in the Refresh method.
typeTaintOption¶added inv0.16.0
type TaintOption interface {// contains filtered or unexported methods}TaintOption represents options used in the Taint method.
typeTargetOption¶
type TargetOption struct {// contains filtered or unexported fields}funcTarget¶
func Target(resourcestring) *TargetOption
typeTerraform¶
type Terraform struct {// contains filtered or unexported fields}Terraform represents the Terraform CLI executable and working directory.
Typically this is constructed against the root module of a Terraform configurationbut you can override paths used in some commands depending on the availableoptions.
All functions that execute CLI commands take a context.Context. It should be noted thatexec.Cmd.Run will not return context.DeadlineExceeded or context.Canceled by default, wehave augmented our wrapped errors to respond true to errors.Is for context.DeadlineExceededand context.Canceled if those are present on the context when the error is parsed. Seehttps://github.com/golang/go/issues/21880 for more about the Go limitations.
By default, the instance inherits the environment from the calling code (using os.Environ)but it ignores certain environment variables that are managed within the code and prohibitssetting them through SetEnv:
- TF_APPEND_USER_AGENT
- TF_IN_AUTOMATION
- TF_INPUT
- TF_LOG
- TF_LOG_PATH
- TF_REATTACH_PROVIDERS
- TF_DISABLE_PLUGIN_TLS
- TF_SKIP_PROVIDER_VERIFY
funcNewTerraform¶
NewTerraform returns a Terraform struct with default values for all fields.If a blank execPath is supplied, NewTerraform will error.Use hc-install or output from os.LookPath to get a desirable execPath.
func (*Terraform)Apply¶
func (tf *Terraform) Apply(ctxcontext.Context, opts ...ApplyOption)error
Apply represents the terraform apply subcommand.
func (*Terraform)ApplyJSON¶added inv0.18.0
ApplyJSON represents the terraform apply subcommand with the `-json` flag.Using the `-json` flag will result in[machine-readable](https://developer.hashicorp.com/terraform/internals/machine-readable-ui)JSON being written to the supplied `io.Writer`. ApplyJSON is likely to beremoved in a future major version in favour of Apply returning JSON by default.
func (*Terraform)Destroy¶
func (tf *Terraform) Destroy(ctxcontext.Context, opts ...DestroyOption)error
Destroy represents the terraform destroy subcommand.
func (*Terraform)DestroyJSON¶added inv0.18.0
DestroyJSON represents the terraform destroy subcommand with the `-json` flag.Using the `-json` flag will result in[machine-readable](https://developer.hashicorp.com/terraform/internals/machine-readable-ui)JSON being written to the supplied `io.Writer`. DestroyJSON is likely to beremoved in a future major version in favour of Destroy returning JSON by default.
func (*Terraform)ForceUnlock¶added inv0.16.0
ForceUnlock represents the `terraform force-unlock` command
func (*Terraform)Format¶added inv0.12.0
Format performs formatting on the unformatted io.Reader (as stdin to the CLI) and returnsthe formatted result on the formatted io.Writer.
func (*Terraform)FormatCheck¶added inv0.11.0
FormatCheck returns true if the config files in the working or selected (via DirOption) directory are already formatted.
func (*Terraform)FormatString¶added inv0.11.0
FormatString formats a passed string.
func (*Terraform)FormatWrite¶added inv0.11.0
func (tf *Terraform) FormatWrite(ctxcontext.Context, opts ...FormatOption)error
FormatWrite attempts to format and modify all config files in the working or selected (via DirOption) directory.
func (*Terraform)Get¶added inv0.14.0
func (tf *Terraform) Get(ctxcontext.Context, opts ...GetCmdOption)error
Get represents the terraform get subcommand.
func (*Terraform)Init¶
func (tf *Terraform) Init(ctxcontext.Context, opts ...InitOption)error
Init represents the terraform init subcommand.
func (*Terraform)InitJSON¶added inv0.22.0
InitJSON represents the terraform init subcommand with the `-json` flag.Using the `-json` flag will result in[machine-readable](https://developer.hashicorp.com/terraform/internals/machine-readable-ui)JSON being written to the supplied `io.Writer`.
func (*Terraform)MetadataFunctions¶added inv0.18.0
MetadataFunctions represents the terraform metadata functions -json subcommand.
func (*Terraform)Output¶
func (tf *Terraform) Output(ctxcontext.Context, opts ...OutputOption) (map[string]OutputMeta,error)
Output represents the terraform output subcommand.
func (*Terraform)Plan¶
Plan executes `terraform plan` with the specified options and waits for itto complete.
The returned boolean is false when the plan diff is empty (no changes) andtrue when the plan diff is non-empty (changes present).
The returned error is nil if `terraform plan` has been executed and exitswith either 0 or 2.
func (*Terraform)PlanJSON¶added inv0.18.0
PlanJSON executes `terraform plan` with the specified options as well as the`-json` flag and waits for it to complete.
Using the `-json` flag will result in[machine-readable](https://developer.hashicorp.com/terraform/internals/machine-readable-ui)JSON being written to the supplied `io.Writer`.
The returned boolean is false when the plan diff is empty (no changes) andtrue when the plan diff is non-empty (changes present).
The returned error is nil if `terraform plan` has been executed and exitswith either 0 or 2.
PlanJSON is likely to be removed in a future major version in favour ofPlan returning JSON by default.
func (*Terraform)ProvidersLock¶added inv0.15.0
func (tf *Terraform) ProvidersLock(ctxcontext.Context, opts ...ProvidersLockOption)error
ProvidersLock represents the `terraform providers lock` command
func (*Terraform)ProvidersSchema¶
ProvidersSchema represents the terraform providers schema -json subcommand.
func (*Terraform)QueryJSON¶added inv0.24.0
func (tf *Terraform) QueryJSON(ctxcontext.Context, opts ...QueryOption) (iter.Seq[NextMessage],error)
QueryJSON executes `terraform query` with the specified options as well as the`-json` flag and waits for it to complete.
Using the `-json` flag will result in[machine-readable](https://developer.hashicorp.com/terraform/internals/machine-readable-ui)JSON being written to the supplied `io.Writer`.
The returned error is nil if `terraform query` has been executed and exitswith 0.
QueryJSON is likely to be removed in a future major version in favour ofquery returning JSON by default.
func (*Terraform)Refresh¶added inv0.7.0
func (tf *Terraform) Refresh(ctxcontext.Context, opts ...RefreshCmdOption)error
Refresh represents the terraform refresh subcommand.
func (*Terraform)RefreshJSON¶added inv0.18.0
RefreshJSON represents the terraform refresh subcommand with the `-json` flag.Using the `-json` flag will result in[machine-readable](https://developer.hashicorp.com/terraform/internals/machine-readable-ui)JSON being written to the supplied `io.Writer`. RefreshJSON is likely to beremoved in a future major version in favour of Refresh returning JSON by default.
func (*Terraform)SetAppendUserAgent¶added inv0.8.0
SetAppendUserAgent sets the TF_APPEND_USER_AGENT environment variable forTerraform CLI execution.
func (*Terraform)SetDisablePluginTLS¶added inv0.9.0
SetDisablePluginTLS sets the TF_DISABLE_PLUGIN_TLS environment variable forTerraform CLI execution.
func (*Terraform)SetEnableLegacyPipeClosing¶added inv0.23.1
SetEnableLegacyPipeClosing causes the library to "force-close" stdio pipes.This works around a bug in Terraform < v1.1 that would otherwise leavethe process (and caller) hanging after graceful shutdown.
This option can be safely ignored (set to false) with Terraform 1.1+.
func (*Terraform)SetEnv¶
SetEnv allows you to override environment variables, this should not be used for any well knownTerraform environment variables that are already covered in options. Pass nil to copy the valuesfrom os.Environ. Attempting to set environment variables that should be managed manually willresult in ErrManualEnvVar being returned.
func (*Terraform)SetLog¶added inv0.17.0
SetLog sets the TF_LOG environment variable for Terraform CLI execution.This must be combined with a call to SetLogPath to take effect.
This is only compatible with Terraform CLI 0.15.0 or later as setting thelog level was unreliable in earlier versions. It will default to TRACE whenSetLogPath is called on versions 0.14.11 and earlier, or if SetLogCore andSetLogProvider have not been called before SetLogPath on versions 0.15.0 andlater.
func (*Terraform)SetLogCore¶added inv0.17.2
SetLogCore sets the TF_LOG_CORE environment variable for Terraform CLIexecution. This must be combined with a call to SetLogPath to take effect.
This is only compatible with Terraform CLI 0.15.0 or later.
func (*Terraform)SetLogPath¶added inv0.4.0
SetLogPath sets the TF_LOG_PATH environment variable for Terraform CLIexecution.
func (*Terraform)SetLogProvider¶added inv0.17.2
SetLogProvider sets the TF_LOG_PROVIDER environment variable for TerraformCLI execution. This must be combined with a call to SetLogPath to takeeffect.
This is only compatible with Terraform CLI 0.15.0 or later.
func (*Terraform)SetLogger¶
func (tf *Terraform) SetLogger(logger printfer)
SetLogger specifies a logger for tfexec to use.
func (*Terraform)SetSkipProviderVerify¶added inv0.9.0
SetSkipProviderVerify sets the TF_SKIP_PROVIDER_VERIFY environment variablefor Terraform CLI execution. This is no longer used in 0.13.0 and greater.
func (*Terraform)SetStderr¶added inv0.6.0
SetStderr specifies a writer to stream stderr to for every command.
This should be used for information or logging purposes only, not controlflow. Any parsing necessary should be added as functionality to this package.
func (*Terraform)SetStdout¶added inv0.6.0
SetStdout specifies a writer to stream stdout to for every command.
This should be used for information or logging purposes only, not controlflow. Any parsing necessary should be added as functionality to this package.
func (*Terraform)SetWaitDelay¶added inv0.23.0
SetWaitDelay sets the WaitDelay of running Terraform process asexec.Cmd
func (*Terraform)Show¶added inv0.3.0
Show reads the default state path and outputs the state.To read a state or plan file, ShowState or ShowPlan must be used instead.
func (*Terraform)ShowPlanFile¶added inv0.7.0
func (tf *Terraform) ShowPlanFile(ctxcontext.Context, planPathstring, opts ...ShowOption) (*tfjson.Plan,error)
ShowPlanFile reads a given plan file and outputs the plan.
func (*Terraform)ShowPlanFileRaw¶added inv0.10.0
func (tf *Terraform) ShowPlanFileRaw(ctxcontext.Context, planPathstring, opts ...ShowOption) (string,error)
ShowPlanFileRaw reads a given plan file and outputs the plan in ahuman-friendly, opaque format.
func (*Terraform)ShowStateFile¶added inv0.7.0
func (tf *Terraform) ShowStateFile(ctxcontext.Context, statePathstring, opts ...ShowOption) (*tfjson.State,error)
ShowStateFile reads a given state file and outputs the state.
func (*Terraform)StateMv¶added inv0.12.0
func (tf *Terraform) StateMv(ctxcontext.Context, sourcestring, destinationstring, opts ...StateMvCmdOption)error
StateMv represents the terraform state mv subcommand.
func (*Terraform)Test¶added inv0.19.0
Test represents the terraform test -json subcommand.
The given io.Writer, if specified, will receive[machine-readable](https://developer.hashicorp.com/terraform/internals/machine-readable-ui)JSON from Terraform including test results.
func (*Terraform)Upgrade012¶added inv0.12.0
func (tf *Terraform) Upgrade012(ctxcontext.Context, opts ...Upgrade012Option)error
Upgrade012 represents the terraform 0.12upgrade subcommand.
func (*Terraform)Upgrade013¶added inv0.14.0
func (tf *Terraform) Upgrade013(ctxcontext.Context, opts ...Upgrade013Option)error
Upgrade013 represents the terraform 0.13upgrade subcommand.
func (*Terraform)Validate¶added inv0.12.0
Validate represents the validate subcommand to the Terraform CLI. The -jsonflag support was added in 0.12.0, so this will not work on earlier versions.
func (*Terraform)Version¶added inv0.4.0
func (tf *Terraform) Version(ctxcontext.Context, skipCachebool) (tfVersion *version.Version, providerVersions map[string]*version.Version, errerror)
Version returns structured output from the terraform version command including both the Terraform CLI versionand any initialized provider versions. This will read cached values when present unless the skipCache parameteris set to true.
func (*Terraform)WorkingDir¶added inv0.5.0
WorkingDir returns the working directory for Terraform.
func (*Terraform)WorkspaceDelete¶added inv0.16.0
func (tf *Terraform) WorkspaceDelete(ctxcontext.Context, workspacestring, opts ...WorkspaceDeleteCmdOption)error
WorkspaceDelete represents the workspace delete subcommand to the Terraform CLI.
func (*Terraform)WorkspaceList¶added inv0.8.0
WorkspaceList represents the workspace list subcommand to the Terraform CLI.
func (*Terraform)WorkspaceNew¶added inv0.8.0
func (tf *Terraform) WorkspaceNew(ctxcontext.Context, workspacestring, opts ...WorkspaceNewCmdOption)error
WorkspaceNew represents the workspace new subcommand to the Terraform CLI.
func (*Terraform)WorkspaceSelect¶added inv0.8.0
WorkspaceSelect represents the workspace select subcommand to the Terraform CLI.
typeTestOption¶added inv0.19.0
type TestOption interface {// contains filtered or unexported methods}typeTestsDirectoryOption¶added inv0.19.0
type TestsDirectoryOption struct {// contains filtered or unexported fields}funcTestsDirectory¶added inv0.19.0
func TestsDirectory(testsDirectorystring) *TestsDirectoryOption
TestsDirectory represents the -tests-directory option (path to tests files)
typeUntaintOption¶added inv0.16.0
type UntaintOption interface {// contains filtered or unexported methods}OutputOption represents options used in the Output method.
typeUpdateOption¶added inv0.14.0
type UpdateOption struct {// contains filtered or unexported fields}funcUpdate¶added inv0.14.0
func Update(updatebool) *UpdateOption
typeUpgrade012Option¶added inv0.12.0
type Upgrade012Option interface {// contains filtered or unexported methods}Upgrade012Option represents options used in the Destroy method.
typeUpgrade013Option¶added inv0.14.0
type Upgrade013Option interface {// contains filtered or unexported methods}Upgrade013Option represents options used in the Destroy method.
typeUpgradeOption¶
type UpgradeOption struct {// contains filtered or unexported fields}funcUpgrade¶
func Upgrade(upgradebool) *UpgradeOption
typeUseJSONNumberOption¶added inv0.20.0
type UseJSONNumberOption struct {// contains filtered or unexported fields}funcJSONNumber¶added inv0.20.0
func JSONNumber(useJSONNumberbool) *UseJSONNumberOption
JSONNumber determines how numerical values are handled during JSON decoding.
typeVarFileOption¶
type VarFileOption struct {// contains filtered or unexported fields}funcVarFile¶
func VarFile(pathstring) *VarFileOption
typeVerifyPluginsOption¶
type VerifyPluginsOption struct {// contains filtered or unexported fields}funcVerifyPlugins¶
func VerifyPlugins(verifyPluginsbool) *VerifyPluginsOption
typeWorkspaceDeleteCmdOption¶added inv0.16.0
type WorkspaceDeleteCmdOption interface {// contains filtered or unexported methods}WorkspaceDeleteCmdOption represents options that are applicable to the WorkspaceDelete method.
typeWorkspaceNewCmdOption¶added inv0.8.0
type WorkspaceNewCmdOption interface {// contains filtered or unexported methods}WorkspaceNewCmdOption represents options that are applicable to the WorkspaceNew method.
Source Files¶
- apply.go
- cmd.go
- cmd_linux.go
- destroy.go
- doc.go
- errors.go
- fmt.go
- force_unlock.go
- get.go
- graph.go
- import.go
- init.go
- metadata_functions.go
- options.go
- output.go
- plan.go
- providers_lock.go
- providers_schema.go
- query.go
- refresh.go
- show.go
- state_mv.go
- state_pull.go
- state_push.go
- state_rm.go
- taint.go
- terraform.go
- test.go
- untaint.go
- upgrade012.go
- upgrade013.go
- validate.go
- version.go
- workspace_delete.go
- workspace_list.go
- workspace_new.go
- workspace_select.go
- workspace_show.go