Terraform Provider Factories

Hello,

I’m creating a new Provider, but i have some doubts in provider Factories.

I’m following terraform-provider-scaffolding so in provider_test.go i have the following:

var providerFactories = map[string]func() (*schema.Provider, error){
	"acdcn": func() (*schema.Provider, error) {
		return New("dev")(), nil
	},
}

Then in resource test file i would like access to Provider to be able to use my api client to delete the created resource. I’m trying the following:

provider, err := providerFactories["acdcn"]()

apiClient := provider.Meta().(*client.Client)

But the provider.Meta() is always nil. How i can access to my api client configured in provider?

The Test works well, the resource is created, but i’m unable to destroy the resource inside function configured in CheckDestroy

Regards,
Fábio Santos

Hi,

I notice that i misunderstood the meaning of CheckDestroy key. The test automatically runs the delete resource operation. So that solves my problem. But i maintain the question, how can i access to my api client?

Thanks

Response In Github

1 Like