Skip to content

1.13.* : importstate doesn't use configuration from previous state with ConfigDirectory #516

@jeremmfr

Description

@jeremmfr

terraform-plugin-testing version

github.com/hashicorp/terraform-plugin-testing v1.13.1

The issue is not present in v1.12.0

Relevant provider source code

To reproduce the bug, I tested with https://github.com/hashicorp/terraform-provider-hashicups/tree/main/12-final after upgrading this module to v1.13.1, terraform-plugin-framework to v1.15.0 and terraform-plugin-go to v0.27.0

func TestAccOrderResource(t *testing.T) {
	resource.Test(t, resource.TestCase{
		ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
		Steps: []resource.TestStep{
			// Create and Read testing
			{
				ConfigDirectory: config.TestStepDirectory(),
			},
			// ImportState testing
			{
				ResourceName:      "hashicups_order.test",
				ImportState:       true,
				ImportStateVerify: true,
				// The last_updated attribute does not exist in the HashiCups
				// API, therefore there is no value for it during import.
				ImportStateVerifyIgnore: []string{"last_updated"},
			},
		},
	})
}

Terraform Configuration Files

12-final/internal/provider/testdata/TestAccOrderResource/1/main.tf

resource "hashicups_order" "test" {
  items = [
    {
      coffee = {
        id = 1
      }
      quantity = 2
    },
  ]
}

Expected Behavior

On the second step, the import doesn't catch an error

Actual Behavior

On the second step, the module catch this error when using ConfigDirectory: config.TestStepDirectory() on the previous step before import :

=== RUN   TestAccOrderResource
    order_resource_test.go:11: Step 2/2 error running import: exit status 1
        Error: resource address "hashicups_order.test" does not exist in the configuration.
        
        Before importing this resource, please create its configuration in the root module. For example:
        
        resource "hashicups_order" "test" {
          # (resource arguments)
        }
        
--- FAIL: TestAccOrderResource (0.64s)

Steps to Reproduce

Launch TestAccOrderResource test

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions