Skip to content

Commit

Permalink
change disable_*_dir_diff_check to *_skip_plan
Browse files Browse the repository at this point in the history
Per feedback from @minamijoyo
(#142 (comment)),
this changes the option field names for disabling plan/diff checks.

Signed-off-by: Mike Ball <mikedball@gmail.com>
  • Loading branch information
mdb committed Aug 4, 2023
1 parent 87dd6ac commit f05adc9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 38 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -638,10 +638,10 @@ migration "state" "test" {
The `multi_state` migration updates states in two different directories. It is intended for moving resources across states. It has the following attributes.

- `from_dir` (required): A working directory where states of resources move from.
- `disable_from_dir_diff_check` (optional): If true, `tfmigrate` will not perform and analyze a `terraform plan` in the `from_dir`.
- `from_skip_plan` (optional): If true, `tfmigrate` will not perform and analyze a `terraform plan` in the `from_dir`.
- `from_workspace` (optional): A terraform workspace in the FROM directory. Defaults to "default".
- `to_dir` (required): A working directory where states of resources move to.
- `disable_to_dir_diff_check` (optional): If true, `tfmigrate` will not perform and analyze a `terraform plan` in the `to_dir`.
- `to_skip_plan` (optional): If true, `tfmigrate` will not perform and analyze a `terraform plan` in the `to_dir`.
- `to_workspace` (optional): A terraform workspace in the TO directory. Defaults to "default".
- `actions` (required): Actions is a list of multi state action. An action is a plain text for state operation. Valid formats are the following.
- `"mv <source> <destination>"`
Expand Down
46 changes: 23 additions & 23 deletions tfmigrate/multi_state_migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import (
type MultiStateMigratorConfig struct {
// FromDir is a working directory where states of resources move from.
FromDir string `hcl:"from_dir"`
// DisableFromDirDiffCheck controls whether or not to run and analyze Terraform
// plan within the from_dir.
DisableFromDirDiffCheck bool `hcl:"disable_from_dir_diff_check,optional"`
// FromSkipPlan controls whether or not to run and analyze Terraform plan
// within the from_dir.
FromSkipPlan bool `hcl:"from_skip_plan,optional"`
// ToDir is a working directory where states of resources move to.
ToDir string `hcl:"to_dir"`
// DisableToDirDiffCheck controls whether or not to and analyze Terraform plan
// within the to_dir.
DisableToDirDiffCheck bool `hcl:"disable_to_dir_diff_check,optional"`
// ToSkipPlan controls whether or not to and analyze Terraform plan within the
// to_dir.
ToSkipPlan bool `hcl:"to_skip_plan,optional"`
// FromWorkspace is a workspace within FromDir
FromWorkspace string `hcl:"from_workspace,optional"`
// ToWorkspace is a workspace within ToDir
Expand Down Expand Up @@ -62,19 +62,19 @@ func (c *MultiStateMigratorConfig) NewMigrator(o *MigratorOption) (Migrator, err
c.ToWorkspace = "default"
}

return NewMultiStateMigrator(c.FromDir, c.ToDir, c.FromWorkspace, c.ToWorkspace, actions, o, c.Force, c.DisableFromDirDiffCheck, c.DisableToDirDiffCheck), nil
return NewMultiStateMigrator(c.FromDir, c.ToDir, c.FromWorkspace, c.ToWorkspace, actions, o, c.Force, c.FromSkipPlan, c.ToSkipPlan), nil
}

// MultiStateMigrator implements the Migrator interface.
type MultiStateMigrator struct {
// fromTf is an instance of TerraformCLI which executes terraform command in a fromDir.
fromTf tfexec.TerraformCLI
// disableFromDirDiffCheck disables the running of Terraform plan in fromDir.
disableFromDirDiffCheck bool
// fromSkipPlan disables the running of Terraform plan in fromDir.
fromSkipPlan bool
// fromTf is an instance of TerraformCLI which executes terraform command in a toDir.
toTf tfexec.TerraformCLI
// disableToDirDiffCheck disables the running of Terraform plan in toDir.
disableToDirDiffCheck bool
// toSkipPlan disables the running of Terraform plan in toDir.
toSkipPlan bool
//fromWorkspace is the workspace from which the resource will be migrated
fromWorkspace string
//toWorkspace is the workspace to which the resource will be migrated
Expand All @@ -92,7 +92,7 @@ var _ Migrator = (*MultiStateMigrator)(nil)

// NewMultiStateMigrator returns a new MultiStateMigrator instance.
func NewMultiStateMigrator(fromDir string, toDir string, fromWorkspace string, toWorkspace string,
actions []MultiStateAction, o *MigratorOption, force bool, disableFromDirDiffCheck bool, disableToDirDiffCheck bool) *MultiStateMigrator {
actions []MultiStateAction, o *MigratorOption, force bool, fromSkipPlan bool, toSkipPlan bool) *MultiStateMigrator {
fromTf := tfexec.NewTerraformCLI(tfexec.NewExecutor(fromDir, os.Environ()))
toTf := tfexec.NewTerraformCLI(tfexec.NewExecutor(toDir, os.Environ()))
if o != nil && len(o.ExecPath) > 0 {
Expand All @@ -101,15 +101,15 @@ func NewMultiStateMigrator(fromDir string, toDir string, fromWorkspace string, t
}

return &MultiStateMigrator{
fromTf: fromTf,
disableFromDirDiffCheck: disableFromDirDiffCheck,
toTf: toTf,
disableToDirDiffCheck: disableToDirDiffCheck,
fromWorkspace: fromWorkspace,
toWorkspace: toWorkspace,
actions: actions,
o: o,
force: force,
fromTf: fromTf,
fromSkipPlan: fromSkipPlan,
toTf: toTf,
toSkipPlan: toSkipPlan,
fromWorkspace: fromWorkspace,
toWorkspace: toWorkspace,
actions: actions,
o: o,
force: force,
}
}

Expand Down Expand Up @@ -151,7 +151,7 @@ func (m *MultiStateMigrator) plan(ctx context.Context) (*tfexec.State, *tfexec.S
planOpts = append(planOpts, "-out="+m.o.PlanOut)
}

if m.disableFromDirDiffCheck {
if m.fromSkipPlan {
// check if a plan in fromDir has no changes.
log.Printf("[INFO] [migrator@%s] check diffs\n", m.fromTf.Dir())
_, err = m.fromTf.Plan(ctx, fromCurrentState, planOpts...)
Expand All @@ -170,7 +170,7 @@ func (m *MultiStateMigrator) plan(ctx context.Context) (*tfexec.State, *tfexec.S
log.Printf("[INFO] [migrator@%s] skipping check diffs\n", m.fromTf.Dir())
}

if m.disableToDirDiffCheck {
if m.toSkipPlan {
// check if a plan in toDir has no changes.
log.Printf("[INFO] [migrator@%s] check diffs\n", m.toTf.Dir())
_, err = m.toTf.Plan(ctx, toCurrentState, planOpts...)
Expand Down
26 changes: 13 additions & 13 deletions tfmigrate/multi_state_migrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func TestMultiStateMigratorConfigNewMigrator(t *testing.T) {
{
desc: "valid and default workspace, with diff check disabled in from dir",
config: &MultiStateMigratorConfig{
FromDir: "dir1",
DisableFromDirDiffCheck: true,
ToDir: "dir2",
FromDir: "dir1",
FromSkipPlan: true,
ToDir: "dir2",
Actions: []string{
"mv null_resource.foo null_resource.foo2",
"mv null_resource.bar null_resource.bar2",
Expand All @@ -52,9 +52,9 @@ func TestMultiStateMigratorConfigNewMigrator(t *testing.T) {
{
desc: "valid and default workspace, with diff check disabled in to dir",
config: &MultiStateMigratorConfig{
FromDir: "dir1",
ToDir: "dir2",
DisableToDirDiffCheck: true,
FromDir: "dir1",
ToDir: "dir2",
ToSkipPlan: true,
Actions: []string{
"mv null_resource.foo null_resource.foo2",
"mv null_resource.bar null_resource.bar2",
Expand All @@ -68,10 +68,10 @@ func TestMultiStateMigratorConfigNewMigrator(t *testing.T) {
{
desc: "valid and default workspace, with diff check disabled in from and to dirs",
config: &MultiStateMigratorConfig{
FromDir: "dir1",
DisableFromDirDiffCheck: true,
ToDir: "dir2",
DisableToDirDiffCheck: true,
FromDir: "dir1",
FromSkipPlan: true,
ToDir: "dir2",
ToSkipPlan: true,
Actions: []string{
"mv null_resource.foo null_resource.foo2",
"mv null_resource.bar null_resource.bar2",
Expand Down Expand Up @@ -273,7 +273,7 @@ resource "null_resource" "qux" {}
}
}

func TestAccMultiStateMigratorApplyWithDisableFromDirDiffCheck(t *testing.T) {
func TestAccMultiStateMigratorApplyWithFromSkipPlan(t *testing.T) {
tfexec.SkipUnlessAcceptanceTestEnabled(t)
ctx := context.Background()

Expand Down Expand Up @@ -386,7 +386,7 @@ resource "null_resource" "qux" {}
}
}

func TestAccMultiStateMigratorApplyWithDisableToDirDiffCheck(t *testing.T) {
func TestAccMultiStateMigratorApplyWithToSkipPlan(t *testing.T) {
tfexec.SkipUnlessAcceptanceTestEnabled(t)
ctx := context.Background()

Expand Down Expand Up @@ -497,7 +497,7 @@ resource "null_resource" "baz" {}
}
}

func TestAccMultiStateMigratorApplyWithDisableDiffCheck(t *testing.T) {
func TestAccMultiStateMigratorApplyWithSkipPlan(t *testing.T) {
tfexec.SkipUnlessAcceptanceTestEnabled(t)
ctx := context.Background()

Expand Down

0 comments on commit f05adc9

Please sign in to comment.