hashicorp / terraform-plugin-testing

Module for testing Terraform providers
Mozilla Public License 2.0
45 stars 11 forks source link

Setup/Teardown hook on `resource.Test()` and `resource.TestStep` level #82

Open timofurrer opened 2 years ago

timofurrer commented 2 years ago

SDK version

v2.17.0

Use-cases

In the Terraform Provider GitLab we have to setup testing resources (e.g. a project the resource under test resides in) in each test case.

At the moment we are creating them in each test case just before calling resource.Test() or resource.ParallelTest(). However, that's a problem because when using resource.ParallelTest() this setup code isn't parallelized.

We have a similar scenario for resource.TestStep where sometimes we have to introduce errors or other things and currently misuse PreConfig, but don't have a way for a proper teardown (t.Cleanup() doesn't help if a subsequent TestStep required that to happen)

Attempted Solutions

Misusing PreConfig for TestStep and defining setup / teardown outside of resource.Test() / resource.ParallelTest() with be above mentioned limitations.

Proposal

I don't have a concrete proposal, but envision some sort of Setup and Teardown field registering some function on resource.Test() / resource.ParallelTest() and resource.TestStep() level.

The biggest challenge I see is how to pass data from Setup to Teardown - this data would be necessary to cleanup properly. Another one is how to pass data from Setup() - from resource.Test() and resource.TestStep() to e.g. the Config or Check ?

Questions

bflad commented 1 year ago

Hi folks 👋

With the introduction of the terraform-plugin-testing module (migration guide), we are transferring feature requests relating to the helper/resource "testing framework" in the terraform-plugin-sdk repository over to the new terraform-plugin-testing repository.

Thanks again for this feature request.