Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow use of SingleNestedBlock in resource schemas #35813

Open
ewbankkit opened this issue Feb 14, 2024 · 1 comment
Open

Disallow use of SingleNestedBlock in resource schemas #35813

ewbankkit opened this issue Feb 14, 2024 · 1 comment

Comments

@ewbankkit
Copy link
Contributor

ewbankkit commented 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 SingleNestedBlocks are not available in Terraform Plugin SDK v2.

Relates #34664.

There are only 3 uses in the current codebase:

% grep SingleNestedBlock internal/service/*/*.go
internal/service/bedrock/model_invocation_logging_configuration.go:			"logging_config": schema.SingleNestedBlock{
internal/service/bedrock/model_invocation_logging_configuration.go:					"cloudwatch_config": schema.SingleNestedBlock{
internal/service/bedrock/model_invocation_logging_configuration.go:							"large_data_delivery_s3_config": schema.SingleNestedBlock{
internal/service/bedrock/model_invocation_logging_configuration.go:					"s3_config": schema.SingleNestedBlock{
internal/service/opensearchserverless/security_config.go:			"saml_options": schema.SingleNestedBlock{
internal/service/opensearchserverless/security_config_data_source.go:			"saml_options": schema.SingleNestedBlock{
internal/service/verifiedpermissions/schema.go:			"definition": schema.SingleNestedBlock{

Add a semgrep rule to prevent additional occurrences and migrate the existing occurrences to ListNestedBlocks.

Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • 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 ewbankkit changed the title Disallow use of SingleNestedBlock in resource schemas Disallow use of SingleNestedBlock in resource schemas Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant