Cannot get acceptance test running with local provider

I’m trying to get acceptance tests running with a local provider. I have a directory structure toplevel, and then within that have toplevel/redfish. I set both TF_ACC and TF_ACC_TERRAFORM_PATH. I have an acceptance test in toplevel/redfish however, when I try to run it I get:

=== RUN   TestAccRedfishPower_basic
    resource_redfish_power_test.go:12: Step 1/1 error: Error running pre-apply refresh: 
        Error: Could not load plugin
        
        
        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, run "terraform providers".
        
        Failed to instantiate provider "registry.terraform.io/grantcurell/redfish" to obtain
        schema: unknown provider "registry.terraform.io/grantcurell/redfish"
        
        
    testing_new.go:56: Error retrieving state, there may be dangling resources: 
        Error: Could not load plugin
        
        
        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, run "terraform providers".
        
        Failed to instantiate provider "registry.terraform.io/grantcurell/redfish" to obtain
        schema: unknown provider "registry.terraform.io/grantcurell/redfish"
        
        
--- FAIL: TestAccRedfishPower_basic (0.54s)

FAIL

For whatever reason it can’t find the provider. However, if I move to directory toplevel and run go test redfish\resource_redfish_power_test.go -v - that is to say I run the go test command in the root directory but point to the test it stops complaining about not finding the provider but then gives me:

go test redfish\resource_redfish_power_test.go -v
# command-line-arguments [command-line-arguments.test]
redfish\resource_redfish_power_test.go:13:17: undefined: testAccProviders
FAIL    command-line-arguments [build failed]
FAIL

Running Terraform normally from the command line is no problem and it has no problems finding the provider and running normally so it would appear this problem is specific to the test framework.

1 Like

Hello @grantcurell , did you find any solution for this? My problem was that name of datasource must start with name of provider. So for example if you have provider with name “exampleprovider” name of datasource must be “exampleprovider_exampledatasource”