Custom Provider ("Error initializing context"): Testing framework cannot find provider, but CLI can

Hi there,

I’m writing a custom provider and I’m encountering an issue where I put the terraform provider in what should have been the correct location but it is not being detected when I run my acceptance testing.

=== RUN   TestAccLatestVersion
2021/01/25 19:53:28 [DEBUG] Test: Executing step 0
2021/01/25 19:53:28 [TRACE] ModuleInstaller: installing child modules for /var/folders/md/_yh_32m51xqbn88pq0n1dllm000s60/T/tf-test303365878 into /var/folders/md/_yh_32m51xqbn88pq0n1dllm000s60/T/tf-test303365878/.modules
2021/01/25 19:53:28 [TRACE] modsdir: writing modules manifest to /var/folders/md/_yh_32m51xqbn88pq0n1dllm000s60/T/tf-test303365878/.modules/modules.json
2021/01/25 19:53:28 [TRACE] terraform.NewContext: starting
2021/01/25 19:53:28 [TRACE] terraform.NewContext: resolving provider version selections
2021/01/25 19:53:28 [WARN] Skipping destroy test since there is no state.
--- FAIL: TestAccLatestVersion (0.00s)
    testing.go:684: Step 0 error: Error initializing context: 2 problems:
        - Could not satisfy plugin requirements: 
        Plugin reinitialization required. Please run "terraform init".
        Plugins are external binaries that Terraform uses to access and manipulate
        resources. The configuration provided requires plugins which can't be located,
        don't satisfy the version constraints, or are otherwise incompatible.
        Terraform automatically discovers provider requirements from your
        configuration, including providers used in child modules. To see the
        requirements and constraints from each module, run "terraform providers".
        - provider "crt" is not available

The location is:

molee-mn1:terraform-provider-crt_trunk molee$ ls -la  ~/.terraform.d/plugins/darwin_amd64/total 58776
drwxr-xr-x  3 molee  staff        96 Jan 25 17:41 .
drwxr-xr-x  4 molee  staff       128 Jan 25 19:52 ..
-rwxr-xr-x  1 molee  staff  30090612 Jan 25 17:41 terraform-provider-crt_v0.0.1

using terraform directly on a terraform file I created (for the data source)

molee-mn1:basic molee$ terraform init

Initializing the backend...

Initializing provider plugins...

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
molee-mn1:basic molee$ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

data.crt_latest_product_version.test: Refreshing state...


No changes. Infrastructure is up-to-date.

This means that Terraform did not detect any differences between your
configuration and real physical resources that exist. As a result, no
actions need to be performed.
molee-mn1:basic molee$ 

I’m curious what’s the expected location of my binary for acceptance testing exactly.

I’m using terraform binary 0.12.30 for this test

//"TF_ACC_TERRAFORM_PATH": "/export/content/lid/terraform1230/terraform"
$ /export/content/lid/terraform1230/terraform --version
Terraform v0.12.30

and my sdk is

    "terraform-plugin-sdk": "com.github.hashicorp:terraform-plugin-sdk:1.15.0",

I figured out the issue.

When I specified the below, the provider was being used.

resource.Test(t, resource.TestCase{
		PreCheck:  func() { testAccPreCheck(t) },
		Providers: testProviders,

The naming of the key was the name of the provider. I was not aware of that.

testProvider = Provider()
	testProviders = map[string]terraform.ResourceProvider{
		"crt": testProvider,