Plugin Framework: Blocks don't have required field

I am migrating the resources from sdk v2 to the new plugin framework. In the plugin framework there is no way to specify a block as required while in sdk v2 I was able to do that. This causes all the blocks to be shown as optional when the documentation for the resource/data source is generated using the tf-plugin-docs tool. Is there a way to overcome this? We have certain blocks which need to be marked as required. Can’t change to nested attributes as it has to be backwards compatible.

Hi there @prakkarp! :wave:

As you noted, there is no longer a built-in field to mark blocks as Required in the plugin-framework. This affects the terraform-plugin-doc tool as it defaults fields to optional if it can’t determine if it’s Required.

Currently, there are 3 validators that will help you achieve the same functionality as a required block that can be used with ListNestedBlock , SetNestedBlock , or SingleNestedBlock respectively.

  • listvalidator.IsRequiredListNestedBlock
  • objectvalidator.IsRequiredSetNestedBlock
  • setvalidator.IsRequiredSingleNestedBlock

As for the documentation, currently you’ll have to workaround the documentation generation tool to avoid it being shown as optional by using a manual template.

You can run an initial generation to get your fields/descriptions, then insert them into a template. Here is an example from our cloudinit provider:

Available fields for use in your templates are documented here


Hi Agustin, thanks for the response. I will make the validations as suggested and also try out creating the documentation template.

1 Like