Hi There, In my test cases, I found provider.Resources(ctx context.Context) has been called many times. Because my plugin relies on an internal state, I wonder if there is a better way to keep only one instance of resource type in the testing code.
The provider acceptance testing logic (either in github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource or github.com/hashicorp/terraform-plugin-testing/helper/resource) executes a decent number of Terraform CLI commands per TestStep. Each of those Terraform CLI commands may interrogate the provider’s implementation via the GetProviderSchema RPC multiple times (mainly due to implementation details within Terraform CLI) each of which will trigger a call to a terraform-plugin-framework based provider Resources method. This is expected behavior, which matches production Terraform CLI usage, since the testing logic is calling actual Terraform CLI commands.
I think before anyone here may be able to comment on:
I wonder if there is a better way to keep only one instance of resource type in the testing code.
I wonder if we might need to better understand:
my plugin relies on an internal state
Can you describe more about what you mean here or what you are trying to solve? Thanks.
Hi @bflad, Thanks for the response. I think that it’s fair enough to have multiple calls of Resourecs method. I want to keep the application always using one instance of the resource. Otherwise, I can’t capture the state between test cases.
The example code I have shown is a workable solution.