@@ -917,25 +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- // TODO:: Needs to be commented so the state upgraders run
921- // Find state file in tmpDir
922- //entries, err := os.ReadDir(tmpDir)
923- //var stateDir string
924- //if err != nil {
925- // t.Logf("Failed to read test directory: %v", err)
926- //} else {
927- //for _, entry := range entries {
928- // if entry.IsDir() {
929- // inner_entries, _ := os.ReadDir(filepath.Join(tmpDir, entry.Name()))
930- // for _, inner_entry := range inner_entries {
931- // if inner_entry.Name() == "terraform.tfstate" {
932- // stateDir = filepath.Join(tmpDir, entry.Name())
933- // }
934- // }
935- // }
936- //}
937- //}
938-
939920 // Build the command
940921 args := []string {
941922 "migrate" ,
@@ -944,11 +925,6 @@ func RunMigrationV2Command(t *testing.T, v4Config string, tmpDir string, sourceV
944925 "--target-version" , targetVersion ,
945926 }
946927
947- // Add state file argument if found
948- //if stateDir != "" {
949- // args = append(args, "--state-file", filepath.Join(stateDir, "terraform.tfstate"))
950- //}
951-
952928 // Add debug logging if TF_LOG is set
953929 if strings .ToLower (os .Getenv ("TF_LOG" )) == "debug" {
954930 args = append (args , "--log-level" , "debug" )
@@ -1022,8 +998,8 @@ func RunMigrationCommand(t *testing.T, v4Config string, tmpDir string) {
1022998 cmd = exec .Command ("go" , "run" , "-C" , migratePath , "." ,
1023999 "-config" , tmpDir ,
10241000 "-state" , filepath .Join (stateDir , "terraform.tfstate" ),
1025- "-grit=false" , // Disable Grit transformations
1026- "-transformer=true" , // Enable YAML transformations
1001+ "-grit=false" , // Disable Grit transformations
1002+ "-transformer=true" , // Enable YAML transformations
10271003 "-transformer-dir" , transformerDir ) // Use local YAML configs
10281004 cmd .Dir = tmpDir
10291005 // Capture output for debugging
@@ -1071,6 +1047,16 @@ func MigrationTestStepWithPlan(t *testing.T, v4Config string, tmpDir string, exa
10711047 return []resource.TestStep {migrationStep , planStep , validationStep }
10721048}
10731049
1050+ // DetermineSourceTargetVersion determines the source and target versions for migration tests
1051+ // based on the test version being used. For v4 versions, returns "v4" -> "v5" migration.
1052+ // For v5 versions, returns "v5" -> "v5" which tests StateUpgrader idempotency only.
1053+ func DetermineSourceTargetVersion (version string ) (source , target string ) {
1054+ if strings .HasPrefix (version , "5." ) {
1055+ return "v5" , "v5"
1056+ }
1057+ return "v4" , "v5"
1058+ }
1059+
10741060// MigrationV2TestStepWithPlan creates multiple test steps for v2 migration with plan processing
10751061// This is similar to MigrationTestStepWithPlan but uses the v2 migration command with explicit version parameters
10761062func MigrationV2TestStepWithPlan (t * testing.T , v4Config string , tmpDir string , exactVersion string , sourceVersion string , targetVersion string , stateChecks []statecheck.StateCheck ) []resource.TestStep {
@@ -1167,8 +1153,14 @@ func MigrationV2TestStep(t *testing.T, v4Config string, tmpDir string, exactVers
11671153 return resource.TestStep {
11681154 PreConfig : func () {
11691155 WriteOutConfig (t , v4Config , tmpDir )
1170- debugLogf (t , "Running migration command for version: %s (%s -> %s)" , exactVersion , sourceVersion , targetVersion )
1171- RunMigrationV2Command (t , v4Config , tmpDir , sourceVersion , targetVersion )
1156+ // Only run migration command if source version is v4
1157+ // v5→v5 "migrations" only test StateUpgrader idempotency, no config changes needed
1158+ if sourceVersion == "v4" {
1159+ debugLogf (t , "Running migration command for version: %s (%s -> %s)" , exactVersion , sourceVersion , targetVersion )
1160+ RunMigrationV2Command (t , v4Config , tmpDir , sourceVersion , targetVersion )
1161+ } else {
1162+ debugLogf (t , "Skipping migration command for version: %s (%s -> %s) - testing StateUpgrader only" , exactVersion , sourceVersion , targetVersion )
1163+ }
11721164 },
11731165 ProtoV6ProviderFactories : TestAccProtoV6ProviderFactories ,
11741166 ConfigDirectory : config .StaticDirectory (tmpDir ),
0 commit comments