Provider Configuration empty during Acceptance Testing

Hi,

I’m having trouble injecting a provider configuration during Acceptance Tests.

If I run my provider (terraform plan) with this configuration:

provider "dummy" {
   some_block = {
      some_key = "some_value"
   }
}

… it works fine. Under the function supplied to the provider ConfigureFunc, I can use d.Get("some_block").

But, if I configure the Provider in provider_test.go like so:

func init() {
	testAccProvider = Provider().(*schema.Provider)

	raw := map[string]interface{}{
		"some_block": map[string]interface{}{
			"some_key": "some_value",
		},
	}

	err := testAccProvider.Configure(terraform.NewResourceConfigRaw(raw))
	if err != nil {
		fmt.Printf("provider config error: %s", err)
	}

	testAccProviders = map[string]terraform.ResourceProvider{
		"dummy": testAccProvider,
	}
}

Then I cannot get the configuration from the function supplied to ConfigureFunc.

I didn’t want to fill this message with all the code, so if there is more detail I can provide you, please let me know.

Hello, I am also writing an acceptance test. I have an error when I assign the provider to a variable, testAccProvider. “Invalid type assertion…non-interface type *schema.Provider on left”. Is your variable testAccProvider declared outside like this?var testAccProvider *schema.Provider
Thank you!

Can you show the code that is prompting this error? Can you show the instantiation of testAccProvider and what is being assigned to it?

Hello! I am using the same code in the example from terraform website: https://www.terraform.io/docs/extend/testing/acceptance-tests/testcase.html

I only replace the “Provider()” to “***Provider()” where *** is my company’s name because we have this function named “***Provider()” in the provider.go file.

The error is prompted by Goland: “Invalid type assertion: ***Provider().(*schema.Provider) (non-interface type *schema.Provider on left)”

Here is my code:

var testAccProviders map[string]terraform.ResourceProvider
var testAccProvider *schema.Provider

func init() {
testAccProvider = ***Provider().(*schema.Provider)
testAccProviders = map[string]terraform.ResourceProvider{
“example”: testAccProvider,
}
}
Thanks!

Remove the .(*schema.Provider) and you’ll be all set.

Also, sorry, I just now realised we’re on another topic. In the future, creating your own topic is better.