feat(generate): Support multiple configuration example files in default templates#511
Conversation
…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" > } ```
|
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 |
austinvalle
left a comment
There was a problem hiding this comment.
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 👍🏻
austinvalle
left a comment
There was a problem hiding this comment.
Ran this locally against the tls provider as well and all looks good 👍🏻
|
Thanks so much, @austinvalle and @rainkwan! 🎉 |
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*.tfinstead of justresource.tf). Compatibility with the existing singularHasExampleandExampleFilefields for templating is preserved, while new pluralHasExamplesandExampleFilesfields 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:Rollback Plan
Changes to Security Controls
Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.