oci_tool

package
v2.1.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2018 License: MPL-2.0 Imports: 11 Imported by: 0

README

About this tool

This tool will target a terraform plan directory and transform all baremetal names found in .tf and .tfstate files to the new oci provider name. It creates a backup of the target directory <plan-directory>.backup as a sibling folder.

It also detects and modifies provider blocks not specifying a region to explicitly use "us-phoenix-1" since the default region value has been removed from the provider.

Provider Setup and Config Verfification

You can use the new and old providers side by side. This is helpful for knowing you are migrating plans from a known good state (no pending changes when running plan), and will be able to verify successful migration (no pending changes running plan with the new provider).

If you configure your plugins with a .terraformrc file, add an entry for the new oci provider, example:

providers {
	oci = "/Users/moi/providers/terraform-provider-oci"
	baremetal = "/Users/moi/providers/terraform-provider-baremetal"
}

Otherwise, drop the new provider in your terraform plugin directory.

Remote State

The oci-tool does not support remote state. If you are using remote state, then the recommended approach is to copy the state file locally, run the oci-tool, and then push the state file back to the remote location. See the documentation here for details about how to unconfigure and reconfigure your backend.

Using the tool

To migrate a plan, follow these steps:

From the plan directory, run terraform plan, make sure there are no pending changes in your plan.

Execute the oci-tool binary, passing the path to your plan directory, example:
oci-tool migrate -dir=<plan-path>

After migrating a plan file, run terraform plan again and verify there are no new pending modifications.

For Terraform v.10+, you will need to initialize terraform for the directory using
terraform init

If the migration was not successful, manually restore the plan files from the .backup directory or run:
oci-tool backup -dir=<plan-path> -restore

After you have verified the migration was successful, delete the backup folder or run:
oci-tool backup -dir=<plan-path> -purge

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddRegionField

func AddRegionField(targetDir string, backupDir string) (err error)

Traverse all .tf files and insert `region = "us-phoenix-1"` where region is not specified

func AddRegionToProvider

func AddRegionToProvider(targetFile string, backupFile string) error

Scan TF files for provider blocks and inject a region value if not specified

func CopyFile

func CopyFile(targetFile string, backupFile string) (err error)

Copy file from targetFile path to backupFile path

func CreateBackup

func CreateBackup(targetDir string, backupDir string) (err error)

Copy target directory and append .backup

func DeleteBackup

func DeleteBackup(backupDir string) (err error)

Remove .backup directory

func Migrate

func Migrate(targetDir string, backupDir string) (err error)

Traverse all .tf files and apply transforms

func MigratePlanFile

func MigratePlanFile(targetFile string, backupFile string) (err error)

Read file from backup location, apply transforms and overwrite original file

func ProcessDirectory

func ProcessDirectory(targetDir string, backupDir string, fileActionFn FileAction, targetExtns ...string) (err error)

Traverse a directory, executing the supplied FileAction on each file

func RestoreBackup

func RestoreBackup(backupDir string, targetDir string) (err error)

Overwrite target directory with contents of .backup directory

Types

type FileAction

type FileAction func(string, string) error

Individual file io strategies for different operations

Jump to

Keyboard shortcuts

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