Acceptance testing sdk -> framework upgrade issue

Hi,

I’m currently testing upgrading from sdkv2 to framework (protocol6), I have been going through the recent upgrade docs which were merged into the framework project and taking a look at some of the examples, namely here: terraform-provider-random/resource_id_test.go at 21bf43373d6cfccdb5f818df5374d79637a88d02 · hashicorp/terraform-provider-random · GitHub

This led me to create the following acceptance test:

var testAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
	"pingfederate": providerserver.NewProtocol6WithError(New("test")),
}
...
resource.ParallelTest(t, resource.TestCase{
		Steps: []resource.TestStep{
			{
				ExternalProviders: map[string]resource.ExternalProvider{
					"pingfederate": {
						VersionConstraint: "0.0.24",
						Source:            "iwarapter/pingfederate",
					},
				},
				Config: testAccPingFederateAuthenticationPolicyContractResourceConfig("email"),
				Check: resource.ComposeTestCheckFunc(
					testAccCheckPingFederateAuthenticationPolicyContractResourceExists(resourceName),
					resource.TestCheckResourceAttr(resourceName, "name", "acc_test_one"),
					resource.TestCheckResourceAttr(resourceName, "extended_attributes.0", "email"),
					resource.TestCheckResourceAttr(resourceName, "extended_attributes.1", "foo"),
				),
			},
			{
				ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
				PlanOnly:                 true,
				Config:                   testAccPingFederateAuthenticationPolicyContractResourceConfig("email"),
				Check: resource.ComposeTestCheckFunc(
					testAccCheckPingFederateAuthenticationPolicyContractResourceExists(resourceName),
					resource.TestCheckResourceAttr(resourceName, "name", "acc_test_one"),
					resource.TestCheckResourceAttr(resourceName, "extended_attributes.0", "email"),
					resource.TestCheckResourceAttr(resourceName, "extended_attributes.1", "foo"),
				),
			},
		},
	})

However this fails with:

Step 1/2 error: Error running pre-apply refresh: 
Error: Inconsistent dependency lock file
  
The following dependency selections recorded in the lock file are
inconsistent with the current configuration:
  - provider registry.terraform.io/hashicorp/pingfederate: required by this configuration but no version is selected
  
To update the locked dependency selections to match a changed configuration,
run:
  terraform init -upgrade
github.com/hashicorp/terraform-plugin-framework v0.11.1
github.com/hashicorp/terraform-plugin-go v0.14.0
github.com/hashicorp/terraform-plugin-log v0.7.0
github.com/hashicorp/terraform-plugin-mux v0.7.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.21.0

Is there something obvious I am missing from this?

After a dive through the sdk testing harness internals I was able to get this to work:

resource.ParallelTest(t, resource.TestCase{
		Steps: []resource.TestStep{
			{
				ExternalProviders: map[string]resource.ExternalProvider{
					"pingfederate": {
						VersionConstraint: "0.0.24",
						Source:            "iwarapter/pingfederate",
					},
				},
				Config: `
terraform {
  required_providers {
    pingfederate = {
      source = "iwarapter/pingfederate"
      version = "0.0.24"
    }
  }
}

provider "pingfederate" {}

resource "pingfederate_authentication_policy_contract" "demo" {
  name                = "acc_test_one"
  extended_attributes = ["foo", "email"]
}`,
				Check: resource.ComposeTestCheckFunc(
					testAccCheckPingFederateAuthenticationPolicyContractResourceExists(resourceName),
					resource.TestCheckResourceAttr(resourceName, "name", "acc_test_one"),
					resource.TestCheckResourceAttr(resourceName, "extended_attributes.0", "email"),
					resource.TestCheckResourceAttr(resourceName, "extended_attributes.1", "foo"),
				),
			},
			{
				ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
				PlanOnly:                 true,
				Config: `resource "pingfederate_authentication_policy_contract" "demo" {
  name                = "acc_test_one"
  extended_attributes = ["foo", "email"]
}`,
				Check: resource.ComposeTestCheckFunc(
					testAccCheckPingFederateAuthenticationPolicyContractResourceExists(resourceName),
					resource.TestCheckResourceAttr(resourceName, "name", "acc_test_one"),
					resource.TestCheckResourceAttr(resourceName, "extended_attributes.0", "email"),
					resource.TestCheckResourceAttr(resourceName, "extended_attributes.1", "foo"),
				),
			},
		},
	})

I suspect there is a bug somewhere in the sdk testing harness relating to non hashicorp providers.

Hi @iwarapter :wave: Thanks for raising this and sorry you ran into trouble here.

This appears to be an actual bug report / feature request for the terraform-plugin-sdk project. Could you raise a GitHub issue there? Issues · hashicorp/terraform-plugin-sdk · GitHub

The testing framework will use the ExternalProviders setup to create a temporary Terraform configuration with the terraform and provider configuration blocks for calling terraform init, however it does not add that same configuration to each TestStep configuration when necessary. Terraform CLI defaults the provider hostname to registry.terraform.io and the provider namespace to hashicorp when there is no terraform configuration block to tell it otherwise. If you try to run the resource-only configuration via a “normal” terraform init or terraform plan command, there should be a similar lookup for registry.terraform.io/hashicorp/pingfederate.

Thanks!

1 Like

Hi again :wave: This may now be resolved in terraform-plugin-sdk version 2.23.0, which was released yesterday. If you are still having problems, please raise a GitHub issue and we can take a fresh look. :+1:

1 Like

This works for me now. Thanks for the quick fix.