terraform-plugin-sdk
terraform-plugin-sdk copied to clipboard
Add ability in a TestCase to manually inject beginning state data
Use-cases
For some tests, its hard to get the TF state and upstream API in the proper state to reproduce observed issues (ie reading when deleting upstream without first creating then deleting through SDK, or some issues with provider upgrades or things that may not be possible in the API but possible in the UI, etc.). It may be useful (or in some cases just more expedient) to explicitly set the starting state for a resource in a TestCase prior to executing it.
Interested in that.
One of such cases is testing if ReadFunc in resource behaves properly when the resource does not exist anymore (basically to test if it conforms with recommended approach).
If it was possible to create and inject a state I could:
- Create a state with
ID(and additional mandatory fields if needed) - Using a TestStep trigger a
refreshorapply - See if it behaves as it has (removes the object from state)
I was able to achieve similar functionality with data sources currently by doing the following:
- Looping over all data sources defined in
func Provider() terraform.ResourceProvider - For each of defined data sources generating a
Configtemplate - Run a subtest for each data source (with mandatory fields filled in) and test that an error occurs when a data source object is not found (by simply inserting invalid name)
This way the test should cover data sources added in future.