Skip to content

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"
> }
```
@bflad bflad requested a review from a team as a code owner August 19, 2025 17:42
@austinvalle austinvalle added this to the v0.24.0 milestone Sep 18, 2025
@austinvalle
Copy link
Member

Hey @bflad 👋🏻 , thanks for the contribution! Just to give you an update, we triaged this PR today and I'm planning on reviewing this next week so we can include your changes in our upcoming v0.24.0 release.

austinvalle
austinvalle previously approved these changes Sep 24, 2025
Copy link
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for the submission @bflad! All of these changes LGTM 🚀

There is a merge conflict to work through before they can be merged, which I will do and push to your PR. There's also some follow-up work so that this pattern is applied for some recently introduced action types (#505), which I will also submit before we release v0.24.0 with your changes here 👍🏻

Copy link
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this locally against the tls provider as well and all looks good 👍🏻

Copy link
Contributor

@rainkwan rainkwan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@austinvalle austinvalle merged commit 6975416 into hashicorp:main Sep 24, 2025
6 checks passed
@bflad
Copy link
Contributor Author

bflad commented Sep 25, 2025

Thanks so much, @austinvalle and @rainkwan! 🎉

@bflad bflad deleted the bflad/multiple-default-example-files branch September 25, 2025 11:31
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
3 participants