Skip to content

Commit c0fd026

Browse files
committed
Fail ImportStateVerify if no new resources are imported
1 parent bd29ab0 commit c0fd026

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-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/importstate/import_block_with_id_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ func TestTest_TestStep_ImportBlockId_ImportStateVerifyIgnore_Real_Example(t *tes
200200
I also need to omit the `password` in the import config, otherwise the value in the config is used when importing the
201201
with an import block and the test ends up passing regardless of whether `ImportStateVerifyIgnore` has been specified or not
202202
*/
203+
204+
// Skipped while we decide whether ImportBlockWithID will perform an apply; else, it will not produce a new state,
205+
// and there is no new state for ImportStateVerify to do anything meaningful with.
206+
t.Skip()
207+
203208
t.Parallel()
204209

205210
r.UnitTest(t, r.TestCase{
@@ -301,6 +306,10 @@ func TestTest_TestStep_ImportBlockId_ImportStateVerifyIgnore_Real_Example(t *tes
301306
}
302307

303308
func TestTest_TestStep_ImportBlockId_ImportStateVerifyIgnore(t *testing.T) {
309+
// Skipped while we decide whether ImportBlockWithID will perform an apply; else, it will not produce a new state,
310+
// and there is no new state for ImportStateVerify to do anything meaningful with.
311+
t.Skip()
312+
304313
t.Parallel()
305314

306315
r.UnitTest(t, r.TestCase{

helper/resource/importstate/import_command_with_id_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"github.com/hashicorp/terraform-plugin-testing/tfversion"
2121
)
2222

23-
func Test_TestStep_ImportStateCheck_SkipDataSourceState(t *testing.T) {
23+
func Test_ImportCommmandWithId_SkipDataSourceState(t *testing.T) {
2424
t.Parallel()
2525

2626
r.UnitTest(t, r.TestCase{
@@ -123,7 +123,7 @@ func Test_TestStep_ImportStateCheck_SkipDataSourceState(t *testing.T) {
123123
})
124124
}
125125

126-
func Test_TestStep_ImportStateVerify(t *testing.T) {
126+
func Test_ImportCommandWithId_ImportStateVerify(t *testing.T) {
127127
t.Parallel()
128128

129129
r.UnitTest(t, r.TestCase{

helper/resource/testing_new_import_state.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ func testStepNewImportState(ctx context.Context, t testing.T, helper *plugintest
254254
identifierAttribute = "id"
255255
}
256256

257+
if len(newResources) == 0 {
258+
return fmt.Errorf("ImportStateVerify: no new resources imported")
259+
}
260+
257261
for _, r := range newResources {
258262
rIdentifier, ok := r.Primary.Attributes[identifierAttribute]
259263

0 commit comments

Comments
 (0)