Skip to content

Commit 6975416

Browse files
bfladaustinvalle
andauthored
feat(generate): Support multiple configuration example files in default templates (#511)
* feat(generate): Support multiple configuration example files in default templates Reference: #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" > } ``` * test fix after recent merge * fix merge conflict --------- Co-authored-by: Austin Valle <austinvalle@gmail.com>
1 parent df10e95 commit 6975416

File tree

7 files changed

+678
-53
lines changed

7 files changed

+678
-53
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: FEATURES
2+
body: 'generate: Support multiple configuration example files in default templates'
3+
time: 2025-08-19T13:34:00.429551-04:00
4+
custom:
5+
Issue: "508"

README.md

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -226,18 +226,18 @@ For examples:
226226
> **NOTE:** In the following conventional paths for examples, `<data source name>` and `<resource name>` include the provider prefix as well, but the provider prefix is **NOT** included in`<function name>`.
227227
> For example, the data source [`caller_identity`](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) in the `aws` provider would have an "example" conventional path of: `examples/data-sources/aws_caller_identity/data-source.tf`
228228
229-
| Path | Description |
230-
|---------------------------------------------------------------------------|--------------------------------------------|
231-
| `examples/` | Root of examples |
232-
| `examples/provider/provider.tf` | Provider example config |
233-
| `examples/actions/<action_type>/action.tf` | Action example config |
234-
| `examples/data-sources/<data source name>/data-source.tf` | Data source example config |
235-
| `examples/ephemeral-resources/<ephemeral resource>/ephemeral-resource.tf` | Ephemeral resource example config |
236-
| `examples/functions/<function name>/function.tf` | Function example config |
237-
| `examples/resources/<resource name>/resource.tf` | Resource example config |
238-
| `examples/resources/<resource name>/import.sh` | Resource example import command |
239-
| `examples/resources/<resource name>/import-by-string-id.tf` | Resource example import by id config |
240-
| `examples/resources/<resource name>/import-by-identity.tf` | Resource example import by identity config |
229+
| Path | Description |
230+
|------------------------------------------------------------------------------|--------------------------------------------|
231+
| `examples/` | Root of examples |
232+
| `examples/provider/provider<*>.tf` | Provider example config(s) |
233+
| `examples/actions/<action_type>/action.tf` | Action example config |
234+
| `examples/data-sources/<data source name>/data-source<*>.tf` | Data source example config(s) |
235+
| `examples/ephemeral-resources/<ephemeral resource>/ephemeral-resource<*>.tf` | Ephemeral resource example config(s) |
236+
| `examples/functions/<function name>/function<*>.tf` | Function example config(s) |
237+
| `examples/resources/<resource name>/resource<*>.tf` | Resource example config(s) |
238+
| `examples/resources/<resource name>/import.sh` | Resource example import command |
239+
| `examples/resources/<resource name>/import-by-string-id.tf` | Resource example import by id config |
240+
| `examples/resources/<resource name>/import-by-identity.tf` | Resource example import by identity config |
241241
242242
#### Migration
243243
@@ -291,8 +291,10 @@ using the following data fields and functions:
291291
| Field | Type | Description |
292292
|-------------------------|--------|-------------------------------------------------------------------------------------------|
293293
| `.Description` | string | Provider description |
294-
| `.HasExample` | bool | Is there an example file? |
295-
| `.ExampleFile` | string | Path to the file with the terraform configuration example |
294+
| `.HasExample` | bool | (Legacy) Is there an example file? |
295+
| `.HasExamples` | bool | Are there example files? Always true if HasExample is true. |
296+
| `.ExampleFile` | string | (Legacy) Path to the file with the Terraform configuration example. |
297+
| `.ExampleFiles` | string | Paths to the files with the Terraform configuration example. Includes ExampleFile. |
296298
| `.ProviderName` | string | Canonical provider name (ex. `terraform-provider-random`) |
297299
| `.ProviderShortName` | string | Short version of the rendered provider name (ex. `random`) |
298300
| `.RenderedProviderName` | string | Value provided via argument `--rendered-provider-name`, otherwise same as `.ProviderName` |
@@ -305,8 +307,10 @@ using the following data fields and functions:
305307
| `.Name` | string | Name of the resource/data-source (ex. `tls_certificate`) |
306308
| `.Type` | string | Either `Resource` or `Data Source` |
307309
| `.Description` | string | Resource / Data Source description |
308-
| `.HasExample` | bool | Is there an example file? |
309-
| `.ExampleFile` | string | Path to the file with the terraform configuration example |
310+
| `.HasExample` | bool | (Legacy) Is there an example file? |
311+
| `.HasExamples` | bool | Are there example files? Always true if HasExample is true. |
312+
| `.ExampleFile` | string | (Legacy) Path to the file with the Terraform configuration example. |
313+
| `.ExampleFiles` | string | Paths to the files with Terraform configuration examples. Includes ExampleFile. |
310314
| `.HasImport` | bool | Is there an import shell file? (`terraform import` shell example) |
311315
| `.ImportFile` | string | Path to the file with the command for importing the resource |
312316
| `.HasImportIDConfig` | bool | Is there an import terraform config file? (`import` block example with `id`) |
@@ -327,8 +331,10 @@ using the following data fields and functions:
327331
| `.Type` | string | Returns `Function` |
328332
| `.Description` | string | Function description |
329333
| `.Summary` | string | Function summary |
330-
| `.HasExample` | bool | Is there an example file? |
331-
| `.ExampleFile` | string | Path to the file with the terraform configuration example |
334+
| `.HasExample` | bool | (Legacy) Is there an example file? |
335+
| `.HasExamples` | bool | Are there example files? Always true if HasExample is true. |
336+
| `.ExampleFile` | string | (Legacy) Path to the file with the Terraform configuration example |
337+
| `.ExampleFiles` | string | Paths to the files with Terraform configuration examples. Includes ExampleFile. |
332338
| `.ProviderName` | string | Canonical provider name (ex. `terraform-provider-random`) |
333339
| `.ProviderShortName` | string | Short version of the rendered provider name (ex. `random`) |
334340
| `.RenderedProviderName` | string | Value provided via argument `--rendered-provider-name`, otherwise same as `.ProviderName` |

0 commit comments

Comments
 (0)