diff --git a/examples/main.tf b/examples/main.tf index ad823fd..c74d549 100644 --- a/examples/main.tf +++ b/examples/main.tf @@ -58,17 +58,17 @@ data "aws_caller_identity" "ident" { resource "null_resource" "foo" {} -module "foo" { - source = "bar" - version = "1.2.3" -} - module "bar" { source = "baz" version = "4.5.6" } +module "foo" { + source = "bar" + version = "1.2.3" +} + module "baz" { source = "baz" version = "4.5.6" -} \ No newline at end of file +} diff --git a/go.mod b/go.mod index 3279b85..8863637 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/spf13/cobra v1.1.3 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.7.0 - github.com/terraform-docs/plugin-sdk v0.1.1-0.20210315181351-354f95b748c2 + github.com/terraform-docs/plugin-sdk v0.1.1-0.20210315210824-bb03f50252e3 github.com/terraform-docs/terraform-config-inspect v0.0.0-20210126151735-6ef25af8884f gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b honnef.co/go/tools v0.1.2 diff --git a/go.sum b/go.sum index 55576fa..7e3842d 100644 --- a/go.sum +++ b/go.sum @@ -221,8 +221,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= -github.com/terraform-docs/plugin-sdk v0.1.1-0.20210315181351-354f95b748c2 h1:sRiFTk/RE2vdLu4/Qm7NN0wNvIuj7vFblBfYDOuQ7qg= -github.com/terraform-docs/plugin-sdk v0.1.1-0.20210315181351-354f95b748c2/go.mod h1:3G+0nZTeaMF1c5CZh8cOEYeNq0kUL6+DlQOVcxK7eCQ= +github.com/terraform-docs/plugin-sdk v0.1.1-0.20210315210824-bb03f50252e3 h1:3X3lgb0DSmmJrsMIvIkkF/PTueQ+qkBz31Y6ARIx2AY= +github.com/terraform-docs/plugin-sdk v0.1.1-0.20210315210824-bb03f50252e3/go.mod h1:3G+0nZTeaMF1c5CZh8cOEYeNq0kUL6+DlQOVcxK7eCQ= github.com/terraform-docs/terraform-config-inspect v0.0.0-20210126151735-6ef25af8884f h1:WXgHENMC8JOyj6aRpOlnAnJkZ3ZAkPBOhqYrJ5GOhDE= github.com/terraform-docs/terraform-config-inspect v0.0.0-20210126151735-6ef25af8884f/go.mod h1:GtanFwTsRRXScYHOMb5h4K18XQBFeS2tXat9/LrPtPc= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= diff --git a/internal/format/testdata/asciidoc/document-Base.golden b/internal/format/testdata/asciidoc/document-Base.golden index e027b9f..538fdfe 100644 --- a/internal/format/testdata/asciidoc/document-Base.golden +++ b/internal/format/testdata/asciidoc/document-Base.golden @@ -62,18 +62,18 @@ The following providers are used by this module: The following Modules are called: -=== foo - -Source: bar - -Version: 1.2.3 - === bar Source: baz Version: 4.5.6 +=== foo + +Source: bar + +Version: 1.2.3 + === baz Source: baz diff --git a/internal/format/testdata/asciidoc/document-IndentationOfFour.golden b/internal/format/testdata/asciidoc/document-IndentationOfFour.golden index 67066ee..57acf5c 100644 --- a/internal/format/testdata/asciidoc/document-IndentationOfFour.golden +++ b/internal/format/testdata/asciidoc/document-IndentationOfFour.golden @@ -62,18 +62,18 @@ The following providers are used by this module: The following Modules are called: -===== foo - -Source: bar - -Version: 1.2.3 - ===== bar Source: baz Version: 4.5.6 +===== foo + +Source: bar + +Version: 1.2.3 + ===== baz Source: baz diff --git a/internal/format/testdata/asciidoc/document-OnlyModulecalls.golden b/internal/format/testdata/asciidoc/document-OnlyModulecalls.golden index 8552bbf..bea2517 100644 --- a/internal/format/testdata/asciidoc/document-OnlyModulecalls.golden +++ b/internal/format/testdata/asciidoc/document-OnlyModulecalls.golden @@ -2,18 +2,18 @@ The following Modules are called: -=== foo - -Source: bar - -Version: 1.2.3 - === bar Source: baz Version: 4.5.6 +=== foo + +Source: bar + +Version: 1.2.3 + === baz Source: baz diff --git a/internal/format/testdata/asciidoc/document-WithAnchor.golden b/internal/format/testdata/asciidoc/document-WithAnchor.golden index fe0ee66..e95019d 100644 --- a/internal/format/testdata/asciidoc/document-WithAnchor.golden +++ b/internal/format/testdata/asciidoc/document-WithAnchor.golden @@ -62,18 +62,18 @@ The following providers are used by this module: The following Modules are called: -=== [[module_foo]] <> - -Source: bar - -Version: 1.2.3 - === [[module_bar]] <> Source: baz Version: 4.5.6 +=== [[module_foo]] <> + +Source: bar + +Version: 1.2.3 + === [[module_baz]] <> Source: baz diff --git a/internal/format/testdata/asciidoc/document-WithRequired.golden b/internal/format/testdata/asciidoc/document-WithRequired.golden index a863f94..95031f7 100644 --- a/internal/format/testdata/asciidoc/document-WithRequired.golden +++ b/internal/format/testdata/asciidoc/document-WithRequired.golden @@ -62,18 +62,18 @@ The following providers are used by this module: The following Modules are called: -=== foo - -Source: bar - -Version: 1.2.3 - === bar Source: baz Version: 4.5.6 +=== foo + +Source: bar + +Version: 1.2.3 + === baz Source: baz diff --git a/internal/format/testdata/asciidoc/table-Base.golden b/internal/format/testdata/asciidoc/table-Base.golden index c19814b..979e826 100644 --- a/internal/format/testdata/asciidoc/table-Base.golden +++ b/internal/format/testdata/asciidoc/table-Base.golden @@ -62,8 +62,8 @@ followed by another line of text. [cols="a,a,a",options="header,autowidth"] |=== |Name|Source|Version| -|foo|bar|1.2.3 |bar|baz|4.5.6 +|foo|bar|1.2.3 |baz|baz|4.5.6 |=== diff --git a/internal/format/testdata/asciidoc/table-IndentationOfFour.golden b/internal/format/testdata/asciidoc/table-IndentationOfFour.golden index 146b0ce..51442c5 100644 --- a/internal/format/testdata/asciidoc/table-IndentationOfFour.golden +++ b/internal/format/testdata/asciidoc/table-IndentationOfFour.golden @@ -62,8 +62,8 @@ followed by another line of text. [cols="a,a,a",options="header,autowidth"] |=== |Name|Source|Version| -|foo|bar|1.2.3 |bar|baz|4.5.6 +|foo|bar|1.2.3 |baz|baz|4.5.6 |=== diff --git a/internal/format/testdata/asciidoc/table-OnlyModulecalls.golden b/internal/format/testdata/asciidoc/table-OnlyModulecalls.golden index 3d96062..6ae6fb6 100644 --- a/internal/format/testdata/asciidoc/table-OnlyModulecalls.golden +++ b/internal/format/testdata/asciidoc/table-OnlyModulecalls.golden @@ -3,7 +3,7 @@ [cols="a,a,a",options="header,autowidth"] |=== |Name|Source|Version| -|foo|bar|1.2.3 |bar|baz|4.5.6 +|foo|bar|1.2.3 |baz|baz|4.5.6 |=== \ No newline at end of file diff --git a/internal/format/testdata/asciidoc/table-WithAnchor.golden b/internal/format/testdata/asciidoc/table-WithAnchor.golden index 28ebbc4..8cad22a 100644 --- a/internal/format/testdata/asciidoc/table-WithAnchor.golden +++ b/internal/format/testdata/asciidoc/table-WithAnchor.golden @@ -62,8 +62,8 @@ followed by another line of text. [cols="a,a,a",options="header,autowidth"] |=== |Name|Source|Version| -|[[module_foo]] <>|bar|1.2.3 |[[module_bar]] <>|baz|4.5.6 +|[[module_foo]] <>|bar|1.2.3 |[[module_baz]] <>|baz|4.5.6 |=== diff --git a/internal/format/testdata/asciidoc/table-WithRequired.golden b/internal/format/testdata/asciidoc/table-WithRequired.golden index 29da578..e015764 100644 --- a/internal/format/testdata/asciidoc/table-WithRequired.golden +++ b/internal/format/testdata/asciidoc/table-WithRequired.golden @@ -62,8 +62,8 @@ followed by another line of text. [cols="a,a,a",options="header,autowidth"] |=== |Name|Source|Version| -|foo|bar|1.2.3 |bar|baz|4.5.6 +|foo|bar|1.2.3 |baz|baz|4.5.6 |=== diff --git a/internal/format/testdata/common/sort-NoSort.golden b/internal/format/testdata/common/sort-NoSort.golden index c699a48..74d1431 100644 --- a/internal/format/testdata/common/sort-NoSort.golden +++ b/internal/format/testdata/common/sort-NoSort.golden @@ -33,8 +33,8 @@ "object_default_empty" ], "modules": [ - "foo-bar", "bar-baz", + "foo-bar", "baz-baz" ], "outputs": [ diff --git a/internal/format/testdata/json/json-Base.golden b/internal/format/testdata/json/json-Base.golden index 5cc5f20..29de44d 100644 --- a/internal/format/testdata/json/json-Base.golden +++ b/internal/format/testdata/json/json-Base.golden @@ -246,16 +246,16 @@ } ], "modules": [ - { - "name": "foo", - "source": "bar", - "version": "1.2.3" - }, { "name": "bar", "source": "baz", "version": "4.5.6" }, + { + "name": "foo", + "source": "bar", + "version": "1.2.3" + }, { "name": "baz", "source": "baz", @@ -350,4 +350,4 @@ "version": "latest" } ] -} \ No newline at end of file +} diff --git a/internal/format/testdata/json/json-EscapeCharacters.golden b/internal/format/testdata/json/json-EscapeCharacters.golden index c878aac..bc77e7b 100644 --- a/internal/format/testdata/json/json-EscapeCharacters.golden +++ b/internal/format/testdata/json/json-EscapeCharacters.golden @@ -246,16 +246,16 @@ } ], "modules": [ - { - "name": "foo", - "source": "bar", - "version": "1.2.3" - }, { "name": "bar", "source": "baz", "version": "4.5.6" }, + { + "name": "foo", + "source": "bar", + "version": "1.2.3" + }, { "name": "baz", "source": "baz", @@ -350,4 +350,4 @@ "version": "latest" } ] -} \ No newline at end of file +} diff --git a/internal/format/testdata/json/json-OnlyModulecalls.golden b/internal/format/testdata/json/json-OnlyModulecalls.golden index de2fc4b..794e541 100644 --- a/internal/format/testdata/json/json-OnlyModulecalls.golden +++ b/internal/format/testdata/json/json-OnlyModulecalls.golden @@ -3,16 +3,16 @@ "footer": "", "inputs": [], "modules": [ - { - "name": "foo", - "source": "bar", - "version": "1.2.3" - }, { "name": "bar", "source": "baz", "version": "4.5.6" }, + { + "name": "foo", + "source": "bar", + "version": "1.2.3" + }, { "name": "baz", "source": "baz", diff --git a/internal/format/testdata/json/json-OnlyResources.golden b/internal/format/testdata/json/json-OnlyResources.golden index edd8e89..8200a5d 100644 --- a/internal/format/testdata/json/json-OnlyResources.golden +++ b/internal/format/testdata/json/json-OnlyResources.golden @@ -40,4 +40,4 @@ "version": "latest" } ] -} \ No newline at end of file +} diff --git a/internal/format/testdata/markdown/document-Base.golden b/internal/format/testdata/markdown/document-Base.golden index 8a318b1..902a64f 100644 --- a/internal/format/testdata/markdown/document-Base.golden +++ b/internal/format/testdata/markdown/document-Base.golden @@ -62,18 +62,18 @@ The following providers are used by this module: The following Modules are called: -### foo - -Source: bar - -Version: 1.2.3 - ### bar Source: baz Version: 4.5.6 +### foo + +Source: bar + +Version: 1.2.3 + ### baz Source: baz diff --git a/internal/format/testdata/markdown/document-EscapeCharacters.golden b/internal/format/testdata/markdown/document-EscapeCharacters.golden index eb745f8..cd6677d 100644 --- a/internal/format/testdata/markdown/document-EscapeCharacters.golden +++ b/internal/format/testdata/markdown/document-EscapeCharacters.golden @@ -62,18 +62,18 @@ The following providers are used by this module: The following Modules are called: -### foo - -Source: bar - -Version: 1.2.3 - ### bar Source: baz Version: 4.5.6 +### foo + +Source: bar + +Version: 1.2.3 + ### baz Source: baz diff --git a/internal/format/testdata/markdown/document-IndentationOfFour.golden b/internal/format/testdata/markdown/document-IndentationOfFour.golden index 75f7395..bcf07b6 100644 --- a/internal/format/testdata/markdown/document-IndentationOfFour.golden +++ b/internal/format/testdata/markdown/document-IndentationOfFour.golden @@ -62,18 +62,18 @@ The following providers are used by this module: The following Modules are called: -##### foo - -Source: bar - -Version: 1.2.3 - ##### bar Source: baz Version: 4.5.6 +##### foo + +Source: bar + +Version: 1.2.3 + ##### baz Source: baz diff --git a/internal/format/testdata/markdown/document-OnlyModulecalls.golden b/internal/format/testdata/markdown/document-OnlyModulecalls.golden index 6ba6a10..9fa9dc7 100644 --- a/internal/format/testdata/markdown/document-OnlyModulecalls.golden +++ b/internal/format/testdata/markdown/document-OnlyModulecalls.golden @@ -2,18 +2,18 @@ The following Modules are called: -### foo - -Source: bar - -Version: 1.2.3 - ### bar Source: baz Version: 4.5.6 +### foo + +Source: bar + +Version: 1.2.3 + ### baz Source: baz diff --git a/internal/format/testdata/markdown/document-WithAnchor.golden b/internal/format/testdata/markdown/document-WithAnchor.golden index 24016f9..5514041 100644 --- a/internal/format/testdata/markdown/document-WithAnchor.golden +++ b/internal/format/testdata/markdown/document-WithAnchor.golden @@ -62,18 +62,18 @@ The following providers are used by this module: The following Modules are called: -### [foo](#module_foo) - -Source: bar - -Version: 1.2.3 - ### [bar](#module_bar) Source: baz Version: 4.5.6 +### [foo](#module_foo) + +Source: bar + +Version: 1.2.3 + ### [baz](#module_baz) Source: baz diff --git a/internal/format/testdata/markdown/document-WithRequired.golden b/internal/format/testdata/markdown/document-WithRequired.golden index f46139a..8fe9956 100644 --- a/internal/format/testdata/markdown/document-WithRequired.golden +++ b/internal/format/testdata/markdown/document-WithRequired.golden @@ -62,18 +62,18 @@ The following providers are used by this module: The following Modules are called: -### foo - -Source: bar - -Version: 1.2.3 - ### bar Source: baz Version: 4.5.6 +### foo + +Source: bar + +Version: 1.2.3 + ### baz Source: baz diff --git a/internal/format/testdata/markdown/table-Base.golden b/internal/format/testdata/markdown/table-Base.golden index 0704e11..56f2c5d 100644 --- a/internal/format/testdata/markdown/table-Base.golden +++ b/internal/format/testdata/markdown/table-Base.golden @@ -57,8 +57,8 @@ followed by another line of text. | Name | Source | Version | |------|--------|---------| -| foo | bar | 1.2.3 | | bar | baz | 4.5.6 | +| foo | bar | 1.2.3 | | baz | baz | 4.5.6 | ## Resources diff --git a/internal/format/testdata/markdown/table-EscapeCharacters.golden b/internal/format/testdata/markdown/table-EscapeCharacters.golden index 056ec42..c330659 100644 --- a/internal/format/testdata/markdown/table-EscapeCharacters.golden +++ b/internal/format/testdata/markdown/table-EscapeCharacters.golden @@ -57,8 +57,8 @@ followed by another line of text. | Name | Source | Version | |------|--------|---------| -| foo | bar | 1.2.3 | | bar | baz | 4.5.6 | +| foo | bar | 1.2.3 | | baz | baz | 4.5.6 | ## Resources diff --git a/internal/format/testdata/markdown/table-IndentationOfFour.golden b/internal/format/testdata/markdown/table-IndentationOfFour.golden index 02bf129..fdb38b3 100644 --- a/internal/format/testdata/markdown/table-IndentationOfFour.golden +++ b/internal/format/testdata/markdown/table-IndentationOfFour.golden @@ -57,8 +57,8 @@ followed by another line of text. | Name | Source | Version | |------|--------|---------| -| foo | bar | 1.2.3 | | bar | baz | 4.5.6 | +| foo | bar | 1.2.3 | | baz | baz | 4.5.6 | #### Resources diff --git a/internal/format/testdata/markdown/table-OnlyModulecalls.golden b/internal/format/testdata/markdown/table-OnlyModulecalls.golden index c982ec4..e710ac8 100644 --- a/internal/format/testdata/markdown/table-OnlyModulecalls.golden +++ b/internal/format/testdata/markdown/table-OnlyModulecalls.golden @@ -2,6 +2,6 @@ | Name | Source | Version | |------|--------|---------| -| foo | bar | 1.2.3 | | bar | baz | 4.5.6 | +| foo | bar | 1.2.3 | | baz | baz | 4.5.6 | \ No newline at end of file diff --git a/internal/format/testdata/markdown/table-WithAnchor.golden b/internal/format/testdata/markdown/table-WithAnchor.golden index 2afd739..672aa31 100644 --- a/internal/format/testdata/markdown/table-WithAnchor.golden +++ b/internal/format/testdata/markdown/table-WithAnchor.golden @@ -57,8 +57,8 @@ followed by another line of text. | Name | Source | Version | |------|--------|---------| -| [foo](#module_foo) | bar | 1.2.3 | | [bar](#module_bar) | baz | 4.5.6 | +| [foo](#module_foo) | bar | 1.2.3 | | [baz](#module_baz) | baz | 4.5.6 | ## Resources diff --git a/internal/format/testdata/markdown/table-WithRequired.golden b/internal/format/testdata/markdown/table-WithRequired.golden index 34f2018..28c65cc 100644 --- a/internal/format/testdata/markdown/table-WithRequired.golden +++ b/internal/format/testdata/markdown/table-WithRequired.golden @@ -57,8 +57,8 @@ followed by another line of text. | Name | Source | Version | |------|--------|---------| -| foo | bar | 1.2.3 | | bar | baz | 4.5.6 | +| foo | bar | 1.2.3 | | baz | baz | 4.5.6 | ## Resources diff --git a/internal/format/testdata/pretty/pretty-Base.golden b/internal/format/testdata/pretty/pretty-Base.golden index 9033088..e2edfd4 100644 --- a/internal/format/testdata/pretty/pretty-Base.golden +++ b/internal/format/testdata/pretty/pretty-Base.golden @@ -48,8 +48,8 @@ provider.aws.ident (>= 2.15.0) provider.null -modulecall.foo (bar,1.2.3) modulecall.bar (baz,4.5.6) +modulecall.foo (bar,1.2.3) modulecall.baz (baz,4.5.6) @@ -200,4 +200,4 @@ terraform 0.12 only ## This is an example of a footer -It looks exactly like a header, but is placed at the end of the document \ No newline at end of file +It looks exactly like a header, but is placed at the end of the document diff --git a/internal/format/testdata/pretty/pretty-OnlyModulecalls.golden b/internal/format/testdata/pretty/pretty-OnlyModulecalls.golden index 164a003..82334b9 100644 --- a/internal/format/testdata/pretty/pretty-OnlyModulecalls.golden +++ b/internal/format/testdata/pretty/pretty-OnlyModulecalls.golden @@ -1,3 +1,3 @@ -modulecall.foo (bar,1.2.3) modulecall.bar (baz,4.5.6) -modulecall.baz (baz,4.5.6) \ No newline at end of file +modulecall.foo (bar,1.2.3) +modulecall.baz (baz,4.5.6) diff --git a/internal/format/testdata/pretty/pretty-WithColor.golden b/internal/format/testdata/pretty/pretty-WithColor.golden index f5d6c95..d7be301 100644 --- a/internal/format/testdata/pretty/pretty-WithColor.golden +++ b/internal/format/testdata/pretty/pretty-WithColor.golden @@ -48,8 +48,8 @@ followed by another line of text. provider.null -modulecall.foo (bar,1.2.3) modulecall.bar (baz,4.5.6) +modulecall.foo (bar,1.2.3) modulecall.baz (baz,4.5.6) @@ -200,4 +200,4 @@ It spans over multiple lines. ## This is an example of a footer -It looks exactly like a header, but is placed at the end of the document \ No newline at end of file +It looks exactly like a header, but is placed at the end of the document diff --git a/internal/format/testdata/toml/toml-Base.golden b/internal/format/testdata/toml/toml-Base.golden index 96942d2..a3d720d 100644 --- a/internal/format/testdata/toml/toml-Base.golden +++ b/internal/format/testdata/toml/toml-Base.golden @@ -230,16 +230,16 @@ footer = "## This is an example of a footer\n\nIt looks exactly like a header, b required = false [inputs.default] -[[modules]] - Name = "foo" - Source = "bar" - Version = "1.2.3" - [[modules]] Name = "bar" Source = "baz" Version = "4.5.6" +[[modules]] + Name = "foo" + Source = "bar" + Version = "1.2.3" + [[modules]] Name = "baz" Source = "baz" @@ -323,4 +323,4 @@ footer = "## This is an example of a footer\n\nIt looks exactly like a header, b providerName = "aws" providerSource = "hashicorp/aws" mode = "data" - version = "latest" \ No newline at end of file + version = "latest" diff --git a/internal/format/testdata/toml/toml-OnlyModulecalls.golden b/internal/format/testdata/toml/toml-OnlyModulecalls.golden index 4506541..0aaf329 100644 --- a/internal/format/testdata/toml/toml-OnlyModulecalls.golden +++ b/internal/format/testdata/toml/toml-OnlyModulecalls.golden @@ -6,17 +6,17 @@ providers = [] requirements = [] resources = [] -[[modules]] - Name = "foo" - Source = "bar" - Version = "1.2.3" - [[modules]] Name = "bar" Source = "baz" Version = "4.5.6" +[[modules]] + Name = "foo" + Source = "bar" + Version = "1.2.3" + [[modules]] Name = "baz" Source = "baz" - Version = "4.5.6" \ No newline at end of file + Version = "4.5.6" diff --git a/internal/format/testdata/toml/toml-OnlyRequirements.golden b/internal/format/testdata/toml/toml-OnlyRequirements.golden index 8e0158f..639c3f0 100644 --- a/internal/format/testdata/toml/toml-OnlyRequirements.golden +++ b/internal/format/testdata/toml/toml-OnlyRequirements.golden @@ -16,4 +16,4 @@ resources = [] [[requirements]] Name = "random" - Version = ">= 2.2.0" \ No newline at end of file + Version = ">= 2.2.0" diff --git a/internal/format/testdata/toml/toml-OnlyResources.golden b/internal/format/testdata/toml/toml-OnlyResources.golden index 45e2f38..1ff1e8f 100644 --- a/internal/format/testdata/toml/toml-OnlyResources.golden +++ b/internal/format/testdata/toml/toml-OnlyResources.golden @@ -36,4 +36,4 @@ requirements = [] providerName = "aws" providerSource = "hashicorp/aws" mode = "data" - version = "latest" \ No newline at end of file + version = "latest" diff --git a/internal/format/testdata/xml/xml-Base.golden b/internal/format/testdata/xml/xml-Base.golden index 4e2eea6..8b89a19 100644 --- a/internal/format/testdata/xml/xml-Base.golden +++ b/internal/format/testdata/xml/xml-Base.golden @@ -246,16 +246,16 @@ - - foo - bar - 1.2.3 - bar baz 4.5.6 + + foo + bar + 1.2.3 + baz baz @@ -350,4 +350,4 @@ latest - \ No newline at end of file + diff --git a/internal/format/testdata/xml/xml-OnlyModulecalls.golden b/internal/format/testdata/xml/xml-OnlyModulecalls.golden index bf9e212..72cc145 100644 --- a/internal/format/testdata/xml/xml-OnlyModulecalls.golden +++ b/internal/format/testdata/xml/xml-OnlyModulecalls.golden @@ -3,16 +3,16 @@
- - foo - bar - 1.2.3 - bar baz 4.5.6 + + foo + bar + 1.2.3 + baz baz @@ -23,4 +23,4 @@ - \ No newline at end of file + diff --git a/internal/format/testdata/xml/xml-OnlyResources.golden b/internal/format/testdata/xml/xml-OnlyResources.golden index 2f1b4f5..98ab2b6 100644 --- a/internal/format/testdata/xml/xml-OnlyResources.golden +++ b/internal/format/testdata/xml/xml-OnlyResources.golden @@ -40,4 +40,4 @@ latest - \ No newline at end of file + diff --git a/internal/format/testdata/yaml/yaml-Base.golden b/internal/format/testdata/yaml/yaml-Base.golden index bf41f4f..349fa2e 100644 --- a/internal/format/testdata/yaml/yaml-Base.golden +++ b/internal/format/testdata/yaml/yaml-Base.golden @@ -225,12 +225,12 @@ inputs: default: {} required: false modules: - - name: foo - source: bar - version: 1.2.3 - name: bar source: baz version: 4.5.6 + - name: foo + source: bar + version: 1.2.3 - name: baz source: baz version: 4.5.6 @@ -287,4 +287,4 @@ resources: providerName: aws providerSource: hashicorp/aws mode: data - version: latest \ No newline at end of file + version: latest diff --git a/internal/format/testdata/yaml/yaml-OnlyModulecalls.golden b/internal/format/testdata/yaml/yaml-OnlyModulecalls.golden index c0cb028..6d48d86 100644 --- a/internal/format/testdata/yaml/yaml-OnlyModulecalls.golden +++ b/internal/format/testdata/yaml/yaml-OnlyModulecalls.golden @@ -2,12 +2,12 @@ header: "" footer: "" inputs: [] modules: - - name: foo - source: bar - version: 1.2.3 - name: bar source: baz version: 4.5.6 + - name: foo + source: bar + version: 1.2.3 - name: baz source: baz version: 4.5.6 diff --git a/internal/format/testdata/yaml/yaml-OnlyResources.golden b/internal/format/testdata/yaml/yaml-OnlyResources.golden index dd1d32f..85ef85e 100644 --- a/internal/format/testdata/yaml/yaml-OnlyResources.golden +++ b/internal/format/testdata/yaml/yaml-OnlyResources.golden @@ -29,4 +29,4 @@ resources: providerName: aws providerSource: hashicorp/aws mode: data - version: latest \ No newline at end of file + version: latest diff --git a/internal/terraform/module.go b/internal/terraform/module.go index 68e023f..2e47fb6 100644 --- a/internal/terraform/module.go +++ b/internal/terraform/module.go @@ -292,15 +292,19 @@ func loadInputs(tfmodule *tfconfig.Module) ([]*Input, []*Input, []*Input) { } func loadModulecalls(tfmodule *tfconfig.Module) []*ModuleCall { - var modulecalls = make([]*ModuleCall, 0) - for _, modulecall := range tfmodule.ModuleCalls { - modulecalls = append(modulecalls, &ModuleCall{ - Name: modulecall.Name, - Source: modulecall.Source, - Version: modulecall.Version, + var modules = make([]*ModuleCall, 0) + for _, m := range tfmodule.ModuleCalls { + modules = append(modules, &ModuleCall{ + Name: m.Name, + Source: m.Source, + Version: m.Version, + Position: Position{ + Filename: m.Pos.Filename, + Line: m.Pos.Line, + }, }) } - return modulecalls + return modules } func loadOutputs(tfmodule *tfconfig.Module, options *Options) ([]*Output, error) { @@ -534,7 +538,9 @@ func sortItems(tfmodule *Module, sortby *SortBy) { // modules if sortby.Name || sortby.Required { sort.Sort(modulecallsSortedByName(tfmodule.ModuleCalls)) - } else { + } else if sortby.Type { sort.Sort(modulecallsSortedBySource(tfmodule.ModuleCalls)) + } else { + sort.Sort(modulecallsSortedByPosition(tfmodule.ModuleCalls)) } } diff --git a/internal/terraform/modulecall.go b/internal/terraform/modulecall.go index 7834c76..ad04cca 100644 --- a/internal/terraform/modulecall.go +++ b/internal/terraform/modulecall.go @@ -18,9 +18,10 @@ import ( // ModuleCall represents a submodule called by Terraform module. type ModuleCall struct { - Name string `json:"name"` - Source string `json:"source"` - Version string `json:"version,omitempty"` + Name string `json:"name"` + Source string `json:"source"` + Version string `json:"version,omitempty"` + Position Position `json:"-" toml:"-" xml:"-" yaml:"-"` } // FullName returns full name of the modulecall, with version if available @@ -33,11 +34,9 @@ func (mc *ModuleCall) FullName() string { 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 -} +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 @@ -50,6 +49,14 @@ func (a modulecallsSortedBySource) Less(i, j int) bool { return a[i].Source < a[j].Source } +type modulecallsSortedByPosition []*ModuleCall + +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 +} + type modulecalls []*ModuleCall func (mm modulecalls) convert() []*terraformsdk.ModuleCall { @@ -59,6 +66,10 @@ func (mm modulecalls) convert() []*terraformsdk.ModuleCall { Name: m.Name, Source: m.Source, Version: m.Version, + Position: terraformsdk.Position{ + Filename: m.Position.Filename, + Line: m.Position.Line, + }, }) } return list diff --git a/internal/terraform/modulecall_test.go b/internal/terraform/modulecall_test.go index 82f86e9..3ac53e2 100644 --- a/internal/terraform/modulecall_test.go +++ b/internal/terraform/modulecall_test.go @@ -11,26 +11,114 @@ the root directory of this source tree. package terraform import ( + "sort" "testing" "github.com/stretchr/testify/assert" ) -func TestModulecallNameWithoutVersion(t *testing.T) { - assert := assert.New(t) - modulecall := ModuleCall{ - Name: "provider", - Source: "bar", +func TestModulecallName(t *testing.T) { + tests := map[string]struct { + module ModuleCall + expected string + }{ + "WithoutVersion": { + module: ModuleCall{ + Name: "provider", + Source: "bar", + }, + expected: "bar", + }, + "WithVersion": { + module: ModuleCall{ + Name: "provider", + Source: "bar", + Version: "1.2.3", + }, + expected: "bar,1.2.3", + }, + } + for name, tt := range tests { + t.Run(name, func(t *testing.T) { + assert := assert.New(t) + assert.Equal(tt.expected, tt.module.FullName()) + }) } - assert.Equal("bar", modulecall.FullName()) } -func TestModulecallNameWithVersion(t *testing.T) { - assert := assert.New(t) - modulecall := ModuleCall{ - Name: "provider", - Source: "bar", - Version: "1.2.3", +func TestModulecallSort(t *testing.T) { + modules := sampleModulecalls() + tests := map[string]struct { + sortType sort.Interface + expected []string + }{ + "ByName": { + sortType: modulecallsSortedByName(modules), + expected: []string{"a", "b", "c", "d", "e", "f"}, + }, + "BySource": { + sortType: modulecallsSortedBySource(modules), + expected: []string{"f", "d", "c", "e", "a", "b"}, + }, + "ByPosition": { + sortType: modulecallsSortedByPosition(modules), + expected: []string{"b", "c", "a", "e", "d", "f"}, + }, + } + for name, tt := range tests { + t.Run(name, func(t *testing.T) { + assert := assert.New(t) + + sort.Sort(tt.sortType) + + actual := make([]string, len(modules)) + + for k, i := range modules { + actual[k] = i.Name + } + + assert.Equal(tt.expected, actual) + }) + } +} + +func sampleModulecalls() []*ModuleCall { + return []*ModuleCall{ + { + Name: "a", + Source: "z", + Version: "1.2.3", + Position: Position{Filename: "foo/main.tf", Line: 35}, + }, + { + Name: "b", + Source: "z", + Version: "1.2.3", + Position: Position{Filename: "foo/main.tf", Line: 10}, + }, + { + Name: "c", + Source: "m", + Version: "1.2.3", + Position: Position{Filename: "foo/main.tf", Line: 23}, + }, + { + Name: "e", + Source: "x", + Version: "1.2.3", + Position: Position{Filename: "foo/main.tf", Line: 42}, + }, + { + Name: "d", + Source: "l", + Version: "1.2.3", + Position: Position{Filename: "foo/main.tf", Line: 51}, + }, + { + Name: "f", + Source: "a", + Version: "1.2.3", + Position: Position{Filename: "foo/main.tf", Line: 59}, + }, } - assert.Equal("bar,1.2.3", modulecall.FullName()) }