@@ -917,24 +917,6 @@ func RunMigrationV2Command(t *testing.T, v4Config string, tmpDir string, sourceV
917917 t .Fatalf ("tf-migrate binary not found at %s. Please set TF_MIGRATE_BINARY_PATH or ensure the binary is built." , migratorPath )
918918 }
919919
920- // Find state file in tmpDir
921- entries , err := os .ReadDir (tmpDir )
922- var stateDir string
923- if err != nil {
924- t .Logf ("Failed to read test directory: %v" , err )
925- } else {
926- for _ , entry := range entries {
927- if entry .IsDir () {
928- inner_entries , _ := os .ReadDir (filepath .Join (tmpDir , entry .Name ()))
929- for _ , inner_entry := range inner_entries {
930- if inner_entry .Name () == "terraform.tfstate" {
931- stateDir = filepath .Join (tmpDir , entry .Name ())
932- }
933- }
934- }
935- }
936- }
937-
938920 // Build the command
939921 args := []string {
940922 "migrate" ,
@@ -943,11 +925,6 @@ func RunMigrationV2Command(t *testing.T, v4Config string, tmpDir string, sourceV
943925 "--target-version" , targetVersion ,
944926 }
945927
946- // Add state file argument if found
947- if stateDir != "" {
948- args = append (args , "--state-file" , filepath .Join (stateDir , "terraform.tfstate" ))
949- }
950-
951928 // Add debug logging if TF_LOG is set
952929 if strings .ToLower (os .Getenv ("TF_LOG" )) == "debug" {
953930 args = append (args , "--log-level" , "debug" )
@@ -1099,6 +1076,15 @@ func MigrationV2TestStepWithPlan(t *testing.T, v4Config string, tmpDir string, e
10991076 return []resource.TestStep {migrationStep , planStep , validationStep }
11001077}
11011078
1079+ // InferMigrationVersions determines source and target versions from test provider version.
1080+ // Returns ("v4", "v5") for v4.x versions, ("v5", "v5") for v5.x versions.
1081+ func InferMigrationVersions (testVersion string ) (source , target string ) {
1082+ if strings .HasPrefix (testVersion , "5." ) {
1083+ return "v5" , "v5"
1084+ }
1085+ return "v4" , "v5"
1086+ }
1087+
11021088// MigrationTestStep creates a test step that runs the migration command and validates with v5 provider
11031089func MigrationTestStep (t * testing.T , v4Config string , tmpDir string , exactVersion string , stateChecks []statecheck.StateCheck ) resource.TestStep {
11041090 // Choose the appropriate plan check based on the version
@@ -1166,8 +1152,14 @@ func MigrationV2TestStep(t *testing.T, v4Config string, tmpDir string, exactVers
11661152 return resource.TestStep {
11671153 PreConfig : func () {
11681154 WriteOutConfig (t , v4Config , tmpDir )
1169- debugLogf (t , "Running migration command for version: %s (%s -> %s)" , exactVersion , sourceVersion , targetVersion )
1170- RunMigrationV2Command (t , v4Config , tmpDir , sourceVersion , targetVersion )
1155+ // Only run migration command if source version is v4
1156+ // v5→v5 "migrations" only test StateUpgrader idempotency, no config changes needed
1157+ if sourceVersion == "v4" {
1158+ debugLogf (t , "Running migration command for version: %s (%s -> %s)" , exactVersion , sourceVersion , targetVersion )
1159+ RunMigrationV2Command (t , v4Config , tmpDir , sourceVersion , targetVersion )
1160+ } else {
1161+ debugLogf (t , "Skipping migration command for version: %s (%s -> %s) - testing StateUpgrader only" , exactVersion , sourceVersion , targetVersion )
1162+ }
11711163 },
11721164 ProtoV6ProviderFactories : TestAccProtoV6ProviderFactories ,
11731165 ConfigDirectory : config .StaticDirectory (tmpDir ),
0 commit comments