You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The use of SingleNestedBlock resource schemas for resources implemented using Terraform Plugin Framework is problematic.
NestedBlocks have no Required/Optional/Computed flags – they are effectively always there, so an “Optional” SingleNestedBlock doesn’t work as expected if the block isn’t present in configuration (e.g. Required attributes).
The pattern with Terraform Plugin SDK v2 is to use ListNestedBlock with SizeAtMost(1) and then a missing block is equivalent to an empty list. In fact SingleNestedBlocks are not available in Terraform Plugin SDK v2.
Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
Volunteering to Work on This Issue
If you are interested in working on this issue, please leave a comment.
If this would be your first contribution, please review the contribution guide.
ewbankkit
changed the title
Disallow use of SingleNestedBlock in resource schemas
Disallow use of SingleNestedBlock in resource schemas
Feb 14, 2024
The use of
SingleNestedBlock
resource schemas for resources implemented using Terraform Plugin Framework is problematic.NestedBlocks have no Required/Optional/Computed flags – they are effectively always there, so an “Optional”
SingleNestedBlock
doesn’t work as expected if the block isn’t present in configuration (e.g. Required attributes).The pattern with Terraform Plugin SDK v2 is to use ListNestedBlock with SizeAtMost(1) and then a missing block is equivalent to an empty list. In fact
SingleNestedBlock
s are not available in Terraform Plugin SDK v2.Relates #34664.
There are only 3 uses in the current codebase:
Add a semgrep rule to prevent additional occurrences and migrate the existing occurrences to
ListNestedBlock
s.The text was updated successfully, but these errors were encountered: