Consistent Error Handling for Setting Terraform State #17117
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.
Community Note
Description
Resources that need to write to the Terraform State use the Terraform Plugin SDK
(helper/schema.ResourceData).Set()
receiver method. e.g.Technically speaking, implementing the error checking for every attribute should be done to notify operators about the potential loss of drift detection and cover missing acceptance testing data scenarios. However for pragmatic purposes such as code readability and that most acceptance testing generally covers these types well, the error checking has been considered as optional for "simple" data types such as
TypeString
(string
), instead suggesting it for "complex" types such asTypeList
/TypeMap
/TypeSet
. The choice of whether or not to apply the error checking can be confusing for developers and the implementations can vary.This issue to discuss if the handling should be standardized across all resources and attributes. If so, coming up with the desired code implementation, then the tactical details of documenting it, applying it to all existing code, and enforcing it via static analysis.
Given that our desire is to move to Terraform Plugin SDK v2 compatible resources over the coming months, it is likely best to focus on that implementation. We may want to consider our own simple diagnostic wrapper to always be used for simplicity and consistency. e.g.
However, it would be better if the Terraform Plugin SDK hosted the implementation details here, since it should be generic across Terraform Providers. I will follow up with those maintainers. It may be better to consider a different receiver method (e.g.
d.SetWithDiag()
), but that team is better suited to make that determination.References
The text was updated successfully, but these errors were encountered: