Skip to content

Add support for generating documentation for actions #505

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20250811-174112.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'generate: Add support for unlinked actions'
time: 2025-08-11T17:41:12.858383-04:00
custom:
Issue: "505"
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20250811-174141.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'migrate: Add support for unlinked actions'
time: 2025-08-11T17:41:41.553344-04:00
custom:
Issue: "505"
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20250811-174155.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'validate: Add support for unlinked actions'
time: 2025-08-11T17:41:55.966547-04:00
custom:
Issue: "505"
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ When you run `tfplugindocs`, by default from the root directory of a provider co
* Generate data source template files, if missing
* Generate function template files, if missing (Requires Terraform v1.8.0+)
* Generate ephemeral resource template files, if missing (Requires Terraform v1.10.0+)
* Generate action template files, if missing (Requires Terraform v1.14.0+)
* Copy all non-template files to the output website directory

> [!NOTE]
Expand Down Expand Up @@ -207,10 +208,12 @@ For templates:
|--------------------------------------------------------------------|-----------------------------------------------|
| `templates/` | Root of templated docs |
| `templates/index.md[.tmpl]` | Docs index page (or template) |
| `templates/actions.md[.tmpl]` | Generic action page (or template) |
| `templates/actions/<action type name>.md[.tmpl]` | Action page (or template) |
| `templates/data-sources.md[.tmpl]` | Generic data source page (or template) |
| `templates/data-sources/<data source name>.md[.tmpl]` | Data source page (or template) |
| `templates/ephemeral-resources.md[.tmpl]` | Generic ephemeral resource page (or template) |
| `templates/ephemeral-resources/<ephemeral resource name>.md[.tmpl]` | Ephemeral resource page (or template) |
| `templates/ephemeral-resources/<ephemeral resource name>.md[.tmpl]`| Ephemeral resource page (or template) |
| `templates/functions.md[.tmpl]` | Generic function page (or template) |
| `templates/functions/<function name>.md[.tmpl]` | Function page (or template) |
| `templates/resources.md[.tmpl]` | Generic resource page (or template) |
Expand All @@ -227,6 +230,7 @@ For examples:
|---------------------------------------------------------------------------|--------------------------------------------|
| `examples/` | Root of examples |
| `examples/provider/provider.tf` | Provider example config |
| `examples/actions/<action_type>/action.tf` | Action example config |
| `examples/data-sources/<data source name>/data-source.tf` | Data source example config |
| `examples/ephemeral-resources/<ephemeral resource>/ephemeral-resource.tf` | Ephemeral resource example config |
| `examples/functions/<function name>/function.tf` | Function example config |
Expand All @@ -249,6 +253,7 @@ Legacy website directory structure:
| `website/` | Root of website docs |
| `website/docs/guides` | Root of guides subdirectory |
| `website/docs/index.html.markdown` | Docs index page |
| `website/docs/actions/<action type name>.html.markdown` | Action page |
| `website/docs/d/<data source name>.html.markdown` | Data source page |
| `website/docs/ephemeral-resources/<ephemeral resource name>.html.markdown` | Ephemeral resource page |
| `website/docs/functons/<function name>.html.markdown` | Functions page |
Expand All @@ -261,6 +266,7 @@ Docs website directory structure:
| `docs/` | Root of website docs |
| `docs/guides` | Root of guides subdirectory |
| `docs/index.html.markdown` | Docs index page |
| `docs/actions/<action type name>.html.markdown` | Action page |
| `docs/data-sources/<data source name>.html.markdown` | Data source page |
| `docs/ephemeral-resources/<ephemeral resource name>.html.markdown` | Ephemeral resource page |
| `docs/functions/<function name>.html.markdown` | Function page |
Expand Down Expand Up @@ -331,6 +337,20 @@ using the following data fields and functions:
| `.HasVariadic` | bool | Does this function have a variadic argument? |
| `.FunctionVariadicArgumentMarkdown` | string | a Markdown formatted Function variadic argument definition |

##### Action Fields

| Field | Type | Description |
|-------------------------|--------|-------------------------------------------------------------------------------------------|
| `.Name` | string | Name of the action (ex. `examplecloud_do_thing`) |
| `.Type` | string | `Action` |
| `.Description` | string | Action description |
| `.HasExample` | bool | Is there an example file? |
| `.ExampleFile` | string | Path to the file with the terraform configuration example |
| `.ProviderName` | string | Canonical provider name (ex. `terraform-provider-random`) |
| `.ProviderShortName` | string | Short version of the rendered provider name (ex. `random`) |
| `.RenderedProviderName` | string | Value provided via argument `--rendered-provider-name`, otherwise same as `.ProviderName` |
| `.SchemaMarkdown` | string | a Markdown formatted Action Schema definition |

#### Template Functions

| Function | Description |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ generating missing data source content
data-source "scaffolding_example" fallback template exists, creating template
generating missing function content
generating missing ephemeral resource content
generating missing action content
generating missing provider content
provider "terraform-provider-scaffolding" template exists, skipping
rendering static website
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ generating missing data source content
data-source "scaffolding_example" template exists, skipping
generating missing function content
generating missing ephemeral resource content
generating missing action content
generating missing provider content
provider "terraform-provider-scaffolding" template exists, skipping
rendering static website
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ generating missing data source content
generating new template for data-source "scaffolding_example"
generating missing function content
generating missing ephemeral resource content
generating missing action content
generating missing provider content
generating new template for "terraform-provider-scaffolding"
rendering static website
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ generating missing data source content
data-source "null_data_source" fallback template exists, creating template
generating missing function content
generating missing ephemeral resource content
generating missing action content
generating missing provider content
provider "terraform-provider-null" template exists, skipping
rendering static website
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ generating missing data source content
generating missing function content
generating new template for function "scaffolding"
generating missing ephemeral resource content
generating missing action content
generating missing provider content
generating new template for "terraform-provider-scaffolding"
rendering static website
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cmpenv docs/data-sources/example.md expected-datasource.md
cmpenv docs/resources/example.md expected-resource.md
cmpenv docs/functions/example.md expected-function.md
cmpenv docs/ephemeral-resources/example.md expected-ephemeral-resource.md
cmpenv docs/actions/unlinked_example.md expected-unlinked-action.md


-- expected-output.txt --
Expand All @@ -27,16 +28,70 @@ generating missing function content
function "example" fallback template exists, creating template
generating missing ephemeral resource content
ephemeral resource "scaffolding_example" fallback template exists, creating template
generating missing action content
action "scaffolding_unlinked_example" fallback template exists, creating template
generating missing provider content
provider "terraform-provider-scaffolding" template exists, skipping
rendering static website
cleaning rendered website dir
rendering templated website to static markdown
rendering "actions/unlinked_example.md.tmpl"
rendering "data-sources/example.md.tmpl"
rendering "ephemeral-resources/example.md.tmpl"
rendering "functions/example.md.tmpl"
rendering "index.md.tmpl"
rendering "resources/example.md.tmpl"
-- expected-unlinked-action.md --
# Data Fields

Name: scaffolding_unlinked_example
Type: Action
Description: Example unlinked action
HasExample: true
ExampleFile: $WORK/examples/actions/scaffolding_unlinked_example/action.tf
ProviderName: terraform-provider-scaffolding
ProviderShortName: scaffolding
RenderedProviderName: terraform-provider-scaffolding
SchemaMarkdown: <!-- action schema generated by tfplugindocs -->
## Schema

### Required

- `required_attr` (String) Example required attribute

### Optional

- `optional_attr` (String) Example optional attribute



# Functions

lower: action
plainmarkdown: Action
prefixlines: Prefix: Action
split: [scaffolding unlinked example]
title: Action
trimspace: Action
upper: ACTION

# Conditionals and File Functions

printf tffile:
## Example Usage

{{tffile "$WORK/examples/actions/scaffolding_unlinked_example/action.tf"}}

tffile:
## Example Usage

```terraform
action "scaffolding_unlinked_example" "example" {
config {
required_attr = "some-value"
}
}
```
-- expected-datasource.md --
# Data Fields

Expand Down Expand Up @@ -310,6 +365,44 @@ resource "scaffolding_example" "example" {
configurable_attribute = "some-value"
}
```
-- templates/actions.md.tmpl --
# Data Fields

Name: {{.Name}}
Type: {{.Type}}
Description: {{.Description}}
HasExample: {{.HasExample}}
ExampleFile: {{.ExampleFile}}
ProviderName: {{.ProviderName}}
ProviderShortName: {{.ProviderShortName}}
RenderedProviderName: {{.RenderedProviderName}}
SchemaMarkdown: {{.SchemaMarkdown}}

# Functions

lower: {{ .Type | lower }}
plainmarkdown: {{ .Type | plainmarkdown }}
prefixlines: {{ .Type | prefixlines "Prefix: " }}
split: {{ split .Name "_" }}
title: {{ .Type | title }}
trimspace: {{ .Type | trimspace }}
upper: {{ .Type | upper }}

# Conditionals and File Functions

printf tffile:
{{ if .HasExample -}}
## Example Usage

{{ printf "{{tffile %q}}" .ExampleFile }}
{{- end }}

tffile:
{{ if .HasExample -}}
## Example Usage

{{tffile .ExampleFile }}
{{- end }}
-- templates/data-sources.md.tmpl --
# Data Fields

Expand Down Expand Up @@ -572,6 +665,12 @@ The document generation tool looks for files in the following locations by defau
* **provider/provider.tf** example file for the provider index page
* **data-sources/`full data source name`/data-source.tf** example file for the named data source page
* **resources/`full resource name`/resource.tf** example file for the named data source page
-- examples/actions/scaffolding_unlinked_example/action.tf --
action "scaffolding_unlinked_example" "example" {
config {
required_attr = "some-value"
}
}
-- examples/data-sources/scaffolding_example/data-source.tf --
data "scaffolding_example" "example" {
configurable_attribute = "some-value"
Expand Down Expand Up @@ -623,6 +722,30 @@ resource "scaffolding_example" "example" {
"description_kind": "markdown"
}
},
"action_schemas": {
"scaffolding_unlinked_example": {
"version": 0,
"block": {
"attributes": {
"required_attr": {
"type": "string",
"description": "Example required attribute",
"description_kind": "plain",
"required": true
},
"optional_attr": {
"type": "string",
"description": "Example optional attribute",
"description_kind": "plain",
"optional": true
}
},
"description": "Example unlinked action",
"description_kind": "plain"
},
"unlinked": {}
}
},
"resource_schemas": {
"scaffolding_example": {
"version": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ cmp templates/ephemeral-resources/example.markdown docs/ephemeral-resources/exam
cmp templates/ephemeral-resources/example.html.markdown docs/ephemeral-resources/example.html.markdown
cmp templates/ephemeral-resources/example.html.md docs/ephemeral-resources/example.html.md

cmp templates/actions/unlinked_example.md docs/actions/unlinked_example.md
cmp templates/actions/unlinked_example.markdown docs/actions/unlinked_example.markdown
cmp templates/actions/unlinked_example.html.markdown docs/actions/unlinked_example.html.markdown
cmp templates/actions/unlinked_example.html.md docs/actions/unlinked_example.html.md

cmp templates/index.md docs/index.md
cmp templates/index.markdown docs/index.markdown
cmp templates/index.html.markdown docs/index.html.markdown
Expand All @@ -45,11 +50,17 @@ generating missing function content
function "example" static file exists, skipping
generating missing ephemeral resource content
ephemeral resource "scaffolding_example" static file exists, skipping
generating missing action content
action "scaffolding_unlinked_example" static file exists, skipping
generating missing provider content
provider "terraform-provider-scaffolding" static file exists, skipping
rendering static website
cleaning rendered website dir
rendering templated website to static markdown
copying non-template file: "actions/unlinked_example.html.markdown"
copying non-template file: "actions/unlinked_example.html.md"
copying non-template file: "actions/unlinked_example.markdown"
copying non-template file: "actions/unlinked_example.md"
copying non-template file: "d/example.html.markdown"
copying non-template file: "d/example.html.md"
copying non-template file: "d/example.markdown"
Expand All @@ -70,6 +81,26 @@ copying non-template file: "r/example.html.markdown"
copying non-template file: "r/example.html.md"
copying non-template file: "r/example.markdown"
copying non-template file: "r/example.md"
-- templates/actions/unlinked_example.md --
# Data Fields

Name: {{.Name}}
Type: {{.Type}}
-- templates/actions/unlinked_example.markdown --
# Data Fields

Name: {{.Name}}
Type: {{.Type}}
-- templates/actions/unlinked_example.html.markdown --
# Data Fields

Name: {{.Name}}
Type: {{.Type}}
-- templates/actions/unlinked_example.html.md --
# Data Fields

Name: {{.Name}}
Type: {{.Type}}
-- templates/r/example.md --
# Data Fields

Expand Down Expand Up @@ -180,6 +211,12 @@ The document generation tool looks for files in the following locations by defau
* **provider/provider.tf** example file for the provider index page
* **data-sources/`full data source name`/data-source.tf** example file for the named data source page
* **resources/`full resource name`/resource.tf** example file for the named data source page
-- examples/actions/scaffolding_unlinked_example/action.tf --
action "scaffolding_unlinked_example" "example" {
config {
required_attr = "some-value"
}
}
-- examples/data-sources/scaffolding_example/data-source.tf --
data "scaffolding_example" "example" {
configurable_attribute = "some-value"
Expand Down Expand Up @@ -227,6 +264,30 @@ terraform import scaffolding_example.example "id-123"
"description_kind": "markdown"
}
},
"action_schemas": {
"scaffolding_unlinked_example": {
"version": 0,
"block": {
"attributes": {
"required_attr": {
"type": "string",
"description": "Example required attribute",
"description_kind": "plain",
"required": true
},
"optional_attr": {
"type": "string",
"description": "Example optional attribute",
"description_kind": "plain",
"optional": true
}
},
"description": "Example unlinked action",
"description_kind": "plain"
},
"unlinked": {}
}
},
"resource_schemas": {
"scaffolding_example": {
"version": 0,
Expand Down
Loading
Loading