diff --git a/internal/cli/config.go b/internal/cli/config.go index c4666dd..9ce114a 100644 --- a/internal/cli/config.go +++ b/internal/cli/config.go @@ -15,7 +15,7 @@ import ( "strings" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" + "github.com/terraform-docs/terraform-docs/terraform" ) // Mappings of CLI flags to Viper config diff --git a/internal/cli/run.go b/internal/cli/run.go index a8d46e4..c275423 100644 --- a/internal/cli/run.go +++ b/internal/cli/run.go @@ -25,8 +25,8 @@ import ( pluginsdk "github.com/terraform-docs/plugin-sdk/plugin" "github.com/terraform-docs/terraform-docs/internal/format" "github.com/terraform-docs/terraform-docs/internal/plugin" - "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/version" + "github.com/terraform-docs/terraform-docs/terraform" ) // Runtime represents the execution runtime for CLI. diff --git a/internal/format/asciidoc_document.go b/internal/format/asciidoc_document.go index 7625283..ba08d0d 100644 --- a/internal/format/asciidoc_document.go +++ b/internal/format/asciidoc_document.go @@ -15,8 +15,8 @@ import ( gotemplate "text/template" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/template" + "github.com/terraform-docs/terraform-docs/terraform" ) //go:embed templates/asciidoc_document*.tmpl diff --git a/internal/format/asciidoc_document_test.go b/internal/format/asciidoc_document_test.go index bfb113f..27aff7d 100644 --- a/internal/format/asciidoc_document_test.go +++ b/internal/format/asciidoc_document_test.go @@ -16,8 +16,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" + "github.com/terraform-docs/terraform-docs/terraform" ) func TestAsciidocDocument(t *testing.T) { diff --git a/internal/format/asciidoc_table.go b/internal/format/asciidoc_table.go index 26d1dec..c666874 100644 --- a/internal/format/asciidoc_table.go +++ b/internal/format/asciidoc_table.go @@ -15,8 +15,8 @@ import ( gotemplate "text/template" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/template" + "github.com/terraform-docs/terraform-docs/terraform" ) //go:embed templates/asciidoc_table*.tmpl diff --git a/internal/format/asciidoc_table_test.go b/internal/format/asciidoc_table_test.go index 0b68222..fff9458 100644 --- a/internal/format/asciidoc_table_test.go +++ b/internal/format/asciidoc_table_test.go @@ -16,8 +16,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" + "github.com/terraform-docs/terraform-docs/terraform" ) func TestAsciidocTable(t *testing.T) { diff --git a/internal/format/common_test.go b/internal/format/common_test.go index a42544c..f9f102c 100644 --- a/internal/format/common_test.go +++ b/internal/format/common_test.go @@ -16,8 +16,8 @@ import ( "github.com/stretchr/testify/assert" - "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" + "github.com/terraform-docs/terraform-docs/terraform" ) func TestCommonSort(t *testing.T) { diff --git a/internal/format/json.go b/internal/format/json.go index 6d84246..02b6613 100644 --- a/internal/format/json.go +++ b/internal/format/json.go @@ -16,7 +16,7 @@ import ( "strings" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" + "github.com/terraform-docs/terraform-docs/terraform" ) // JSON represents JSON format. diff --git a/internal/format/json_test.go b/internal/format/json_test.go index a8c6cd8..e50d114 100644 --- a/internal/format/json_test.go +++ b/internal/format/json_test.go @@ -16,8 +16,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" + "github.com/terraform-docs/terraform-docs/terraform" ) func TestJson(t *testing.T) { diff --git a/internal/format/markdown_document.go b/internal/format/markdown_document.go index 4f49a75..5496e13 100644 --- a/internal/format/markdown_document.go +++ b/internal/format/markdown_document.go @@ -15,8 +15,8 @@ import ( gotemplate "text/template" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/template" + "github.com/terraform-docs/terraform-docs/terraform" ) //go:embed templates/markdown_document*.tmpl diff --git a/internal/format/markdown_document_test.go b/internal/format/markdown_document_test.go index e90eb5a..3b88081 100644 --- a/internal/format/markdown_document_test.go +++ b/internal/format/markdown_document_test.go @@ -16,8 +16,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" + "github.com/terraform-docs/terraform-docs/terraform" ) func TestMarkdownDocument(t *testing.T) { diff --git a/internal/format/markdown_table.go b/internal/format/markdown_table.go index 0baca66..4730596 100644 --- a/internal/format/markdown_table.go +++ b/internal/format/markdown_table.go @@ -15,8 +15,8 @@ import ( gotemplate "text/template" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/template" + "github.com/terraform-docs/terraform-docs/terraform" ) //go:embed templates/markdown_table*.tmpl diff --git a/internal/format/markdown_table_test.go b/internal/format/markdown_table_test.go index 09f02d4..76c9f89 100644 --- a/internal/format/markdown_table_test.go +++ b/internal/format/markdown_table_test.go @@ -16,8 +16,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" + "github.com/terraform-docs/terraform-docs/terraform" ) func TestMarkdownTable(t *testing.T) { diff --git a/internal/format/pretty.go b/internal/format/pretty.go index b6dc634..d4634d4 100644 --- a/internal/format/pretty.go +++ b/internal/format/pretty.go @@ -17,8 +17,8 @@ import ( gotemplate "text/template" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/template" + "github.com/terraform-docs/terraform-docs/terraform" ) //go:embed templates/pretty.tmpl diff --git a/internal/format/pretty_test.go b/internal/format/pretty_test.go index f2aef2f..9b1f4a7 100644 --- a/internal/format/pretty_test.go +++ b/internal/format/pretty_test.go @@ -16,8 +16,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" + "github.com/terraform-docs/terraform-docs/terraform" ) func TestPretty(t *testing.T) { diff --git a/internal/format/tfvars_hcl.go b/internal/format/tfvars_hcl.go index da73c82..5e31ef4 100644 --- a/internal/format/tfvars_hcl.go +++ b/internal/format/tfvars_hcl.go @@ -17,9 +17,9 @@ import ( gotemplate "text/template" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/types" "github.com/terraform-docs/terraform-docs/template" + "github.com/terraform-docs/terraform-docs/terraform" ) //go:embed templates/tfvars_hcl.tmpl diff --git a/internal/format/tfvars_hcl_test.go b/internal/format/tfvars_hcl_test.go index 0129b26..dc32f4b 100644 --- a/internal/format/tfvars_hcl_test.go +++ b/internal/format/tfvars_hcl_test.go @@ -16,8 +16,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" + "github.com/terraform-docs/terraform-docs/terraform" ) func TestTfvarsHcl(t *testing.T) { diff --git a/internal/format/tfvars_json.go b/internal/format/tfvars_json.go index 0f16d5a..31ab08d 100644 --- a/internal/format/tfvars_json.go +++ b/internal/format/tfvars_json.go @@ -18,7 +18,7 @@ import ( "github.com/iancoleman/orderedmap" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" + "github.com/terraform-docs/terraform-docs/terraform" ) // TfvarsJSON represents Terraform tfvars JSON format. diff --git a/internal/format/tfvars_json_test.go b/internal/format/tfvars_json_test.go index a8277c7..07c28b1 100644 --- a/internal/format/tfvars_json_test.go +++ b/internal/format/tfvars_json_test.go @@ -16,8 +16,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" + "github.com/terraform-docs/terraform-docs/terraform" ) func TestTfvarsJson(t *testing.T) { diff --git a/internal/format/toml.go b/internal/format/toml.go index 239d861..59e9e47 100644 --- a/internal/format/toml.go +++ b/internal/format/toml.go @@ -17,7 +17,7 @@ import ( "github.com/BurntSushi/toml" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" + "github.com/terraform-docs/terraform-docs/terraform" ) // TOML represents TOML format. diff --git a/internal/format/toml_test.go b/internal/format/toml_test.go index 3143d7c..a79edb9 100644 --- a/internal/format/toml_test.go +++ b/internal/format/toml_test.go @@ -16,8 +16,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" + "github.com/terraform-docs/terraform-docs/terraform" ) func TestToml(t *testing.T) { diff --git a/internal/format/xml.go b/internal/format/xml.go index 53daba4..eb612a0 100644 --- a/internal/format/xml.go +++ b/internal/format/xml.go @@ -15,7 +15,7 @@ import ( "strings" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" + "github.com/terraform-docs/terraform-docs/terraform" ) // XML represents XML format. diff --git a/internal/format/xml_test.go b/internal/format/xml_test.go index c8c78c8..a332a6d 100644 --- a/internal/format/xml_test.go +++ b/internal/format/xml_test.go @@ -16,8 +16,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" + "github.com/terraform-docs/terraform-docs/terraform" ) func TestXml(t *testing.T) { diff --git a/internal/format/yaml.go b/internal/format/yaml.go index d5b1a6c..97fbb3f 100644 --- a/internal/format/yaml.go +++ b/internal/format/yaml.go @@ -17,7 +17,7 @@ import ( "gopkg.in/yaml.v3" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" + "github.com/terraform-docs/terraform-docs/terraform" ) // YAML represents YAML format. diff --git a/internal/format/yaml_test.go b/internal/format/yaml_test.go index 4d60c41..b065b05 100644 --- a/internal/format/yaml_test.go +++ b/internal/format/yaml_test.go @@ -16,8 +16,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" + "github.com/terraform-docs/terraform-docs/terraform" ) func TestYaml(t *testing.T) { diff --git a/internal/print/engine.go b/internal/print/engine.go index 661cd29..321e66c 100644 --- a/internal/print/engine.go +++ b/internal/print/engine.go @@ -11,7 +11,7 @@ the root directory of this source tree. package print import ( - "github.com/terraform-docs/terraform-docs/internal/terraform" + "github.com/terraform-docs/terraform-docs/terraform" ) // Engine represents a format engine (e.g. json, table, yaml, ...) diff --git a/internal/print/settings.go b/internal/print/settings.go index 49d4f35..25943fc 100644 --- a/internal/print/settings.go +++ b/internal/print/settings.go @@ -12,7 +12,7 @@ package print import ( printsdk "github.com/terraform-docs/plugin-sdk/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" + "github.com/terraform-docs/terraform-docs/terraform" ) // Settings represents all settings. diff --git a/internal/terraform/doc.go b/internal/terraform/doc.go deleted file mode 100644 index 015a6db..0000000 --- a/internal/terraform/doc.go +++ /dev/null @@ -1,12 +0,0 @@ -/* -Copyright 2021 The terraform-docs Authors. - -Licensed under the MIT license (the "License"); you may not -use this file except in compliance with the License. - -You may obtain a copy of the License at the LICENSE file in -the root directory of this source tree. -*/ - -// Package terraform is the representation of a Terraform Module -package terraform diff --git a/internal/testutil/testing.go b/internal/testutil/testing.go index 416dc33..46fd7a8 100644 --- a/internal/testutil/testing.go +++ b/internal/testutil/testing.go @@ -16,7 +16,7 @@ import ( "path/filepath" "runtime" - "github.com/terraform-docs/terraform-docs/internal/terraform" + "github.com/terraform-docs/terraform-docs/terraform" ) // GetModule returns 'example' Module diff --git a/scripts/docs/generate.go b/scripts/docs/generate.go index 03a6459..512672b 100644 --- a/scripts/docs/generate.go +++ b/scripts/docs/generate.go @@ -25,7 +25,7 @@ import ( "github.com/terraform-docs/terraform-docs/cmd" "github.com/terraform-docs/terraform-docs/internal/format" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" + "github.com/terraform-docs/terraform-docs/terraform" ) // These are practiaclly a copy/paste of https://github.com/spf13/cobra/blob/master/doc/md_docs.go diff --git a/template/doc.go b/template/doc.go index a39f8bf..e003672 100644 --- a/template/doc.go +++ b/template/doc.go @@ -17,8 +17,8 @@ the root directory of this source tree. // gotemplate "text/template" // // "github.com/terraform-docs/terraform-docs/internal/print" -// "github.com/terraform-docs/terraform-docs/internal/terraform" // "github.com/terraform-docs/terraform-docs/template" +// "github.com/terraform-docs/terraform-docs/terraform" // ) // // const mainTpl =` diff --git a/template/template.go b/template/template.go index 00b4bfb..49462f4 100644 --- a/template/template.go +++ b/template/template.go @@ -17,8 +17,8 @@ import ( gotemplate "text/template" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/types" + "github.com/terraform-docs/terraform-docs/terraform" ) // Item represents a named templated which can reference other named templated too. diff --git a/template/template_test.go b/template/template_test.go index 147d8ff..e451a0b 100644 --- a/template/template_test.go +++ b/template/template_test.go @@ -21,8 +21,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/terraform-docs/terraform-docs/internal/print" - "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/types" + "github.com/terraform-docs/terraform-docs/terraform" ) func TestTemplateRender(t *testing.T) { diff --git a/terraform/doc.go b/terraform/doc.go new file mode 100644 index 0000000..1708dc8 --- /dev/null +++ b/terraform/doc.go @@ -0,0 +1,52 @@ +/* +Copyright 2021 The terraform-docs Authors. + +Licensed under the MIT license (the "License"); you may not +use this file except in compliance with the License. + +You may obtain a copy of the License at the LICENSE file in +the root directory of this source tree. +*/ + +// Package terraform is the representation of a Terraform Module. +// +// It contains: +// +// • Header: Module header found in shape of multi line '*.tf' comments or an entire file +// +// • Footer: Module footer found in shape of multi line '*.tf' comments or an entire file +// +// • Inputs: List of input 'variables' extracted from the Terraform module .tf files +// +// • ModuleCalls: List of 'modules' extracted from the Terraform module .tf files +// +// • Outputs: List of 'outputs' extracted from Terraform module .tf files +// +// • Providers: List of 'providers' extracted from resources used in Terraform module +// +// • Requirements: List of 'requirements' extracted from the Terraform module .tf files +// +// • Resources: List of 'resources' extracted from the Terraform module .tf files +// +// Usage +// +// options := &terraform.Options{ +// Path: "./examples", +// ShowHeader: true, +// HeaderFromFile: "main.tf", +// ShowFooter: true, +// FooterFromFile: "footer.md", +// SortBy: &terraform.SortBy{ +// Name: true, +// }, +// ReadComments: true, +// } +// +// tfmodule, err := terraform.LoadWithOptions(options) +// if err != nil { +// log.Fatal(err) +// } +// +// ... +// +package terraform diff --git a/internal/terraform/input.go b/terraform/input.go similarity index 64% rename from internal/terraform/input.go rename to terraform/input.go index 5f84873..78a4842 100644 --- a/internal/terraform/input.go +++ b/terraform/input.go @@ -14,6 +14,7 @@ import ( "bytes" "encoding/json" "fmt" + "sort" "strings" terraformsdk "github.com/terraform-docs/plugin-sdk/terraform" @@ -57,40 +58,37 @@ func (i *Input) HasDefault() bool { return i.Default.HasDefault() || !i.Required } -type inputsSortedByName []*Input - -func (a inputsSortedByName) Len() int { return len(a) } -func (a inputsSortedByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a inputsSortedByName) Less(i, j int) bool { return a[i].Name < a[j].Name } - -type inputsSortedByRequired []*Input - -func (a inputsSortedByRequired) Len() int { return len(a) } -func (a inputsSortedByRequired) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a inputsSortedByRequired) Less(i, j int) bool { - if a[i].HasDefault() == a[j].HasDefault() { - return a[i].Name < a[j].Name - } - return !a[i].HasDefault() && a[j].HasDefault() +func sortInputsByName(x []*Input) { + sort.Slice(x, func(i, j int) bool { + return x[i].Name < x[j].Name + }) } -type inputsSortedByPosition []*Input - -func (a inputsSortedByPosition) Len() int { return len(a) } -func (a inputsSortedByPosition) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a inputsSortedByPosition) Less(i, j int) bool { - return a[i].Position.Filename < a[j].Position.Filename || a[i].Position.Line < a[j].Position.Line +func sortInputsByRequired(x []*Input) { + sort.Slice(x, func(i, j int) bool { + if x[i].HasDefault() == x[j].HasDefault() { + return x[i].Name < x[j].Name + } + return !x[i].HasDefault() && x[j].HasDefault() + }) } -type inputsSortedByType []*Input +func sortInputsByPosition(x []*Input) { + sort.Slice(x, func(i, j int) bool { + if x[i].Position.Filename == x[j].Position.Filename { + return x[i].Position.Line < x[j].Position.Line + } + return x[i].Position.Filename < x[j].Position.Filename + }) +} -func (a inputsSortedByType) Len() int { return len(a) } -func (a inputsSortedByType) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a inputsSortedByType) Less(i, j int) bool { - if a[i].Type == a[j].Type { - return a[i].Name < a[j].Name - } - return a[i].Type < a[j].Type +func sortInputsByType(x []*Input) { + sort.Slice(x, func(i, j int) bool { + if x[i].Type == x[j].Type { + return x[i].Name < x[j].Name + } + return x[i].Type < x[j].Type + }) } type inputs []*Input diff --git a/internal/terraform/input_test.go b/terraform/input_test.go similarity index 97% rename from internal/terraform/input_test.go rename to terraform/input_test.go index e3c2313..10414f8 100644 --- a/internal/terraform/input_test.go +++ b/terraform/input_test.go @@ -11,7 +11,6 @@ the root directory of this source tree. package terraform import ( - "sort" "testing" "github.com/stretchr/testify/assert" @@ -214,19 +213,19 @@ func TestInputValue(t *testing.T) { func TestInputsSorted(t *testing.T) { inputs := sampleInputs() tests := map[string]struct { - sortType sort.Interface + sortType func([]*Input) expected []string }{ "ByName": { - sortType: inputsSortedByName(inputs), + sortType: sortInputsByName, expected: []string{"a", "b", "c", "d", "e", "f"}, }, "ByRequired": { - sortType: inputsSortedByRequired(inputs), + sortType: sortInputsByRequired, expected: []string{"b", "d", "a", "c", "e", "f"}, }, "ByPosition": { - sortType: inputsSortedByPosition(inputs), + sortType: sortInputsByPosition, expected: []string{"a", "d", "e", "b", "c", "f"}, }, } @@ -234,7 +233,7 @@ func TestInputsSorted(t *testing.T) { t.Run(name, func(t *testing.T) { assert := assert.New(t) - sort.Sort(tt.sortType) + tt.sortType(inputs) actual := make([]string, len(inputs)) diff --git a/internal/terraform/module.go b/terraform/load.go similarity index 73% rename from internal/terraform/module.go rename to terraform/load.go index c651149..d6f6117 100644 --- a/internal/terraform/module.go +++ b/terraform/load.go @@ -12,7 +12,6 @@ package terraform import ( "encoding/json" - "encoding/xml" "errors" "fmt" "io/ioutil" @@ -25,94 +24,11 @@ import ( "github.com/hashicorp/hcl/v2/hclsimple" - terraformsdk "github.com/terraform-docs/plugin-sdk/terraform" "github.com/terraform-docs/terraform-config-inspect/tfconfig" "github.com/terraform-docs/terraform-docs/internal/reader" "github.com/terraform-docs/terraform-docs/internal/types" ) -// Module represents a Terraform module. It consists of -// -// - Header ('header' json key): Module header found in shape of multi line '*.tf' comments or an entire file -// - Footer ('footer' json key): Module footer found in shape of multi line '*.tf' comments or an entire file -// - Inputs ('inputs' json key): List of input 'variables' extracted from the Terraform module .tf files -// - ModuleCalls ('modules' json key): List of 'modules' extracted from the Terraform module .tf files -// - Outputs ('outputs' json key): List of 'outputs' extracted from Terraform module .tf files -// - Providers ('providers' json key): List of 'providers' extracted from resources used in Terraform module -// - Requirements ('requirements' json key): List of 'requirements' extracted from the Terraform module .tf files -// - Resources ('resources' json key): List of 'resources' extracted from the Terraform module .tf files -type Module struct { - XMLName xml.Name `json:"-" toml:"-" xml:"module" yaml:"-"` - - Header string `json:"header" toml:"header" xml:"header" yaml:"header"` - Footer string `json:"footer" toml:"footer" xml:"footer" yaml:"footer"` - Inputs []*Input `json:"inputs" toml:"inputs" xml:"inputs>input" yaml:"inputs"` - ModuleCalls []*ModuleCall `json:"modules" toml:"modules" xml:"modules>module" yaml:"modules"` - Outputs []*Output `json:"outputs" toml:"outputs" xml:"outputs>output" yaml:"outputs"` - Providers []*Provider `json:"providers" toml:"providers" xml:"providers>provider" yaml:"providers"` - Requirements []*Requirement `json:"requirements" toml:"requirements" xml:"requirements>requirement" yaml:"requirements"` - Resources []*Resource `json:"resources" toml:"resources" xml:"resources>resource" yaml:"resources"` - - RequiredInputs []*Input `json:"-" toml:"-" xml:"-" yaml:"-"` - OptionalInputs []*Input `json:"-" toml:"-" xml:"-" yaml:"-"` -} - -// HasHeader indicates if the module has header. -func (m *Module) HasHeader() bool { - return len(m.Header) > 0 -} - -// HasFooter indicates if the module has footer. -func (m *Module) HasFooter() bool { - return len(m.Footer) > 0 -} - -// HasInputs indicates if the module has inputs. -func (m *Module) HasInputs() bool { - return len(m.Inputs) > 0 -} - -// HasModuleCalls indicates if the module has modulecalls. -func (m *Module) HasModuleCalls() bool { - return len(m.ModuleCalls) > 0 -} - -// HasOutputs indicates if the module has outputs. -func (m *Module) HasOutputs() bool { - return len(m.Outputs) > 0 -} - -// HasProviders indicates if the module has providers. -func (m *Module) HasProviders() bool { - return len(m.Providers) > 0 -} - -// HasRequirements indicates if the module has requirements. -func (m *Module) HasRequirements() bool { - return len(m.Requirements) > 0 -} - -// HasResources indicates if the module has resources. -func (m *Module) HasResources() bool { - return len(m.Resources) > 0 -} - -// Convert internal Module to its equivalent in plugin-sdk -func (m *Module) Convert() terraformsdk.Module { - return terraformsdk.NewModule( - terraformsdk.WithHeader(m.Header), - terraformsdk.WithFooter(m.Footer), - terraformsdk.WithInputs(inputs(m.Inputs).convert()), - terraformsdk.WithModuleCalls(modulecalls(m.ModuleCalls).convert()), - terraformsdk.WithOutputs(outputs(m.Outputs).convert()), - terraformsdk.WithProviders(providers(m.Providers).convert()), - terraformsdk.WithRequirements(requirements(m.Requirements).convert()), - terraformsdk.WithResources(resources(m.Resources).convert()), - terraformsdk.WithRequiredInputs(inputs(m.RequiredInputs).convert()), - terraformsdk.WithOptionalInputs(inputs(m.OptionalInputs).convert()), - ) -} - // LoadWithOptions returns new instance of Module with all the inputs and // outputs discovered from provided 'path' containing Terraform config func LoadWithOptions(options *Options) (*Module, error) { @@ -578,47 +494,47 @@ func sortItems(tfmodule *Module, sortby *SortBy) { //nolint:gocyclo // inputs switch { case sortby.Type: - sort.Sort(inputsSortedByType(tfmodule.Inputs)) - sort.Sort(inputsSortedByType(tfmodule.RequiredInputs)) - sort.Sort(inputsSortedByType(tfmodule.OptionalInputs)) + sortInputsByType(tfmodule.Inputs) + sortInputsByType(tfmodule.RequiredInputs) + sortInputsByType(tfmodule.OptionalInputs) case sortby.Required: - sort.Sort(inputsSortedByRequired(tfmodule.Inputs)) - sort.Sort(inputsSortedByRequired(tfmodule.RequiredInputs)) - sort.Sort(inputsSortedByRequired(tfmodule.OptionalInputs)) + sortInputsByRequired(tfmodule.Inputs) + sortInputsByRequired(tfmodule.RequiredInputs) + sortInputsByRequired(tfmodule.OptionalInputs) case sortby.Name: - sort.Sort(inputsSortedByName(tfmodule.Inputs)) - sort.Sort(inputsSortedByName(tfmodule.RequiredInputs)) - sort.Sort(inputsSortedByName(tfmodule.OptionalInputs)) + sortInputsByName(tfmodule.Inputs) + sortInputsByName(tfmodule.RequiredInputs) + sortInputsByName(tfmodule.OptionalInputs) default: - sort.Sort(inputsSortedByPosition(tfmodule.Inputs)) - sort.Sort(inputsSortedByPosition(tfmodule.RequiredInputs)) - sort.Sort(inputsSortedByPosition(tfmodule.OptionalInputs)) + sortInputsByPosition(tfmodule.Inputs) + sortInputsByPosition(tfmodule.RequiredInputs) + sortInputsByPosition(tfmodule.OptionalInputs) } // outputs if sortby.Name || sortby.Required || sortby.Type { - sort.Sort(outputsSortedByName(tfmodule.Outputs)) + sortOutputsByName(tfmodule.Outputs) } else { - sort.Sort(outputsSortedByPosition(tfmodule.Outputs)) + sortOutputsByPosition(tfmodule.Outputs) } // providers if sortby.Name || sortby.Required || sortby.Type { - sort.Sort(providersSortedByName(tfmodule.Providers)) + sortProvidersByName(tfmodule.Providers) } else { - sort.Sort(providersSortedByPosition(tfmodule.Providers)) + sortProvidersByPosition(tfmodule.Providers) } // resources (always sorted) - sort.Sort(resourcesSortedByType(tfmodule.Resources)) + sortResourcesByType(tfmodule.Resources) // modules switch { case sortby.Name || sortby.Required: - sort.Sort(modulecallsSortedByName(tfmodule.ModuleCalls)) + sortModulecallsByName(tfmodule.ModuleCalls) case sortby.Type: - sort.Sort(modulecallsSortedBySource(tfmodule.ModuleCalls)) + sortModulecallsBySource(tfmodule.ModuleCalls) default: - sort.Sort(modulecallsSortedByPosition(tfmodule.ModuleCalls)) + sortModulecallsByPosition(tfmodule.ModuleCalls) } } diff --git a/internal/terraform/module_test.go b/terraform/load_test.go similarity index 99% rename from internal/terraform/module_test.go rename to terraform/load_test.go index 785a92e..7f0c394 100644 --- a/internal/terraform/module_test.go +++ b/terraform/load_test.go @@ -722,7 +722,6 @@ func TestLoadProviders(t *testing.T) { for _, p := range providers { actual = append(actual, p.FullName()+"-"+string(p.Version)) - providers[0].FullName() } sort.Strings(actual) diff --git a/terraform/module.go b/terraform/module.go new file mode 100644 index 0000000..caa6a91 --- /dev/null +++ b/terraform/module.go @@ -0,0 +1,90 @@ +/* +Copyright 2021 The terraform-docs Authors. + +Licensed under the MIT license (the "License"); you may not +use this file except in compliance with the License. + +You may obtain a copy of the License at the LICENSE file in +the root directory of this source tree. +*/ + +package terraform + +import ( + "encoding/xml" + + terraformsdk "github.com/terraform-docs/plugin-sdk/terraform" +) + +// Module represents a Terraform module. It consists of +type Module struct { + XMLName xml.Name `json:"-" toml:"-" xml:"module" yaml:"-"` + + Header string `json:"header" toml:"header" xml:"header" yaml:"header"` + Footer string `json:"footer" toml:"footer" xml:"footer" yaml:"footer"` + Inputs []*Input `json:"inputs" toml:"inputs" xml:"inputs>input" yaml:"inputs"` + ModuleCalls []*ModuleCall `json:"modules" toml:"modules" xml:"modules>module" yaml:"modules"` + Outputs []*Output `json:"outputs" toml:"outputs" xml:"outputs>output" yaml:"outputs"` + Providers []*Provider `json:"providers" toml:"providers" xml:"providers>provider" yaml:"providers"` + Requirements []*Requirement `json:"requirements" toml:"requirements" xml:"requirements>requirement" yaml:"requirements"` + Resources []*Resource `json:"resources" toml:"resources" xml:"resources>resource" yaml:"resources"` + + RequiredInputs []*Input `json:"-" toml:"-" xml:"-" yaml:"-"` + OptionalInputs []*Input `json:"-" toml:"-" xml:"-" yaml:"-"` +} + +// HasHeader indicates if the module has header. +func (m *Module) HasHeader() bool { + return len(m.Header) > 0 +} + +// HasFooter indicates if the module has footer. +func (m *Module) HasFooter() bool { + return len(m.Footer) > 0 +} + +// HasInputs indicates if the module has inputs. +func (m *Module) HasInputs() bool { + return len(m.Inputs) > 0 +} + +// HasModuleCalls indicates if the module has modulecalls. +func (m *Module) HasModuleCalls() bool { + return len(m.ModuleCalls) > 0 +} + +// HasOutputs indicates if the module has outputs. +func (m *Module) HasOutputs() bool { + return len(m.Outputs) > 0 +} + +// HasProviders indicates if the module has providers. +func (m *Module) HasProviders() bool { + return len(m.Providers) > 0 +} + +// HasRequirements indicates if the module has requirements. +func (m *Module) HasRequirements() bool { + return len(m.Requirements) > 0 +} + +// HasResources indicates if the module has resources. +func (m *Module) HasResources() bool { + return len(m.Resources) > 0 +} + +// Convert internal Module to its equivalent in plugin-sdk +func (m *Module) Convert() terraformsdk.Module { + return terraformsdk.NewModule( + terraformsdk.WithHeader(m.Header), + terraformsdk.WithFooter(m.Footer), + terraformsdk.WithInputs(inputs(m.Inputs).convert()), + terraformsdk.WithModuleCalls(modulecalls(m.ModuleCalls).convert()), + terraformsdk.WithOutputs(outputs(m.Outputs).convert()), + terraformsdk.WithProviders(providers(m.Providers).convert()), + terraformsdk.WithRequirements(requirements(m.Requirements).convert()), + terraformsdk.WithResources(resources(m.Resources).convert()), + terraformsdk.WithRequiredInputs(inputs(m.RequiredInputs).convert()), + terraformsdk.WithOptionalInputs(inputs(m.OptionalInputs).convert()), + ) +} diff --git a/internal/terraform/modulecall.go b/terraform/modulecall.go similarity index 57% rename from internal/terraform/modulecall.go rename to terraform/modulecall.go index e4335f5..d96f4bd 100644 --- a/internal/terraform/modulecall.go +++ b/terraform/modulecall.go @@ -12,6 +12,7 @@ package terraform import ( "fmt" + "sort" terraformsdk "github.com/terraform-docs/plugin-sdk/terraform" ) @@ -32,29 +33,25 @@ func (mc *ModuleCall) FullName() string { return mc.Source } -type modulecallsSortedByName []*ModuleCall - -func (a modulecallsSortedByName) Len() int { return len(a) } -func (a modulecallsSortedByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a modulecallsSortedByName) Less(i, j int) bool { return a[i].Name < a[j].Name } - -type modulecallsSortedBySource []*ModuleCall - -func (a modulecallsSortedBySource) Len() int { return len(a) } -func (a modulecallsSortedBySource) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a modulecallsSortedBySource) Less(i, j int) bool { - if a[i].Source == a[j].Source { - return a[i].Name < a[j].Name - } - return a[i].Source < a[j].Source +func sortModulecallsByName(x []*ModuleCall) { + sort.Slice(x, func(i, j int) bool { + return x[i].Name < x[j].Name + }) } -type modulecallsSortedByPosition []*ModuleCall +func sortModulecallsBySource(x []*ModuleCall) { + sort.Slice(x, func(i, j int) bool { + if x[i].Source == x[j].Source { + return x[i].Name < x[j].Name + } + return x[i].Source < x[j].Source + }) +} -func (a modulecallsSortedByPosition) Len() int { return len(a) } -func (a modulecallsSortedByPosition) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a modulecallsSortedByPosition) Less(i, j int) bool { - return a[i].Position.Filename < a[j].Position.Filename || a[i].Position.Line < a[j].Position.Line +func sortModulecallsByPosition(x []*ModuleCall) { + sort.Slice(x, func(i, j int) bool { + return x[i].Position.Filename < x[j].Position.Filename || x[i].Position.Line < x[j].Position.Line + }) } type modulecalls []*ModuleCall diff --git a/internal/terraform/modulecall_test.go b/terraform/modulecall_test.go similarity index 91% rename from internal/terraform/modulecall_test.go rename to terraform/modulecall_test.go index 3ac53e2..eec0289 100644 --- a/internal/terraform/modulecall_test.go +++ b/terraform/modulecall_test.go @@ -11,7 +11,6 @@ the root directory of this source tree. package terraform import ( - "sort" "testing" "github.com/stretchr/testify/assert" @@ -49,19 +48,19 @@ func TestModulecallName(t *testing.T) { func TestModulecallSort(t *testing.T) { modules := sampleModulecalls() tests := map[string]struct { - sortType sort.Interface + sortType func([]*ModuleCall) expected []string }{ "ByName": { - sortType: modulecallsSortedByName(modules), + sortType: sortModulecallsByName, expected: []string{"a", "b", "c", "d", "e", "f"}, }, "BySource": { - sortType: modulecallsSortedBySource(modules), + sortType: sortModulecallsBySource, expected: []string{"f", "d", "c", "e", "a", "b"}, }, "ByPosition": { - sortType: modulecallsSortedByPosition(modules), + sortType: sortModulecallsByPosition, expected: []string{"b", "c", "a", "e", "d", "f"}, }, } @@ -69,7 +68,7 @@ func TestModulecallSort(t *testing.T) { t.Run(name, func(t *testing.T) { assert := assert.New(t) - sort.Sort(tt.sortType) + tt.sortType(modules) actual := make([]string, len(modules)) diff --git a/internal/terraform/options.go b/terraform/options.go similarity index 100% rename from internal/terraform/options.go rename to terraform/options.go diff --git a/internal/terraform/options_test.go b/terraform/options_test.go similarity index 100% rename from internal/terraform/options_test.go rename to terraform/options_test.go diff --git a/internal/terraform/output.go b/terraform/output.go similarity index 89% rename from internal/terraform/output.go rename to terraform/output.go index f8c7f9a..2bd87f4 100644 --- a/internal/terraform/output.go +++ b/terraform/output.go @@ -15,6 +15,7 @@ import ( "encoding/json" "encoding/xml" "fmt" + "sort" terraformsdk "github.com/terraform-docs/plugin-sdk/terraform" "github.com/terraform-docs/terraform-docs/internal/types" @@ -128,18 +129,19 @@ type output struct { Value interface{} `json:"value"` } -type outputsSortedByName []*Output +func sortOutputsByName(x []*Output) { + sort.Slice(x, func(i, j int) bool { + return x[i].Name < x[j].Name + }) +} -func (a outputsSortedByName) Len() int { return len(a) } -func (a outputsSortedByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a outputsSortedByName) Less(i, j int) bool { return a[i].Name < a[j].Name } - -type outputsSortedByPosition []*Output - -func (a outputsSortedByPosition) Len() int { return len(a) } -func (a outputsSortedByPosition) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a outputsSortedByPosition) Less(i, j int) bool { - return a[i].Position.Filename < a[j].Position.Filename || a[i].Position.Line < a[j].Position.Line +func sortOutputsByPosition(x []*Output) { + sort.Slice(x, func(i, j int) bool { + if x[i].Position.Filename == x[j].Position.Filename { + return x[i].Position.Line < x[j].Position.Line + } + return x[i].Position.Filename < x[j].Position.Filename + }) } type outputs []*Output diff --git a/internal/terraform/output_test.go b/terraform/output_test.go similarity index 98% rename from internal/terraform/output_test.go rename to terraform/output_test.go index d42f614..a9e9819 100644 --- a/internal/terraform/output_test.go +++ b/terraform/output_test.go @@ -14,7 +14,6 @@ import ( "bytes" "encoding/xml" "reflect" - "sort" "testing" "github.com/stretchr/testify/assert" @@ -463,15 +462,15 @@ func sampleOutputs() []Output { func TestOutputsSort(t *testing.T) { outputs := sampleOutputsForSort() tests := map[string]struct { - sortType sort.Interface + sortType func([]*Output) expected []string }{ "ByName": { - sortType: outputsSortedByName(outputs), + sortType: sortOutputsByName, expected: []string{"a", "b", "c", "d", "e"}, }, "ByPosition": { - sortType: outputsSortedByPosition(outputs), + sortType: sortOutputsByPosition, expected: []string{"d", "a", "e", "b", "c"}, }, } @@ -479,7 +478,7 @@ func TestOutputsSort(t *testing.T) { t.Run(name, func(t *testing.T) { assert := assert.New(t) - sort.Sort(tt.sortType) + tt.sortType(outputs) actual := make([]string, len(outputs)) diff --git a/internal/terraform/position.go b/terraform/position.go similarity index 100% rename from internal/terraform/position.go rename to terraform/position.go diff --git a/internal/terraform/provider.go b/terraform/provider.go similarity index 68% rename from internal/terraform/provider.go rename to terraform/provider.go index c411267..f5e2893 100644 --- a/internal/terraform/provider.go +++ b/terraform/provider.go @@ -12,6 +12,7 @@ package terraform import ( "fmt" + "sort" terraformsdk "github.com/terraform-docs/plugin-sdk/terraform" "github.com/terraform-docs/terraform-docs/internal/types" @@ -33,20 +34,22 @@ func (p *Provider) FullName() string { return p.Name } -type providersSortedByName []*Provider - -func (a providersSortedByName) Len() int { return len(a) } -func (a providersSortedByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a providersSortedByName) Less(i, j int) bool { - return a[i].Name < a[j].Name || (a[i].Name == a[j].Name && a[i].Alias < a[j].Alias) +func sortProvidersByName(x []*Provider) { + sort.Slice(x, func(i, j int) bool { + if x[i].Name == x[j].Name { + return x[i].Name == x[j].Name && x[i].Alias < x[j].Alias + } + return x[i].Name < x[j].Name + }) } -type providersSortedByPosition []*Provider - -func (a providersSortedByPosition) Len() int { return len(a) } -func (a providersSortedByPosition) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a providersSortedByPosition) Less(i, j int) bool { - return a[i].Position.Filename < a[j].Position.Filename || a[i].Position.Line < a[j].Position.Line +func sortProvidersByPosition(x []*Provider) { + sort.Slice(x, func(i, j int) bool { + if x[i].Position.Filename == x[j].Position.Filename { + return x[i].Position.Line < x[j].Position.Line + } + return x[i].Position.Filename < x[j].Position.Filename + }) } type providers []*Provider diff --git a/internal/terraform/provider_test.go b/terraform/provider_test.go similarity index 94% rename from internal/terraform/provider_test.go rename to terraform/provider_test.go index 50b60ab..7cda6b4 100644 --- a/internal/terraform/provider_test.go +++ b/terraform/provider_test.go @@ -11,7 +11,6 @@ the root directory of this source tree. package terraform import ( - "sort" "testing" "github.com/stretchr/testify/assert" @@ -54,15 +53,15 @@ func TestProviderName(t *testing.T) { func TestProvidersSort(t *testing.T) { providers := sampleProviders() tests := map[string]struct { - sortType sort.Interface + sortType func([]*Provider) expected []string }{ "ByName": { - sortType: providersSortedByName(providers), + sortType: sortProvidersByName, expected: []string{"a", "b", "c", "d", "d.a", "e", "e.a"}, }, "ByPosition": { - sortType: providersSortedByPosition(providers), + sortType: sortProvidersByPosition, expected: []string{"e.a", "b", "d", "d.a", "a", "e", "c"}, }, } @@ -70,7 +69,7 @@ func TestProvidersSort(t *testing.T) { t.Run(name, func(t *testing.T) { assert := assert.New(t) - sort.Sort(tt.sortType) + tt.sortType(providers) actual := make([]string, len(providers)) diff --git a/internal/terraform/requirement.go b/terraform/requirement.go similarity index 100% rename from internal/terraform/requirement.go rename to terraform/requirement.go diff --git a/internal/terraform/resource.go b/terraform/resource.go similarity index 87% rename from internal/terraform/resource.go rename to terraform/resource.go index 4c2825a..42b7077 100644 --- a/internal/terraform/resource.go +++ b/terraform/resource.go @@ -12,6 +12,7 @@ package terraform import ( "fmt" + "sort" "strings" terraformsdk "github.com/terraform-docs/plugin-sdk/terraform" @@ -67,18 +68,16 @@ func (r *Resource) URL() string { return fmt.Sprintf("https://registry.terraform.io/providers/%s/%s/docs/%s/%s", r.ProviderSource, r.Version, kind, r.Type) } -type resourcesSortedByType []*Resource - -func (a resourcesSortedByType) Len() int { return len(a) } -func (a resourcesSortedByType) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a resourcesSortedByType) Less(i, j int) bool { - if a[i].Mode == a[j].Mode { - if a[i].Spec() == a[j].Spec() { - return a[i].Name <= a[j].Name +func sortResourcesByType(x []*Resource) { + sort.Slice(x, func(i, j int) bool { + if x[i].Mode == x[j].Mode { + if x[i].Spec() == x[j].Spec() { + return x[i].Name <= x[j].Name + } + return x[i].Spec() < x[j].Spec() } - return a[i].Spec() < a[j].Spec() - } - return a[i].Mode > a[j].Mode + return x[i].Mode > x[j].Mode + }) } type resources []*Resource diff --git a/internal/terraform/resource_test.go b/terraform/resource_test.go similarity index 98% rename from internal/terraform/resource_test.go rename to terraform/resource_test.go index 2569c87..c506c4c 100644 --- a/internal/terraform/resource_test.go +++ b/terraform/resource_test.go @@ -11,7 +11,6 @@ the root directory of this source tree. package terraform import ( - "sort" "testing" "github.com/stretchr/testify/assert" @@ -134,7 +133,7 @@ func TestResourcesSortedByType(t *testing.T) { assert := assert.New(t) resources := sampleResources() - sort.Sort(resourcesSortedByType(resources)) + sortResourcesByType(resources) expected := []string{"a_a.a", "a_f.f", "b_b.b", "b_d.d", "c_c.c", "c_e.c", "c_e.d", "c_e_x.c", "c_e_x.d", "z_z.z", "a_a.a", "z_z.z", "a_a.a", "z_z.z"} actual := make([]string, len(resources)) @@ -150,7 +149,7 @@ func TestResourcesSortedByTypeAndMode(t *testing.T) { assert := assert.New(t) resources := sampleResources() - sort.Sort(resourcesSortedByType(resources)) + sortResourcesByType(resources) expected := []string{"a_a.a (r)", "a_f.f (r)", "b_b.b (r)", "b_d.d (r)", "c_c.c (r)", "c_e.c (r)", "c_e.d (r)", "c_e_x.c (r)", "c_e_x.d (r)", "z_z.z (r)", "a_a.a (d)", "z_z.z (d)", "a_a.a", "z_z.z"} actual := make([]string, len(resources)) diff --git a/internal/terraform/testdata/empty-header/main.tf b/terraform/testdata/empty-header/main.tf similarity index 100% rename from internal/terraform/testdata/empty-header/main.tf rename to terraform/testdata/empty-header/main.tf diff --git a/internal/terraform/testdata/expected/full-example-mainTf-Header.golden b/terraform/testdata/expected/full-example-mainTf-Header.golden similarity index 100% rename from internal/terraform/testdata/expected/full-example-mainTf-Header.golden rename to terraform/testdata/expected/full-example-mainTf-Header.golden diff --git a/internal/terraform/testdata/full-example/doc.adoc b/terraform/testdata/full-example/doc.adoc similarity index 100% rename from internal/terraform/testdata/full-example/doc.adoc rename to terraform/testdata/full-example/doc.adoc diff --git a/internal/terraform/testdata/full-example/doc.md b/terraform/testdata/full-example/doc.md similarity index 100% rename from internal/terraform/testdata/full-example/doc.md rename to terraform/testdata/full-example/doc.md diff --git a/internal/terraform/testdata/full-example/doc.tf b/terraform/testdata/full-example/doc.tf similarity index 100% rename from internal/terraform/testdata/full-example/doc.tf rename to terraform/testdata/full-example/doc.tf diff --git a/internal/terraform/testdata/full-example/doc.txt b/terraform/testdata/full-example/doc.txt similarity index 100% rename from internal/terraform/testdata/full-example/doc.txt rename to terraform/testdata/full-example/doc.txt diff --git a/internal/terraform/testdata/full-example/main.tf b/terraform/testdata/full-example/main.tf similarity index 100% rename from internal/terraform/testdata/full-example/main.tf rename to terraform/testdata/full-example/main.tf diff --git a/internal/terraform/testdata/full-example/output-values.json b/terraform/testdata/full-example/output-values.json similarity index 100% rename from internal/terraform/testdata/full-example/output-values.json rename to terraform/testdata/full-example/output-values.json diff --git a/internal/terraform/testdata/full-example/outputs.tf b/terraform/testdata/full-example/outputs.tf similarity index 100% rename from internal/terraform/testdata/full-example/outputs.tf rename to terraform/testdata/full-example/outputs.tf diff --git a/internal/terraform/testdata/full-example/variables.tf b/terraform/testdata/full-example/variables.tf similarity index 100% rename from internal/terraform/testdata/full-example/variables.tf rename to terraform/testdata/full-example/variables.tf diff --git a/internal/terraform/testdata/inputs-crlf/variables.tf b/terraform/testdata/inputs-crlf/variables.tf similarity index 100% rename from internal/terraform/testdata/inputs-crlf/variables.tf rename to terraform/testdata/inputs-crlf/variables.tf diff --git a/internal/terraform/testdata/inputs-lf/variables.tf b/terraform/testdata/inputs-lf/variables.tf similarity index 100% rename from internal/terraform/testdata/inputs-lf/variables.tf rename to terraform/testdata/inputs-lf/variables.tf diff --git a/internal/terraform/testdata/no-inputs/variables.tf b/terraform/testdata/no-inputs/variables.tf similarity index 100% rename from internal/terraform/testdata/no-inputs/variables.tf rename to terraform/testdata/no-inputs/variables.tf diff --git a/internal/terraform/testdata/no-modulecalls/main.tf b/terraform/testdata/no-modulecalls/main.tf similarity index 100% rename from internal/terraform/testdata/no-modulecalls/main.tf rename to terraform/testdata/no-modulecalls/main.tf diff --git a/internal/terraform/testdata/no-optional-inputs/variables.tf b/terraform/testdata/no-optional-inputs/variables.tf similarity index 100% rename from internal/terraform/testdata/no-optional-inputs/variables.tf rename to terraform/testdata/no-optional-inputs/variables.tf diff --git a/internal/terraform/testdata/no-outputs/outputs.tf b/terraform/testdata/no-outputs/outputs.tf similarity index 100% rename from internal/terraform/testdata/no-outputs/outputs.tf rename to terraform/testdata/no-outputs/outputs.tf diff --git a/internal/terraform/testdata/no-providers/main.tf b/terraform/testdata/no-providers/main.tf similarity index 100% rename from internal/terraform/testdata/no-providers/main.tf rename to terraform/testdata/no-providers/main.tf diff --git a/internal/terraform/testdata/no-required-inputs/variables.tf b/terraform/testdata/no-required-inputs/variables.tf similarity index 100% rename from internal/terraform/testdata/no-required-inputs/variables.tf rename to terraform/testdata/no-required-inputs/variables.tf diff --git a/internal/terraform/testdata/read-comments/variables.tf b/terraform/testdata/read-comments/variables.tf similarity index 100% rename from internal/terraform/testdata/read-comments/variables.tf rename to terraform/testdata/read-comments/variables.tf diff --git a/internal/terraform/testdata/with-lock-file/.terraform.lock.hcl b/terraform/testdata/with-lock-file/.terraform.lock.hcl similarity index 100% rename from internal/terraform/testdata/with-lock-file/.terraform.lock.hcl rename to terraform/testdata/with-lock-file/.terraform.lock.hcl diff --git a/internal/terraform/testdata/with-lock-file/main.tf b/terraform/testdata/with-lock-file/main.tf similarity index 100% rename from internal/terraform/testdata/with-lock-file/main.tf rename to terraform/testdata/with-lock-file/main.tf diff --git a/internal/terraform/testdata/with-lock-file/outputs.tf b/terraform/testdata/with-lock-file/outputs.tf similarity index 100% rename from internal/terraform/testdata/with-lock-file/outputs.tf rename to terraform/testdata/with-lock-file/outputs.tf diff --git a/internal/terraform/testdata/with-lock-file/variables.tf b/terraform/testdata/with-lock-file/variables.tf similarity index 100% rename from internal/terraform/testdata/with-lock-file/variables.tf rename to terraform/testdata/with-lock-file/variables.tf