terraform

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPlan

func GetPlan(ctx context.Context, opts ...Option) (*tfjson.Plan, error)

GetPlan obtains a Terraform plan from the module in the given working directory. It does so by running a series of Terraform commands.

func GetVersion

func GetVersion(ctx context.Context, opts ...Option) (*version.Version, error)

GetVersion obtains the version of the configured Terraform binary.

func WriteMoveCommands

func WriteMoveCommands(w io.Writer, moves []Move, opts ...Option) error

WriteMoveCommands encodes the given moves as a series of Terraform CLI commands and writes them to the given writer.

Moving resources across working directories requires a bit of extra work. In those cases, WriteMoveCommands will write a series of commands that copies the state of the working directories involved to the local filesystem, performs the moves, and pushes the states back to configured backends.

Since Terraform's state can contain sensitive information, the copies are written in the same directory as the working directories. This allows the user to know exactly where their state is stored. The files are not deleted automatically, in case the user wants to use them (to revert any changes, for instance).

func WriteMovedBlocks

func WriteMovedBlocks(w io.Writer, moves []Move) error

WriteMovedBlocks encodes the given moves as a series of Terraform moved blocks, in HCL, and writes them to the given writer.

Currently, moved blocks cannot be used to move resources between different working directories. If the given moves contain such a move, WriteMovedBlocks returns an error.

Types

type Move

type Move struct {
	// The working directory the resource is being moved from. Equal to
	// ToWorkdir when the resource is being moved within the same working
	// directory.
	FromWorkdir string
	// The working directory the resource is being moved to. Equal to
	// FromWorkdir when the resource is being moved within the same working
	// directory.
	ToWorkdir string

	// The resource's address before the move.
	FromAddress string
	// The resource's address after the move.
	ToAddress string
}

A Move represents a an object in Terraform's state that should be moved to another address and possibly to another working directory. This is analogous to a moved block or a state mv command.

type Option

type Option func(*settings)

An Option configures how Terraform commands are run.

func WithSkipInit

func WithSkipInit(skipInit bool) Option

WithSkipInit configures whether the init step should be skipped. By default, this step is not skipped.

Skipping the init step can save time, but subsequent steps may fail if the module was not initialized beforehand.

func WithSkipRefresh

func WithSkipRefresh(skipRefresh bool) Option

WithSkipRefresh configures whether the refresh step should be skipped. By default, this step is not skipped.

Skipping the refresh step can save time, but can result in Terraform basing its plan on stale data.

func WithTerraformBin

func WithTerraformBin(path string) Option

WithTerraformBin replaces the Terraform binary with the provided executable. If this option is not provided, it defaults to the `terraform` executable in the current PATH.

func WithWorkdir

func WithWorkdir(workdir string) Option

WithWorkdir sets the directory Terraform commands will run. If this option is not provided, it defaults to the current working directory.

Jump to

Keyboard shortcuts

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