Remove testAccCheck...Exists ("CheckExists") Functions for Resources with Import Support #16435
Labels
proposal
Proposes new design or functionality.
provider
Pertains to the provider itself, rather than any interaction with AWS.
stale
Old or inactive issues managed by automation, if no further action taken these will get closed.
technical-debt
Addresses areas of the codebase that need refactoring or redesign.
tests
PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Community Note
Description
Terraform resource acceptance testing has historically included a
TestCheckFunc
to verify via a followup read API call that the component created by the resource was actually created in the API. For simplicity, we will refer to this as the "CheckExists" function. An example:For resources that support import, the act of importing the resource (
TestStep
containingImportState
) simulates the same functionality since it requires a similar read API call to succeed. Most resource testing should also includeImportStateVerify
to ensure the created state of the resource wholly matches the imported state.Given that testing import performs the same testing as these CheckExists functions, we can remove them.
Caveat: Some legacy resource acceptance testing relies on the "CheckExists" function returning an SDK object for later introspection. An example:
Even in this case, the Terraform resource state should be canonical and verified via
ImportStateVerify
, rather than custom logic. The acceptance testing framework automatically calls a followup plan after apply to check for state differences as well.One consideration here is whether we need to strongly enforce import testing, but that can likely be treated as a separate concern.
References
The text was updated successfully, but these errors were encountered: