Terratest as acceptance test framework in provider development
Hi Team, We are in a process of developing terraform provider for one of our internal products and plan to publish the provider to terraform registry. We are using terraform's latest plugin framework and we do not find any acceptance framework available in it. So we are planning to use terratest as our acceptance test framework. Could you please let us know if there are any restrictions in using terratest as acceptance framework for the providers to be published in terraform registry? Also it would be very helpful if we could get references of any providers published in terraform registry using terratest as the acceptance framework. Thanks in advance, Sooraj --- <ins datetime="2022-08-18T15:14:02Z"> <p><a href="https://support.gruntwork.io/hc/requests/109145">Tracked in ticket #109145</a></p> </ins>
As far as I know, none of the providers rely on Terratest for provider testing, as Terratest is more optimized for Terraform module testing. We don't offer first class support for provider acceptance testing, so you might find it rather limiting if you try to go down this route. That is, Terratest doesn't offer setup and teardown functions that spawn an in-dev provider - it relies on `terraform init` to pull down the providers, so you would need to write the test code that builds and installs the provider in a way that `terraform` can find it, which is an awkward setup process for provider testing. As an alternative... > We are using terraform's latest plugin framework and we do not find any acceptance framework available in it It's not well documented, but `terraform-plugin-sdk` does indeed have a framework for writing acceptance tests (the [helper/resource](https://github.com/hashicorp/terraform-plugin-sdk/tree/main/helper/resource) package). Here is a [simple example](https://github.com/hashicorp/terraform-provider-aws/blob/main/internal/service/sts/caller_identity_data_source_test.go) in the AWS Provider that uses that framework. I would recommend using the official framework for writing the provider tests, as the community is more used to using those framework for testing, and it maintains consistency [with the official documentation on testing providers](https://www.terraform.io/plugin/sdkv2/testing). Using the official SDK as a framework, you could however consider using Terratest for the other aspects of testing, like validating the deployed resource within the provider acceptance testing framework (if you find it useful).