Skip to content

Commit e96524f

Browse files
committed
Error on use of ImportStatePersist with plannable import
1 parent c1d25d3 commit e96524f

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

helper/resource/importstate/import_block_as_first_step_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,10 @@ func Test_ImportBlock_AsFirstStep(t *testing.T) {
3838
ImportStateId: "examplecloud_container.test",
3939
ImportState: true,
4040
ImportStateKind: r.ImportBlockWithID,
41-
// ImportStateVerify: true,
4241
Config: `resource "examplecloud_container" "test" {
4342
name = "somevalue"
4443
location = "westeurope"
4544
}`,
46-
ImportStatePersist: true,
4745
ImportPlanChecks: r.ImportPlanChecks{
4846
PreApply: []plancheck.PlanCheck{
4947
plancheck.ExpectResourceAction("examplecloud_container.test", plancheck.ResourceActionNoop),

helper/resource/testing_new_import_state.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,19 @@ func testStepNewImportState(ctx context.Context, t testing.T, helper *plugintest
3030

3131
// step.ImportStateKind implicitly defaults to the zero-value (ImportCommandWithID) for backward compatibility
3232
kind := step.ImportStateKind
33+
importStatePersist := step.ImportStatePersist
34+
3335
if kind.plannable() {
3436
// Instead of calling [t.Fatal], return an error. This package's unit tests can use [TestStep.ExpectError] to match on the error message.
3537
// An alternative, [plugintest.TestExpectTFatal], does not have access to logged error messages, so it is open to false positives on this
3638
// complex code path.
3739
if err := requirePlannableImport(t, *helper.TerraformVersion()); err != nil {
3840
return err
3941
}
42+
43+
if importStatePersist {
44+
return fmt.Errorf("ImportStatePersist is not supported with plannable import blocks")
45+
}
4046
}
4147

4248
configRequest := teststep.PrepareConfigurationRequest{
@@ -145,7 +151,7 @@ func testStepNewImportState(ctx context.Context, t testing.T, helper *plugintest
145151
var importWd *plugintest.WorkingDir
146152

147153
// Use the same working directory to persist the state from import
148-
if step.ImportStatePersist {
154+
if importStatePersist {
149155
importWd = wd
150156
} else {
151157
importWd = helper.RequireNewWorkingDir(ctx, t, "")
@@ -157,7 +163,7 @@ func testStepNewImportState(ctx context.Context, t testing.T, helper *plugintest
157163
t.Fatalf("Error setting test config: %s", err)
158164
}
159165

160-
if !step.ImportStatePersist {
166+
if !importStatePersist {
161167
err = runProviderCommand(ctx, t, func() error {
162168
logging.HelperResourceDebug(ctx, "Run terraform init")
163169
return importWd.Init(ctx)

0 commit comments

Comments
 (0)