tfmigrate

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Migrator

type Migrator interface {
	// Plan computes a new state by applying state migration operations to a temporary state.
	// It will fail if terraform plan detects any diffs with the new state.
	Plan(ctx context.Context) error

	// Apply computes a new state and pushes it to remote state.
	// It will fail if terraform plan detects any diffs with the new state.
	// We are intended to this is used for state refactoring.
	// Any state migration operations should not break any real resources.
	Apply(ctx context.Context) error
}

Migrator abstracts migration operations.

type MigratorOption

type MigratorOption struct {
	// ExecPath is a string how terraform command is executed. Default to terraform.
	// It's intended to inject a wrapper command such as direnv.
	// e.g.) direnv exec . terraform
	ExecPath string
}

MigratorOption customizes a behaviror of Migrator. It is used for shared settings across Migrator instances.

type MultiStateAction

type MultiStateAction interface {
	// MultiStateUpdate updates given two states and returns new two states.
	MultiStateUpdate(ctx context.Context, fromTf tfexec.TerraformCLI, toTf tfexec.TerraformCLI, fromState *tfexec.State, toState *tfexec.State) (*tfexec.State, *tfexec.State, error)
}

MultiStateAction abstracts multi state migration operations. It's used for moving resources from a state to another.

func NewMultiStateActionFromString

func NewMultiStateActionFromString(cmdStr string) (MultiStateAction, error)

NewMultiStateActionFromString is a factory method which returns a new MultiStateAction from a given string. cmdStr is a plain text for state operation. This method is useful to build an action from terraform state command. Valid formats are the following. "mv <source> <destination>"

type MultiStateMigrator

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

MultiStateMigrator implements the Migrator interface.

func NewMultiStateMigrator

func NewMultiStateMigrator(fromDir string, toDir string, actions []MultiStateAction, o *MigratorOption) *MultiStateMigrator

NewMultiStateMigrator returns a new MultiStateMigrator instance.

func (*MultiStateMigrator) Apply

func (m *MultiStateMigrator) Apply(ctx context.Context) error

Apply computes new states and pushes them to remote states. It will fail if terraform plan detects any diffs with at least one new state. We are intended to this is used for state refactoring. Any state migration operations should not break any real resources.

func (*MultiStateMigrator) Plan

func (m *MultiStateMigrator) Plan(ctx context.Context) error

Plan computes new states by applying multi state migration operations to temporary states. It will fail if terraform plan detects any diffs with at least one new state.

type MultiStateMvAction

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

MultiStateMvAction implements the MultiStateAction interface. MultiStateMvAction moves a resource from a dir to another. It also can rename an address of resource.

func NewMultiStateMvAction

func NewMultiStateMvAction(source string, destination string) *MultiStateMvAction

NewMultiStateMvAction returns a new MultiStateMvAction instance.

func (*MultiStateMvAction) MultiStateUpdate

func (a *MultiStateMvAction) MultiStateUpdate(ctx context.Context, fromTf tfexec.TerraformCLI, toTf tfexec.TerraformCLI, fromState *tfexec.State, toState *tfexec.State) (*tfexec.State, *tfexec.State, error)

MultiStateUpdate updates given two states and returns new two states. It moves a resource from a dir to another. It also can rename an address of resource.

type StateAction

type StateAction interface {
	// StateUpdate updates a given state and returns a new state.
	StateUpdate(ctx context.Context, tf tfexec.TerraformCLI, state *tfexec.State) (*tfexec.State, error)
}

StateAction abstracts state migration operations.

func NewStateActionFromString

func NewStateActionFromString(cmdStr string) (StateAction, error)

NewStateActionFromString is a factory method which returns a new StateAction from a given string. cmdStr is a plain text for state operation. This method is useful to build an action from terraform state command. Valid formats are the following. "mv <source> <destination>" "rm <addresses>... "import <address> <id>"

type StateImportAction

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

StateImportAction implements the StateAction interface. StateImportAction imports an existing resource to state. Note that the Terraform has terraform import command, not terraform state import command. According to the help of import command, this is because a future version Terraform will not only import state, but also generate configuration. We intentionally use term "StateImportAction" to clarify it imports state only.

func NewStateImportAction

func NewStateImportAction(address string, id string) *StateImportAction

NewStateImportAction returns a new StateImportAction instance.

func (*StateImportAction) StateUpdate

func (a *StateImportAction) StateUpdate(ctx context.Context, tf tfexec.TerraformCLI, state *tfexec.State) (*tfexec.State, error)

StateUpdate updates a given state and returns a new state. It imports an existing resource to state.

type StateMigrator

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

StateMigrator implements the Migrator interface.

func NewStateMigrator

func NewStateMigrator(dir string, actions []StateAction, o *MigratorOption) *StateMigrator

NewStateMigrator returns a new StateMigrator instance.

func (*StateMigrator) Apply

func (m *StateMigrator) Apply(ctx context.Context) error

Apply computes a new state and pushes it to remote state. It will fail if terraform plan detects any diffs with the new state. We are intended to this is used for state refactoring. Any state migration operations should not break any real resources.

func (*StateMigrator) Plan

func (m *StateMigrator) Plan(ctx context.Context) error

Plan computes a new state by applying state migration operations to a temporary state. It will fail if terraform plan detects any diffs with the new state.

type StateMvAction

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

StateMvAction implements the StateAction interface. StateMvAction moves a resource from source address to destination address in the same tfstate file.

func NewStateMvAction

func NewStateMvAction(source string, destination string) *StateMvAction

NewStateMvAction returns a new StateMvAction instance.

func (*StateMvAction) StateUpdate

func (a *StateMvAction) StateUpdate(ctx context.Context, tf tfexec.TerraformCLI, state *tfexec.State) (*tfexec.State, error)

StateUpdate updates a given state and returns a new state. It moves a resource from source address to destination address in the same tfstate file.

type StateRmAction

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

StateRmAction implements the StateAction interface. StateRmAction removes resources from state at given addresses.

func NewStateRmAction

func NewStateRmAction(addresses []string) *StateRmAction

NewStateRmAction returns a new StateRmAction instance.

func (*StateRmAction) StateUpdate

func (a *StateRmAction) StateUpdate(ctx context.Context, tf tfexec.TerraformCLI, state *tfexec.State) (*tfexec.State, error)

StateUpdate updates a given state and returns a new state. It removes resources from state at given addresses.

Jump to

Keyboard shortcuts

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