Skip to content

feat(generate): Support multiple configuration example files in default templates #511

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 1 commit into
base: main
Choose a base branch
from

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Aug 19, 2025

Related Issue

Fixes #508

Description

This change updates the generate command to search for multiple configuration example files using a wildcard and render all found files with the default templates (e.g. resource*.tf instead of just resource.tf). Compatibility with the existing singular HasExample and ExampleFile fields for templating is preserved, while new plural HasExamples and ExampleFiles fields were added into the template data. The testing for this feature was added by duplicating the existing "no templates" txtar, then adding second configuration example files:

4c4
< # Successful run of tfplugindocs on a Framework provider with examples but no templates or pre-exiting docs.
---
> # Successful run of tfplugindocs on a Framework provider with multiple configuration examples but no templates or pre-exiting docs.
57c57
<   configurable_attribute = "some-value"
---
>   configurable_attribute = "some-value1"
60a61,66
> ```terraform
> data "scaffolding_example" "example" {
>   configurable_attribute = "some-value2"
> }
> ```
>
91a98,103
> ```terraform
> output "test" {
>   value = provider::scaffolding::example("testvalue3", "testvalue4")
> }
> ```
>
122a135,140
> }
> ```
>
> ```terraform
> output "test" {
>   value = provider::scaffolding::no-variadic("testvalue2")
153c171
<   # example configuration here
---
>   # first example configuration here
156a175,180
> ```terraform
> provider "scaffolding" {
>   # second example configuration here
> }
> ```
>
180c204
<   configurable_attribute = "some-value"
---
>   configurable_attribute = "some-value1"
183a208,213
> ```terraform
> resource "scaffolding_example" "example" {
>   configurable_attribute = "some-value2"
> }
> ```
>
258c288
<   configurable_attribute = "some-value"
---
>   configurable_attribute = "some-value1"
261a292,297
> ```terraform
> resource "scaffolding_example" "example" {
>   configurable_attribute = "some-value2"
> }
> ```
>
285c321
<   configurable_attribute = "some-value"
---
>   configurable_attribute = "some-value1"
286a323,326
> -- examples/data-sources/scaffolding_example/data-source2.tf --
> data "scaffolding_example" "example" {
>   configurable_attribute = "some-value2"
> }
290a331,334
> -- examples/functions/example/function2.tf --
> output "test" {
>   value = provider::scaffolding::example("testvalue3", "testvalue4")
> }
294a339,342
> -- examples/functions/no-variadic/function2.tf --
> output "test" {
>   value = provider::scaffolding::no-variadic("testvalue2")
> }
297c345
<   # example configuration here
---
>   # first example configuration here
298a347,350
> -- examples/provider/provider2.tf --
> provider "scaffolding" {
>   # second example configuration here
> }
323c375
<   configurable_attribute = "some-value"
---
>   configurable_attribute = "some-value1"
324a377,380
> -- examples/resources/scaffolding_example/resource2.tf --
> resource "scaffolding_example" "example" {
>   configurable_attribute = "some-value2"
> }
327c383
<   configurable_attribute = "some-value"
---
>   configurable_attribute = "some-value1"
329c385,388
<
---
> -- examples/ephemeral-resources/scaffolding_example/ephemeral-resource2.tf --
> resource "scaffolding_example" "example" {
>   configurable_attribute = "some-value2"
> }

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

…lt templates

Reference: hashicorp#508

This change updates the generate command to search for multiple configuration example files using a wildcard and render all found files with the default templates (e.g. `resource*.tf` instead of just `resource.tf`). Compatibility with the existing singular `HasExample` and `ExampleFile` fields for templating is preserved, while new plural `HasExamples` and `ExampleFiles` fields were added into the template data. The testing for this feature was added by duplicating the existing "no templates" txtar, then adding second configuration example files:

```diff
4c4
< # Successful run of tfplugindocs on a Framework provider with examples but no templates or pre-exiting docs.
---
> # Successful run of tfplugindocs on a Framework provider with multiple configuration examples but no templates or pre-exiting docs.
57c57
<   configurable_attribute = "some-value"
---
>   configurable_attribute = "some-value1"
60a61,66
> ```terraform
> data "scaffolding_example" "example" {
>   configurable_attribute = "some-value2"
> }
> ```
>
91a98,103
> ```terraform
> output "test" {
>   value = provider::scaffolding::example("testvalue3", "testvalue4")
> }
> ```
>
122a135,140
> }
> ```
>
> ```terraform
> output "test" {
>   value = provider::scaffolding::no-variadic("testvalue2")
153c171
<   # example configuration here
---
>   # first example configuration here
156a175,180
> ```terraform
> provider "scaffolding" {
>   # second example configuration here
> }
> ```
>
180c204
<   configurable_attribute = "some-value"
---
>   configurable_attribute = "some-value1"
183a208,213
> ```terraform
> resource "scaffolding_example" "example" {
>   configurable_attribute = "some-value2"
> }
> ```
>
258c288
<   configurable_attribute = "some-value"
---
>   configurable_attribute = "some-value1"
261a292,297
> ```terraform
> resource "scaffolding_example" "example" {
>   configurable_attribute = "some-value2"
> }
> ```
>
285c321
<   configurable_attribute = "some-value"
---
>   configurable_attribute = "some-value1"
286a323,326
> -- examples/data-sources/scaffolding_example/data-source2.tf --
> data "scaffolding_example" "example" {
>   configurable_attribute = "some-value2"
> }
290a331,334
> -- examples/functions/example/function2.tf --
> output "test" {
>   value = provider::scaffolding::example("testvalue3", "testvalue4")
> }
294a339,342
> -- examples/functions/no-variadic/function2.tf --
> output "test" {
>   value = provider::scaffolding::no-variadic("testvalue2")
> }
297c345
<   # example configuration here
---
>   # first example configuration here
298a347,350
> -- examples/provider/provider2.tf --
> provider "scaffolding" {
>   # second example configuration here
> }
323c375
<   configurable_attribute = "some-value"
---
>   configurable_attribute = "some-value1"
324a377,380
> -- examples/resources/scaffolding_example/resource2.tf --
> resource "scaffolding_example" "example" {
>   configurable_attribute = "some-value2"
> }
327c383
<   configurable_attribute = "some-value"
---
>   configurable_attribute = "some-value1"
329c385,388
<
---
> -- examples/ephemeral-resources/scaffolding_example/ephemeral-resource2.tf --
> resource "scaffolding_example" "example" {
>   configurable_attribute = "some-value2"
> }
```
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

Successfully merging this pull request may close these issues.

Consider supporting multiple example files in default templates
1 participant