migrate

package module
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2020 License: MIT Imports: 10 Imported by: 0

README

terraform-cloud-migrate tests

Migrate a Terraform module to Terraform Cloud

The terraform-cloud-migrate CLI automates the process of adapting a Terraform root module for Terraform Cloud (including Terraform Enterprise). It performs a series of required configuration changes (described below) and runs terraform init which will prompt you to copy state from your existing backend to workspaces in Terraform Cloud.

Versioning your Terraform configuration with git is strongly encouraged so you can recover in the event of unwanted changes.

Usage

terraform-cloud-migrate run \
  --organization my-org \
  --workspace-name my-ws \
  ./path/to/module

# with prefixes
terraform-cloud-migrate run \
  --organization my-org \
  --workspace-prefix my-ws- \
  ./path/to/module

# update terraform_remote_state with --modules
terraform-cloud-migrate run \
  --organization my-org \
  --workspace-name my-ws \
  --modules ~/src/terraform \
  ./path/to/module

Steps

Steps include a link to the Terraform docs where available.

  • Configures a remote backend. (?).
  • Updates any terraform_remote_state data sources that match the previous backend configuration.
  • Replaces terraform.workspace with a variable of your choice, var.environment by default. (?)
  • Renames terraform.tfvars to a name of your choice, default.auto.tfvars by default. (?)

License

MIT © Ben Drucker

Documentation

Index

Constants

View Source
const (
	TfvarsFilename          = "terraform.tfvars"
	TfvarsAlternateFilename = "default.auto.tfvars"
)
View Source
const (
	BackendTypeRemote = "remote"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Change

type Change struct {
	File   *hclwrite.File
	Rename string
}

type Changes

type Changes map[string]*Change

Changes is a map of changed file objects that should be written to prepare the module for Terraform Cloud

type Config

type Config struct {
	Backend           RemoteBackendConfig
	WorkspaceVariable string
	TfvarsFilename    string
	ModulesDir        string
}

type Migration

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

func New

func New(path string, config Config) (*Migration, hcl.Diagnostics)

func (*Migration) Changes

func (m *Migration) Changes() (Changes, hcl.Diagnostics)

type Module

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

Module provides access to information about the Terraform module structure and the ability to update its files

func NewModule

func NewModule(path string) (*Module, hcl.Diagnostics)

func (*Module) Backend

func (m *Module) Backend() *configs.Backend

Backend returns the backend, or nil if none is defined

func (*Module) Dir

func (m *Module) Dir() string

Dir returns the module directory

func (*Module) File

func (m *Module) File(path string) (*hclwrite.File, hcl.Diagnostics)

File returns an existing file object or creates and caches one

func (*Module) HasBackend

func (m *Module) HasBackend() bool

HasBackend returns true if the module has a backend configuration

func (*Module) RemoteStateDataSources

func (m *Module) RemoteStateDataSources() []*configs.Resource

RemoteStateDataSources returns a list of remote state data sources defined for the module

func (*Module) Variables

func (m *Module) Variables() map[string]*configs.Variable

Variables returns the declared variables for the module

type RemoteBackendConfig

type RemoteBackendConfig struct {
	Hostname     string
	Organization string
	Workspaces   WorkspaceConfig
}

type RemoteBackendStep

type RemoteBackendStep struct {
	Config RemoteBackendConfig
	// contains filtered or unexported fields
}

func (*RemoteBackendStep) Changes

func (b *RemoteBackendStep) Changes() (Changes, hcl.Diagnostics)

Changes updates the configured backend

func (*RemoteBackendStep) Complete

func (b *RemoteBackendStep) Complete() bool

Complete checks if the module is using a remote backend

func (*RemoteBackendStep) Description

func (b *RemoteBackendStep) Description() string

Description returns a description of the step

func (*RemoteBackendStep) MultipleWorkspaces

func (b *RemoteBackendStep) MultipleWorkspaces() bool

MultipleWorkspaces returns whether the remote backend will be configured for multiple prefixed workspaces

type RemoteStateStep

type RemoteStateStep struct {
	Path          string
	RemoteBackend RemoteBackendConfig
	// contains filtered or unexported fields
}

func (*RemoteStateStep) Changes

func (s *RemoteStateStep) Changes() (Changes, hcl.Diagnostics)

Changes updates the configured backend

func (*RemoteStateStep) Complete

func (s *RemoteStateStep) Complete() bool

Complete checks if any modules in the path are using remote_state

func (*RemoteStateStep) Description

func (s *RemoteStateStep) Description() string

Description returns a description of the step

type Step

type Step interface {
	// Complete returns whether the step has been completed
	Complete() bool

	// Description returns a description of the step
	Description() string

	// Changes returns a list of files changes and diagnostics if errors ocurred. If Complete() returns true, this should be empty.
	Changes() (Changes, hcl.Diagnostics)
}

Step is a step required to prepare a module to run in Terraform Cloud

type TerraformWorkspaceStep

type TerraformWorkspaceStep struct {
	Variable string
	// contains filtered or unexported fields
}

func (*TerraformWorkspaceStep) Changes

func (s *TerraformWorkspaceStep) Changes() (Changes, hcl.Diagnostics)

Changes determines changes required to remove terraform.workspace

func (*TerraformWorkspaceStep) Complete

func (s *TerraformWorkspaceStep) Complete() bool

Complete checks if any terraform.workspace replaces are proposed

func (*TerraformWorkspaceStep) Description

func (s *TerraformWorkspaceStep) Description() string

Description returns a description of the step

type TfvarsStep

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

func (*TfvarsStep) Changes

func (s *TfvarsStep) Changes() (Changes, hcl.Diagnostics)

Changes determines changes required to remove terraform.workspace

func (*TfvarsStep) Complete

func (s *TfvarsStep) Complete() bool

Complete checks if a terraform.tfvars file exists and returns false if it does

func (*TfvarsStep) Description

func (s *TfvarsStep) Description() string

Description returns a description of the step

type WorkspaceConfig

type WorkspaceConfig struct {
	Name   string
	Prefix string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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