Local Provider Testing, terraform import not finding locally build provider

Hi,
I am trying to write a provider withe the new plugin framework. I managed a working provider so far and tried to added some tests for my ressources. Create, Update, Read and Delete Tests for the resource are working fine, but the import step fails with:

w74_6v40000gp/T/plugintest2055618642 test_step_number=2
2023-08-23T14:36:55.900+0200 [TRACE] sdk.helper_resource: Calling Terraform CLI init command: test_name=TestTxtRecordResource test_terraform_path=/usr/local/bin/terraform test_working_directory=/var/folders/6k/02l_d_5j5hv_wz1bww74_6v40000gp/T/plugintest2055618642 test_step_number=2
2023-08-23T14:36:55.955+0200 [TRACE] sdk.helper_resource: Called Terraform CLI init command: test_name=TestTxtRecordResource test_terraform_path=/usr/local/bin/terraform test_working_directory=/var/folders/6k/02l_d_5j5hv_wz1bww74_6v40000gp/T/plugintest2055618642 test_step_number=2
2023-08-23T14:36:55.955+0200 [WARN] sdk.helper_resource: Error running Terraform CLI command: test_step_number=2
error=
| exit status 1
|
| Error: Failed to query available provider packages
|
| Could not retrieve the list of available versions for provider
| hashicorp.com/edu/bam: no available releases match the given constraints

I am not sure what is going wrong here. hashicorp.com/edu/bam is the name of the local provider for testing purposes. It is redirected in terraform.rc to my local go path. It seems to work for the other terraform commands but not for the import. Can someone give me a hint where to debug?

Regards,
Marco

Hi @marcohelmerich :wave: Thank you for raising this topic and welcome to HashiCorp Discuss! Sorry you are running into trouble here, but let’s see if we can get you going. Are you able to share the Go code you are using for this test (redacting anything if necessary)?

My initial guess would be that if the first test step is working correctly, but the second step is not, then you might have your test setup with:

resource.TestCase{
  // ...
  Steps: []resource.TestStep{
    {
      ProtoV6ProviderFactories: /* ... */,
      Config: "...",
      // ...
    },
    {
      ImportState: true,
      // ... no ProtoV6ProviderFactories
    },
  },
}

If that is the case, moving the provider declaration up to the TestCase level (or duplicating it across TestSteps) would hopefully resolve the issue. If that is not the case, then hopefully we can get this sorted by getting some additional information.

Hi @bflad thanks for the quick response.

First I did it like this (similar to the hashicups tutorial):

resource.Test(t, resource.TestCase{
		ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
		Steps: []resource.TestStep{
			// Create and Read testing
			{
				Config: providerConfig + `
								 resource "bam_txt_record" "test-txt-record" {
								   fqdn           = "testrecord.com"
					                            ...
								 }
                 `,
				Check: resource.ComposeAggregateTestCheckFunc(
					// Verify attributes
					...
				),
			},
				ResourceName:      "bam_txt_record.test-txt-record",
				ImportState:       true,
				ImportStateVerify: true,
			
				ImportStateVerifyIgnore: []string{"last_updated"},
			 },
			// Update and Read testing
			{
				Config: providerConfig + `
                resource "bam_txt_record" "test-txt-record" {
                  fqdn           = "testrecord.com"
                 ...
                `,
				Check: resource.ComposeAggregateTestCheckFunc(
					// Verify attributes
					...
				),
			},
			// Delete testing automatically occurs in TestCase
		},
	})

If I comment out the import Step and keep Step 1 and Step 3 both are working.

then I tried this, but with no luck so far.

                                Config: providerConfig
                                ResourceName:      "bam_txt_record.test-txt-record",
				ImportState:       true,
				ImportStateVerify: true,
			
				ImportStateVerifyIgnore: []string{"last_updated"}

Thank you, @marcohelmerich – makes sense what you are doing and the additional context about setting this up similar to the tutorials is very helpful. I’m not immediately sure what is going wrong in this situation and need to step away for a few hours, but maybe someone else can chime in during the meantime.

Apologies for the delayed response. While this issue is in the terraform-plugin-sdk repository, which uses an older copy of the terraform-plugin-testing code, I believe its relevant here: `dev_overrides` in `.terraformrc` appears to break acceptance tests (`make testacc`/TF_ACC=1) · Issue #1171 · hashicorp/terraform-plugin-sdk · GitHub

HI @bflad. Sorry for the delay, I was on vacation and had no credentials available for login in the discuss forum. Your hint to the issue seems to match my case exactly. Will try to test this asap and update the thread here.

@bflad It is working now. Maybe an addition to the terraform provider plugin framework documentation would be a good idea. In the tutorial dev_overrides are explained, but the caveat with acceptance tests should be explained as well.