Terraform Plugin Framework: Can terraform-plugin-docs automatically include defaults, ForceNew, or sensitive?

Summary

The Terraform Plugin Framework provides a robust way to develop Terraform providers, and terraform-plugin-docs is a tool used to generate documentation for these providers. However, users may notice that certain schema metadata, such as default values, ForceNew attributes, and sensitive information, are not included in the generated documentation by default. This omission can lead to incomplete documentation and requires additional effort to maintain accuracy.

Root Cause

The root cause of this issue is that terraform-plugin-docs does not automatically include all schema metadata in the generated documentation. The tool focuses on basic attribute information, leaving out other crucial details like:

  • Default values for attributes
  • ForceNew attributes that cause resource replacement
  • Sensitive information that should be handled with care

Why This Happens in Real Systems

This happens in real systems because the primary purpose of terraform-plugin-docs is to generate basic documentation for Terraform providers. The tool is designed to work with the Terraform Plugin Framework, which defines the structure and behavior of providers. However, the framework does not mandate the inclusion of all schema metadata in the documentation. As a result, terraform-plugin-docs follows this design and omits certain details.

Real-World Impact

The real-world impact of this omission is significant, as it can lead to:

  • Incomplete documentation that does not fully describe the behavior of resources
  • Increased maintenance efforts to keep documentation up-to-date and accurate
  • Potential security issues if sensitive information is not properly handled
  • Confusion among users who rely on the documentation to understand how to use the provider

Example or Code

resource "example_resource" {
  attribute = "value"
}

In this example, the attribute may have a default value, be marked as ForceNew, or contain sensitive information. However, this information is not included in the documentation generated by terraform-plugin-docs.

How Senior Engineers Fix It

Senior engineers fix this issue by:

  • Manually adding the missing information to the attribute descriptions
  • Using terraform-plugin-docs configuration options or extensions to include the desired metadata
  • Implementing custom documentation generation scripts to include all necessary schema metadata
  • Following best practices for documenting Terraform providers, such as explicitly describing attribute behavior

Why Juniors Miss It

Juniors may miss this issue because they:

  • Are not familiar with the Terraform Plugin Framework and its limitations
  • Do not fully understand the importance of including all schema metadata in the documentation
  • Rely too heavily on automated tools like terraform-plugin-docs without reviewing the generated output
  • Lack experience with best practices for documenting Terraform providers and the potential consequences of incomplete documentation

Leave a Comment