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.
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 factSingleNestedBlock
s are not available in Terraform Plugin SDK v2.Relates https://github.com/hashicorp/terraform-provider-aws/issues/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.