tffwdocs

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2026 License: MPL-2.0 Imports: 17 Imported by: 0

README

terraform-plugin-framework-docs

A Go library for generating comprehensive documentation for Terraform providers built with terraform-plugin-framework.

Features

  • Complete resource coverage, including:
    • Provider
    • Managed Resource
    • Data Source
    • Ephemeral Resource
    • List Resource
    • Action
    • Function
  • Enhanced documentation with descriptions extracted from CustomType, PlanModifiers, and Validators
  • Flexible example integration — accepts strings that can be derived from acceptance test configurations, ensuring examples remain up-to-date
  • Subcategory support for organizing generated documents (addresses #156)
  • Custom template support — extensible template system for tailoring documentation output to specific needs
  • fwdtypes package — provides descriptive type wrappers for terraform-plugin-framework basetypes, enabling documentation for ObjectType members (addresses #333)

Comparison with tfplugindocs

The official terraform-plugin-docs tool relies on Terraform CLI's terraform providers schema -json output, which limits the documentation content it can generate. See this discussion for details.

This library takes a different approach by reading schemas directly from the provider codebase. To use it, create a separate Go package alongside the provider's internal package. See the example for implementation details.

Example

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionRenderOption

type ActionRenderOption = metadata.ActionRenderOption

type ActionWithRenderOption

type ActionWithRenderOption interface {
	action.Action
	RenderOption() ActionRenderOption
}

type DataSourceRenderOption

type DataSourceRenderOption = metadata.DataSourceRenderOption

type DataSourceWithRenderOption

type DataSourceWithRenderOption interface {
	datasource.DataSource
	RenderOption() DataSourceRenderOption
}

type EphemeralResourceRenderOption

type EphemeralResourceRenderOption = metadata.EphemeralRenderOption

type EphemeralResourceWithRenderOption

type EphemeralResourceWithRenderOption interface {
	ephemeral.EphemeralResource
	RenderOption() EphemeralResourceRenderOption
}

type Example

type Example = metadata.Example

type FunctionRenderOption

type FunctionRenderOption = metadata.FunctionRenderOption

type FunctionWithRenderOption

type FunctionWithRenderOption interface {
	function.Function
	RenderOption() FunctionRenderOption
}

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

func NewGenerator

func NewGenerator(ctx context.Context, p provider.Provider) (*Generator, error)

Create a Generator by analyzing the schema of the provider and all the registered resources to the provider.

func (Generator) Lint added in v0.2.0

func (gen Generator) Lint(opt *LintOptions) error

Lint traverses the provider and provider resource type's schema to identify any field without a description specified.

func (Generator) RenderAction

func (gen Generator) RenderAction(ctx context.Context, w io.Writer, actionType string, option *ActionRenderOption) error

RenderAction renders the action document. If option is specified, it will override the ActionWithRenderOption.RenderOption() if is implemented.

func (Generator) RenderDataSource

func (gen Generator) RenderDataSource(ctx context.Context, w io.Writer, dataSourceType string, option *DataSourceRenderOption) error

RenderDataSource renders the data source document. If option is specified, it will override the DataSourceWithRenderOption.RenderOption() if is implemented.

func (Generator) RenderEphemeralResource

func (gen Generator) RenderEphemeralResource(ctx context.Context, w io.Writer, ephemeralResourceType string, option *EphemeralResourceRenderOption) error

RenderEphemeralResource renders the ephemeral resource document. If option is specified, it will override the EphemeralResourceWithRenderOption.RenderOption() if is implemented.

func (Generator) RenderFunction

func (gen Generator) RenderFunction(ctx context.Context, w io.Writer, functionName string, option *FunctionRenderOption) error

RenderFunction renders the function document. If option is specified, it will override the FunctionWithRenderOption.RenderOption() if is implemented.

func (Generator) RenderListResource

func (gen Generator) RenderListResource(ctx context.Context, w io.Writer, listResourceType string, option *ListResourceRenderOption) error

RenderListResource renders the list resource document. If option is specified, it will override the ListResourceWithRenderOption.RenderOption() if is implemented.

func (Generator) RenderProvider

func (gen Generator) RenderProvider(ctx context.Context, w io.Writer, option *ProviderRenderOption) error

RenderProvider renders the provider document. If option is specified, it will override the ProviderWithRenderOption.RenderOption() if is implemented.

func (Generator) RenderResource

func (gen Generator) RenderResource(ctx context.Context, w io.Writer, resourceType string, option *ResourceRenderOption) error

RenderResource renders the resource document. If option is specified, it will override the ResourceWithRenderOption.RenderOption() if is implemented.

func (Generator) WriteAll

func (gen Generator) WriteAll(ctx context.Context, docDir string, opts *RenderOptions) error

WriteAll generates the documents for the provider and all registered resources, actions, functions, etc. and write to the specified document directory, which should be existing.

Example
package main

import (
	"context"
	"log"

	tffwdocs "github.com/magodo/terraform-plugin-framework-docs"
	"github.com/magodo/terraform-plugin-framework-docs/internal/metadata"
	"github.com/magodo/terraform-plugin-framework-docs/internal/testprovider"
)

func main() {
	ctx := context.Background()
	gen, err := tffwdocs.NewGenerator(ctx, &testprovider.ExampleCloudProvider{})
	if err != nil {
		log.Fatal(err)
	}
	if err := gen.Lint(nil); err != nil {
		log.Fatal(err)
	}
	if err := gen.WriteAll(ctx, "./internal/testprovider/docs", &tffwdocs.RenderOptions{
		Provider: &metadata.ProviderRenderOption{
			Examples: []tffwdocs.Example{
				{
					Header:      "Basic",
					Description: "The basic configuration.",
					HCL: `
provider "examplecloud" {
	name = "foo"
}
	`,
				},
				{
					Header:      "Complete",
					Description: "The complete configuration.",
					HCL: `
provider "examplecloud" {
	name = "foo"
	address = "bar"
	age = 123
	role = "Software Engineer"
}
	`,
				},
			},
		},
		Resources: map[string]tffwdocs.ResourceRenderOption{
			"examplecloud_resource": metadata.ResourceRenderOption{
				Subcategory: "abc",
				Examples: []tffwdocs.Example{
					{
						Header:      "Basic",
						Description: "The basic configuration.",
						HCL: `
resource "examplecloud_resource" "example" {
	name = "foo"
}
`,
					},
					{
						Header:      "Complete",
						Description: "The complete configuration.",
						HCL: `
resource "examplecloud_resource" "example" {
	name = "foo"
	address = "bar"
	age = 123
	role = "Software Engineer"
}
`,
					},
				},
				ImportId: &tffwdocs.ImportId{
					Format:    "<parent_id>/<id>[/<version>]",
					ExampleId: "123/456",
					ExampleBlk: `
import {
	to = examplecloud_resource.example
	id = "123/456"
}
`,
				},
				IdentityExamples: []tffwdocs.Example{
					{
						Header:      "Without Version",
						Description: "Import without version.",
						HCL: `
import {
	to = examplecloud_resource.example
	identity = {
		parent_id = "123"
		id = "456"
	}
}
`,
					},
					{
						Header:      "With Version",
						Description: "Import with version.",
						HCL: `
import {
	to = examplecloud_resource.example
	identity = {
		parent_id = "123"
		id = "456"
		version = "v2"
	}
}
`,
					},
				},
			},
		},
	}); err != nil {
		log.Fatal(err)
	}
}

type ImportId

type ImportId = metadata.ImportId

type LintOptions added in v0.2.0

type LintOptions struct {
	SkipProvider           bool
	SkipResources          map[string]bool
	SkipDataSources        map[string]bool
	SkipEphemeralResources map[string]bool
	SkipListResources      map[string]bool
	SkipActions            map[string]bool
	SkipFunctions          map[string]bool
}

type ListResourceRenderOption

type ListResourceRenderOption = metadata.ListRenderOption

type ListResourceWithRenderOption

type ListResourceWithRenderOption interface {
	list.ListResource
	RenderOption() ListResourceRenderOption
}

type ProviderRenderOption

type ProviderRenderOption = metadata.ProviderRenderOption

type ProviderWithRenderOption

type ProviderWithRenderOption interface {
	provider.Provider
	RenderOption() ProviderRenderOption
}

type RenderOptions

type RenderOptions struct {
	Provider           *ProviderRenderOption
	Resources          map[string]ResourceRenderOption
	DataSources        map[string]DataSourceRenderOption
	EphemeralResources map[string]EphemeralResourceRenderOption
	ListResources      map[string]ListResourceRenderOption
	Actions            map[string]ActionRenderOption
	Functions          map[string]FunctionRenderOption
}

type ResourceRenderOption

type ResourceRenderOption = metadata.ResourceRenderOption

type ResourceWithRenderOption

type ResourceWithRenderOption interface {
	resource.Resource
	RenderOption() ResourceRenderOption
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL