Skip to content

Commit

Permalink
Merge pull request #195 from minamijoyo/restore-to-skip-plan
Browse files Browse the repository at this point in the history
Restore and deprecate the `to_skip_plan` in a single-state migration
  • Loading branch information
minamijoyo authored Dec 3, 2024
2 parents 5357815 + 58718c7 commit 8c3c283
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 4 deletions.
46 changes: 46 additions & 0 deletions config/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,52 @@ migration "state" "test" {
},
ok: true,
},
{
desc: "state with skip_plan",
source: `
migration "state" "test" {
skip_plan = true
actions = [
"mv null_resource.foo null_resource.foo2",
]
}
`,
want: &tfmigrate.MigrationConfig{
Type: "state",
Name: "test",
Migrator: &tfmigrate.StateMigratorConfig{
Dir: "",
Actions: []string{
"mv null_resource.foo null_resource.foo2",
},
SkipPlan: true,
},
},
ok: true,
},
{
desc: "state with to_skip_plan",
source: `
migration "state" "test" {
to_skip_plan = true
actions = [
"mv null_resource.foo null_resource.foo2",
]
}
`,
want: &tfmigrate.MigrationConfig{
Type: "state",
Name: "test",
Migrator: &tfmigrate.StateMigratorConfig{
Dir: "",
Actions: []string{
"mv null_resource.foo null_resource.foo2",
},
ToSkipPlan: true,
},
},
ok: true,
},
{
desc: "multi state with from_dir and to_dir",
source: `
Expand Down
12 changes: 11 additions & 1 deletion tfmigrate/state_migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ type StateMigratorConfig struct {
Force bool `hcl:"force,optional"`
// SkipPlan controls whether or not to run and analyze Terraform plan.
SkipPlan bool `hcl:"skip_plan,optional"`
// ToSkipPlan controls whether or not to run and analyze Terraform plan.
// Note: This variable exists only to maintain compatibility with an old bug
// but is deprecated. It will be removed in a future version.
ToSkipPlan bool `hcl:"to_skip_plan,optional"`
// Workspace is the state workspace which the migration works with.
Workspace string `hcl:"workspace,optional"`
}
Expand Down Expand Up @@ -64,7 +68,13 @@ func (c *StateMigratorConfig) NewMigrator(o *MigratorOption) (Migrator, error) {
c.Workspace = "default"
}

return NewStateMigrator(dir, c.Workspace, actions, o, c.Force, c.SkipPlan), nil
// This logic remains to maintain compatibility with an old bug but will be
// removed in a future version.
skipPlan := c.SkipPlan || c.ToSkipPlan
if c.ToSkipPlan {
log.Printf("[WARN] [migrator@%s] `to_skip_plan` is deprecated. Use `skip_plan` instead.", dir)
}
return NewStateMigrator(dir, c.Workspace, actions, o, c.Force, skipPlan), nil
}

// StateMigrator implements the Migrator interface.
Expand Down
15 changes: 12 additions & 3 deletions tfmigrate/state_migrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,24 @@ func TestStateMigratorConfigNewMigrator(t *testing.T) {
Dir: "dir1",
Actions: []string{
"mv null_resource.foo null_resource.foo2",
"mv null_resource.bar null_resource.bar2",
"rm time_static.baz",
"import time_static.qux 2006-01-02T15:04:05Z",
},
SkipPlan: true,
},
o: nil,
ok: true,
},
{
desc: "with to_skip_plan true",
config: &StateMigratorConfig{
Dir: "dir1",
Actions: []string{
"mv null_resource.foo null_resource.foo2",
},
ToSkipPlan: true,
},
o: nil,
ok: true,
},
}

for _, tc := range cases {
Expand Down

0 comments on commit 8c3c283

Please sign in to comment.