Skip to content

Commit b4b63ec

Browse files
committed
Allowing single word resources to use templates
1 parent ed20132 commit b4b63ec

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

internal/provider/generate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ func (g *generator) renderStaticWebsite(providerName string, providerSchema *tfj
414414
g.infof("rendering %q", rel)
415415
switch relDir {
416416
case "data-sources/":
417-
resName := shortName + "_" + removeAllExt(relFile)
417+
resName := resourceName(shortName, relFile)
418418
resSchema, ok := providerSchema.DataSourceSchemas[resName]
419419
if ok {
420420
tmpl := resourceTemplate(tmplData)
@@ -429,7 +429,7 @@ func (g *generator) renderStaticWebsite(providerName string, providerSchema *tfj
429429
return nil
430430
}
431431
case "resources/":
432-
resName := shortName + "_" + removeAllExt(relFile)
432+
resName := resourceName(shortName, relFile)
433433
resSchema, ok := providerSchema.ResourceSchemas[resName]
434434
if ok {
435435
tmpl := resourceTemplate(tmplData)

internal/provider/template.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"text/template"
99

1010
tfjson "github.com/hashicorp/terraform-json"
11+
1112
"github.com/hashicorp/terraform-plugin-docs/internal/mdplain"
1213
"github.com/hashicorp/terraform-plugin-docs/internal/tmplfuncs"
1314
"github.com/hashicorp/terraform-plugin-docs/schemamd"

internal/provider/util.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ func removeAllExt(file string) string {
5252
}
5353
}
5454

55+
// resourceName determines whether the shortname and the relFile
56+
// are identical after file extensions have been stripped from the
57+
// latter. This allows single word resources (e.g., http) to use
58+
// templates (e.g., http.md.tmpl).
59+
func resourceName(shortName, relFile string) string {
60+
if shortName == removeAllExt(relFile) {
61+
return shortName
62+
}
63+
64+
return shortName + "_" + removeAllExt(relFile)
65+
}
66+
5567
func writeFile(path string, data string) error {
5668
dir, _ := filepath.Split(path)
5769
err := os.MkdirAll(dir, 0755)

0 commit comments

Comments
 (0)