|
7 | 7 | "strings" |
8 | 8 |
|
9 | 9 | "github.com/davecgh/go-spew/spew" |
10 | | - testing "github.com/mitchellh/go-testing-interface" |
| 10 | + "github.com/mitchellh/go-testing-interface" |
11 | 11 |
|
12 | 12 | "github.com/hashicorp/terraform-plugin-sdk/v2/internal/logging" |
13 | 13 | "github.com/hashicorp/terraform-plugin-sdk/v2/internal/plugintest" |
@@ -86,20 +86,31 @@ func testStepNewImportState(ctx context.Context, t testing.T, helper *plugintest |
86 | 86 | t.Fatal("Cannot import state with no specified config") |
87 | 87 | } |
88 | 88 | } |
89 | | - importWd := helper.RequireNewWorkingDir(ctx, t) |
90 | | - defer importWd.Close() |
| 89 | + |
| 90 | + var importWd *plugintest.WorkingDir |
| 91 | + |
| 92 | + // Use the same working directory to persist the state from import |
| 93 | + if step.ImportStatePersist { |
| 94 | + importWd = wd |
| 95 | + } else { |
| 96 | + importWd = helper.RequireNewWorkingDir(ctx, t) |
| 97 | + defer importWd.Close() |
| 98 | + } |
| 99 | + |
91 | 100 | err = importWd.SetConfig(ctx, step.Config) |
92 | 101 | if err != nil { |
93 | 102 | t.Fatalf("Error setting test config: %s", err) |
94 | 103 | } |
95 | 104 |
|
96 | 105 | logging.HelperResourceDebug(ctx, "Running Terraform CLI init and import") |
97 | 106 |
|
98 | | - err = runProviderCommand(ctx, t, func() error { |
99 | | - return importWd.Init(ctx) |
100 | | - }, importWd, providers) |
101 | | - if err != nil { |
102 | | - t.Fatalf("Error running init: %s", err) |
| 107 | + if !step.ImportStatePersist { |
| 108 | + err = runProviderCommand(ctx, t, func() error { |
| 109 | + return importWd.Init(ctx) |
| 110 | + }, importWd, providers) |
| 111 | + if err != nil { |
| 112 | + t.Fatalf("Error running init: %s", err) |
| 113 | + } |
103 | 114 | } |
104 | 115 |
|
105 | 116 | err = runProviderCommand(ctx, t, func() error { |
|
0 commit comments