Hello,
I’m currently migrating terraform-lxd-provider to Terraform framework (from SDKv2).
We are using terraform-plugin-testing
for testing. Within tests we retrieve a Client from globally defined Provider, and use it to verify whether Terraform actually made changes to the system and whether those changes are reflected correctly.
Previously, accessing the provider was easy, since it was defined as a global variable.
var testAccProviders map[string]*schema.Provider
var testAccProvider *schema.Provider
func init() {
testAccProvider = Provider()
testAccProviders = map[string]*schema.Provider{
"lxd": testAccProvider,
}
...
}
func TestAccInstance(t *testing.T) {
resource.Test(t, resource.TestCase{
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Check: resource.ComposeTestCheckFunc(
testAccInstanceRunning(t, "lxd_instance.inst1"),
),
},
},
...
})
}
func testAccInstanceRunning(t *testing.T, instName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
...
client, err := testAccProvider.Meta().(*lxdProvider).GetInstanceServer("")
if err != nil {
return err
}
// Use retrieved client to verify resources are created and
// properly configured by Terraform.
...
}
}
However, I cannot figure out how can I access the provider within a test when using ProtoV6ProviderFactories
(if possible at all)?
Thanks