Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore and deprecate the to_skip_plan in a single-state migration #195

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading