From 0284283bd1996f412761be93a7f77f7ad4e7f9af Mon Sep 17 00:00:00 2001 From: "Edgar R. Sandi" Date: Thu, 25 Mar 2021 01:59:22 -0300 Subject: [PATCH] Separate the module version from module source when using `?ref=` Signed-off-by: Edgar R. Sandi --- docs/reference/asciidoc-document.md | 6 ++++ docs/reference/asciidoc-table.md | 1 + docs/reference/json.md | 5 ++++ docs/reference/markdown-document.md | 6 ++++ docs/reference/markdown-table.md | 1 + docs/reference/pretty.md | 1 + docs/reference/toml.md | 5 ++++ docs/reference/xml.md | 5 ++++ docs/reference/yaml.md | 3 ++ examples/main.tf | 4 +++ internal/format/templates/markdown_table.tmpl | 2 +- .../templates/markdown_table_modules.tmpl | 2 +- .../testdata/asciidoc/document-Base.golden | 6 ++++ .../document-IndentationOfFour.golden | 6 ++++ .../asciidoc/document-OnlyModulecalls.golden | 8 ++++- .../asciidoc/document-WithAnchor.golden | 6 ++++ .../asciidoc/document-WithRequired.golden | 6 ++++ .../testdata/asciidoc/table-Base.golden | 1 + .../asciidoc/table-IndentationOfFour.golden | 1 + .../asciidoc/table-OnlyModulecalls.golden | 1 + .../testdata/asciidoc/table-WithAnchor.golden | 1 + .../asciidoc/table-WithRequired.golden | 1 + .../format/testdata/common/sort-NoSort.golden | 3 +- .../testdata/common/sort-SortByName.golden | 3 +- .../common/sort-SortByRequired.golden | 3 +- .../testdata/common/sort-SortByType.golden | 3 +- .../format/testdata/json/json-Base.golden | 5 ++++ .../json/json-EscapeCharacters.golden | 5 ++++ .../testdata/json/json-OnlyModulecalls.golden | 5 ++++ .../testdata/markdown/document-Base.golden | 6 ++++ .../markdown/document-EscapeCharacters.golden | 6 ++++ .../document-IndentationOfFour.golden | 6 ++++ .../markdown/document-OnlyModulecalls.golden | 8 ++++- .../markdown/document-WithAnchor.golden | 6 ++++ .../markdown/document-WithRequired.golden | 6 ++++ .../testdata/markdown/table-Base.golden | 1 + .../markdown/table-EscapeCharacters.golden | 1 + .../markdown/table-IndentationOfFour.golden | 1 + .../markdown/table-OnlyModulecalls.golden | 3 +- .../testdata/markdown/table-WithAnchor.golden | 1 + .../markdown/table-WithRequired.golden | 1 + .../format/testdata/pretty/pretty-Base.golden | 1 + .../pretty/pretty-OnlyModulecalls.golden | 3 +- .../testdata/pretty/pretty-WithColor.golden | 1 + .../format/testdata/toml/toml-Base.golden | 5 ++++ .../testdata/toml/toml-OnlyModulecalls.golden | 7 ++++- internal/format/testdata/xml/xml-Base.golden | 5 ++++ .../testdata/xml/xml-OnlyModulecalls.golden | 5 ++++ .../format/testdata/yaml/yaml-Base.golden | 3 ++ .../testdata/yaml/yaml-OnlyModulecalls.golden | 3 ++ internal/terraform/module.go | 30 +++++++++++++++++-- internal/terraform/module_test.go | 2 +- .../terraform/testdata/full-example/main.tf | 6 +++- 53 files changed, 207 insertions(+), 15 deletions(-) diff --git a/docs/reference/asciidoc-document.md b/docs/reference/asciidoc-document.md index 2e8365ae..441735d0 100644 --- a/docs/reference/asciidoc-document.md +++ b/docs/reference/asciidoc-document.md @@ -137,6 +137,12 @@ generates the following output: Version: 1.2.3 + === [[module_foobar]] <> + + Source: git@github.com:module/path + + Version: v7.8.9 + == Resources The following resources are used by this module: diff --git a/docs/reference/asciidoc-table.md b/docs/reference/asciidoc-table.md index a25aac9d..65b6d330 100644 --- a/docs/reference/asciidoc-table.md +++ b/docs/reference/asciidoc-table.md @@ -122,6 +122,7 @@ generates the following output: |[[module_bar]] <>|baz|4.5.6 |[[module_baz]] <>|baz|4.5.6 |[[module_foo]] <>|bar|1.2.3 + |[[module_foobar]] <>|git@github.com:module/path|v7.8.9 |=== == Resources diff --git a/docs/reference/json.md b/docs/reference/json.md index ec8a71c0..005b57e7 100644 --- a/docs/reference/json.md +++ b/docs/reference/json.md @@ -312,6 +312,11 @@ generates the following output: "name": "foo", "source": "bar", "version": "1.2.3" + }, + { + "name": "foobar", + "source": "git@github.com:module/path", + "version": "v7.8.9" } ], "outputs": [ diff --git a/docs/reference/markdown-document.md b/docs/reference/markdown-document.md index 6e7810c3..ae409350 100644 --- a/docs/reference/markdown-document.md +++ b/docs/reference/markdown-document.md @@ -138,6 +138,12 @@ generates the following output: Version: 1.2.3 + ### [foobar](#module\_foobar) + + Source: git@github.com:module/path + + Version: v7.8.9 + ## Resources The following resources are used by this module: diff --git a/docs/reference/markdown-table.md b/docs/reference/markdown-table.md index af2f990d..833ba145 100644 --- a/docs/reference/markdown-table.md +++ b/docs/reference/markdown-table.md @@ -118,6 +118,7 @@ generates the following output: | [bar](#module\_bar) | baz | 4.5.6 | | [baz](#module\_baz) | baz | 4.5.6 | | [foo](#module\_foo) | bar | 1.2.3 | + | [foobar](#module\_foobar) | git@github.com:module/path | v7.8.9 | ## Resources diff --git a/docs/reference/pretty.md b/docs/reference/pretty.md index 5bccf7f8..8a143e7c 100644 --- a/docs/reference/pretty.md +++ b/docs/reference/pretty.md @@ -103,6 +103,7 @@ generates the following output: module.bar (baz,4.5.6) module.baz (baz,4.5.6) module.foo (bar,1.2.3) + module.foobar (git@github.com:module/path,v7.8.9) resource.null_resource.foo (resource) (https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) diff --git a/docs/reference/toml.md b/docs/reference/toml.md index 96b9237a..c23987f2 100644 --- a/docs/reference/toml.md +++ b/docs/reference/toml.md @@ -296,6 +296,11 @@ generates the following output: source = "bar" version = "1.2.3" + [[modules]] + name = "foobar" + source = "git@github.com:module/path" + version = "v7.8.9" + [[outputs]] name = "output-0.12" description = "terraform 0.12 only" diff --git a/docs/reference/xml.md b/docs/reference/xml.md index 67c0a11b..ce5b1ed6 100644 --- a/docs/reference/xml.md +++ b/docs/reference/xml.md @@ -312,6 +312,11 @@ generates the following output: bar 1.2.3 + + foobar + git@github.com:module/path + v7.8.9 + diff --git a/docs/reference/yaml.md b/docs/reference/yaml.md index 7c5ed8ce..a5f51310 100644 --- a/docs/reference/yaml.md +++ b/docs/reference/yaml.md @@ -285,6 +285,9 @@ generates the following output: - name: foo source: bar version: 1.2.3 + - name: foobar + source: git@github.com:module/path + version: v7.8.9 outputs: - name: output-0.12 description: terraform 0.12 only diff --git a/examples/main.tf b/examples/main.tf index c74d5494..b8f2d8dd 100644 --- a/examples/main.tf +++ b/examples/main.tf @@ -72,3 +72,7 @@ module "baz" { source = "baz" version = "4.5.6" } + +module "foobar" { + source = "git@github.com:module/path?ref=v7.8.9" +} diff --git a/internal/format/templates/markdown_table.tmpl b/internal/format/templates/markdown_table.tmpl index 690ebb8d..da6d3f96 100644 --- a/internal/format/templates/markdown_table.tmpl +++ b/internal/format/templates/markdown_table.tmpl @@ -5,4 +5,4 @@ {{- template "resources" . -}} {{- template "inputs" . -}} {{- template "outputs" . -}} -{{- template "footer" . -}} \ No newline at end of file +{{- template "footer" . -}} diff --git a/internal/format/templates/markdown_table_modules.tmpl b/internal/format/templates/markdown_table_modules.tmpl index 2a7b3007..d1443ea4 100644 --- a/internal/format/templates/markdown_table_modules.tmpl +++ b/internal/format/templates/markdown_table_modules.tmpl @@ -6,7 +6,7 @@ | Name | Source | Version | |------|--------|---------| {{- range .Module.ModuleCalls }} - | {{ anchorName "module" .Name }} | {{ .Source }} | {{ .Version }} | + | {{ anchorName "module" .Name }} | {{ .Source }} | {{ .Version | default "n/a" }} | {{- end }} {{ end }} {{ end -}} \ No newline at end of file diff --git a/internal/format/testdata/asciidoc/document-Base.golden b/internal/format/testdata/asciidoc/document-Base.golden index 538fdfe1..861600bb 100644 --- a/internal/format/testdata/asciidoc/document-Base.golden +++ b/internal/format/testdata/asciidoc/document-Base.golden @@ -80,6 +80,12 @@ Source: baz Version: 4.5.6 +=== foobar + +Source: git@github.com:module/path + +Version: v7.8.9 + == Resources The following resources are used by this module: diff --git a/internal/format/testdata/asciidoc/document-IndentationOfFour.golden b/internal/format/testdata/asciidoc/document-IndentationOfFour.golden index 57acf5c9..b810a379 100644 --- a/internal/format/testdata/asciidoc/document-IndentationOfFour.golden +++ b/internal/format/testdata/asciidoc/document-IndentationOfFour.golden @@ -80,6 +80,12 @@ Source: baz Version: 4.5.6 +===== foobar + +Source: git@github.com:module/path + +Version: v7.8.9 + ==== Resources The following resources are used by this module: diff --git a/internal/format/testdata/asciidoc/document-OnlyModulecalls.golden b/internal/format/testdata/asciidoc/document-OnlyModulecalls.golden index bea2517b..d575617e 100644 --- a/internal/format/testdata/asciidoc/document-OnlyModulecalls.golden +++ b/internal/format/testdata/asciidoc/document-OnlyModulecalls.golden @@ -18,4 +18,10 @@ Version: 1.2.3 Source: baz -Version: 4.5.6 \ No newline at end of file +Version: 4.5.6 + +=== foobar + +Source: git@github.com:module/path + +Version: v7.8.9 \ No newline at end of file diff --git a/internal/format/testdata/asciidoc/document-WithAnchor.golden b/internal/format/testdata/asciidoc/document-WithAnchor.golden index e95019d8..47aa14ce 100644 --- a/internal/format/testdata/asciidoc/document-WithAnchor.golden +++ b/internal/format/testdata/asciidoc/document-WithAnchor.golden @@ -80,6 +80,12 @@ Source: baz Version: 4.5.6 +=== [[module_foobar]] <> + +Source: git@github.com:module/path + +Version: v7.8.9 + == Resources The following resources are used by this module: diff --git a/internal/format/testdata/asciidoc/document-WithRequired.golden b/internal/format/testdata/asciidoc/document-WithRequired.golden index 95031f71..d314416b 100644 --- a/internal/format/testdata/asciidoc/document-WithRequired.golden +++ b/internal/format/testdata/asciidoc/document-WithRequired.golden @@ -80,6 +80,12 @@ Source: baz Version: 4.5.6 +=== foobar + +Source: git@github.com:module/path + +Version: v7.8.9 + == Resources The following resources are used by this module: diff --git a/internal/format/testdata/asciidoc/table-Base.golden b/internal/format/testdata/asciidoc/table-Base.golden index 979e8265..7219ab9f 100644 --- a/internal/format/testdata/asciidoc/table-Base.golden +++ b/internal/format/testdata/asciidoc/table-Base.golden @@ -65,6 +65,7 @@ followed by another line of text. |bar|baz|4.5.6 |foo|bar|1.2.3 |baz|baz|4.5.6 +|foobar|git@github.com:module/path|v7.8.9 |=== == Resources diff --git a/internal/format/testdata/asciidoc/table-IndentationOfFour.golden b/internal/format/testdata/asciidoc/table-IndentationOfFour.golden index 51442c5a..068e0c8d 100644 --- a/internal/format/testdata/asciidoc/table-IndentationOfFour.golden +++ b/internal/format/testdata/asciidoc/table-IndentationOfFour.golden @@ -65,6 +65,7 @@ followed by another line of text. |bar|baz|4.5.6 |foo|bar|1.2.3 |baz|baz|4.5.6 +|foobar|git@github.com:module/path|v7.8.9 |=== ==== Resources diff --git a/internal/format/testdata/asciidoc/table-OnlyModulecalls.golden b/internal/format/testdata/asciidoc/table-OnlyModulecalls.golden index 6ae6fb66..8a30eb62 100644 --- a/internal/format/testdata/asciidoc/table-OnlyModulecalls.golden +++ b/internal/format/testdata/asciidoc/table-OnlyModulecalls.golden @@ -6,4 +6,5 @@ |bar|baz|4.5.6 |foo|bar|1.2.3 |baz|baz|4.5.6 +|foobar|git@github.com:module/path|v7.8.9 |=== \ 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 8cad22af..b4c23d04 100644 --- a/internal/format/testdata/asciidoc/table-WithAnchor.golden +++ b/internal/format/testdata/asciidoc/table-WithAnchor.golden @@ -65,6 +65,7 @@ followed by another line of text. |[[module_bar]] <>|baz|4.5.6 |[[module_foo]] <>|bar|1.2.3 |[[module_baz]] <>|baz|4.5.6 +|[[module_foobar]] <>|git@github.com:module/path|v7.8.9 |=== == Resources diff --git a/internal/format/testdata/asciidoc/table-WithRequired.golden b/internal/format/testdata/asciidoc/table-WithRequired.golden index e0157647..cc20a08c 100644 --- a/internal/format/testdata/asciidoc/table-WithRequired.golden +++ b/internal/format/testdata/asciidoc/table-WithRequired.golden @@ -65,6 +65,7 @@ followed by another line of text. |bar|baz|4.5.6 |foo|bar|1.2.3 |baz|baz|4.5.6 +|foobar|git@github.com:module/path|v7.8.9 |=== == Resources diff --git a/internal/format/testdata/common/sort-NoSort.golden b/internal/format/testdata/common/sort-NoSort.golden index 74d14315..8ab0a85d 100644 --- a/internal/format/testdata/common/sort-NoSort.golden +++ b/internal/format/testdata/common/sort-NoSort.golden @@ -35,7 +35,8 @@ "modules": [ "bar-baz", "foo-bar", - "baz-baz" + "baz-baz", + "foobar-git@github.com:module/path" ], "outputs": [ "unquoted", diff --git a/internal/format/testdata/common/sort-SortByName.golden b/internal/format/testdata/common/sort-SortByName.golden index 7a6d73eb..29ac9c12 100644 --- a/internal/format/testdata/common/sort-SortByName.golden +++ b/internal/format/testdata/common/sort-SortByName.golden @@ -35,7 +35,8 @@ "modules": [ "bar-baz", "baz-baz", - "foo-bar" + "foo-bar", + "foobar-git@github.com:module/path" ], "outputs": [ "output-0.12", diff --git a/internal/format/testdata/common/sort-SortByRequired.golden b/internal/format/testdata/common/sort-SortByRequired.golden index 71a9079f..1e3b623a 100644 --- a/internal/format/testdata/common/sort-SortByRequired.golden +++ b/internal/format/testdata/common/sort-SortByRequired.golden @@ -35,7 +35,8 @@ "modules": [ "bar-baz", "baz-baz", - "foo-bar" + "foo-bar", + "foobar-git@github.com:module/path" ], "outputs": [ "output-0.12", diff --git a/internal/format/testdata/common/sort-SortByType.golden b/internal/format/testdata/common/sort-SortByType.golden index 0421ed08..7edaf076 100644 --- a/internal/format/testdata/common/sort-SortByType.golden +++ b/internal/format/testdata/common/sort-SortByType.golden @@ -35,7 +35,8 @@ "modules": [ "foo-bar", "bar-baz", - "baz-baz" + "baz-baz", + "foobar-git@github.com:module/path" ], "outputs": [ "output-0.12", diff --git a/internal/format/testdata/json/json-Base.golden b/internal/format/testdata/json/json-Base.golden index 8c47aad8..393aaae6 100644 --- a/internal/format/testdata/json/json-Base.golden +++ b/internal/format/testdata/json/json-Base.golden @@ -260,6 +260,11 @@ "name": "baz", "source": "baz", "version": "4.5.6" + }, + { + "name": "foobar", + "source": "git@github.com:module/path", + "version": "v7.8.9" } ], "outputs": [ diff --git a/internal/format/testdata/json/json-EscapeCharacters.golden b/internal/format/testdata/json/json-EscapeCharacters.golden index 4cf9664c..cdc99a73 100644 --- a/internal/format/testdata/json/json-EscapeCharacters.golden +++ b/internal/format/testdata/json/json-EscapeCharacters.golden @@ -260,6 +260,11 @@ "name": "baz", "source": "baz", "version": "4.5.6" + }, + { + "name": "foobar", + "source": "git@github.com:module/path", + "version": "v7.8.9" } ], "outputs": [ diff --git a/internal/format/testdata/json/json-OnlyModulecalls.golden b/internal/format/testdata/json/json-OnlyModulecalls.golden index 794e541b..0cf5df67 100644 --- a/internal/format/testdata/json/json-OnlyModulecalls.golden +++ b/internal/format/testdata/json/json-OnlyModulecalls.golden @@ -17,6 +17,11 @@ "name": "baz", "source": "baz", "version": "4.5.6" + }, + { + "name": "foobar", + "source": "git@github.com:module/path", + "version": "v7.8.9" } ], "outputs": [], diff --git a/internal/format/testdata/markdown/document-Base.golden b/internal/format/testdata/markdown/document-Base.golden index 902a64fb..b0208e3d 100644 --- a/internal/format/testdata/markdown/document-Base.golden +++ b/internal/format/testdata/markdown/document-Base.golden @@ -80,6 +80,12 @@ Source: baz Version: 4.5.6 +### foobar + +Source: git@github.com:module/path + +Version: v7.8.9 + ## Resources The following resources are used by this module: diff --git a/internal/format/testdata/markdown/document-EscapeCharacters.golden b/internal/format/testdata/markdown/document-EscapeCharacters.golden index cd6677d7..52828b83 100644 --- a/internal/format/testdata/markdown/document-EscapeCharacters.golden +++ b/internal/format/testdata/markdown/document-EscapeCharacters.golden @@ -80,6 +80,12 @@ Source: baz Version: 4.5.6 +### foobar + +Source: git@github.com:module/path + +Version: v7.8.9 + ## Resources The following resources are used by this module: diff --git a/internal/format/testdata/markdown/document-IndentationOfFour.golden b/internal/format/testdata/markdown/document-IndentationOfFour.golden index bcf07b60..25ca644e 100644 --- a/internal/format/testdata/markdown/document-IndentationOfFour.golden +++ b/internal/format/testdata/markdown/document-IndentationOfFour.golden @@ -80,6 +80,12 @@ Source: baz Version: 4.5.6 +##### foobar + +Source: git@github.com:module/path + +Version: v7.8.9 + #### Resources The following resources are used by this module: diff --git a/internal/format/testdata/markdown/document-OnlyModulecalls.golden b/internal/format/testdata/markdown/document-OnlyModulecalls.golden index 9fa9dc76..3903e55a 100644 --- a/internal/format/testdata/markdown/document-OnlyModulecalls.golden +++ b/internal/format/testdata/markdown/document-OnlyModulecalls.golden @@ -18,4 +18,10 @@ Version: 1.2.3 Source: baz -Version: 4.5.6 \ No newline at end of file +Version: 4.5.6 + +### foobar + +Source: git@github.com:module/path + +Version: v7.8.9 \ No newline at end of file diff --git a/internal/format/testdata/markdown/document-WithAnchor.golden b/internal/format/testdata/markdown/document-WithAnchor.golden index 55140419..b4f23ee9 100644 --- a/internal/format/testdata/markdown/document-WithAnchor.golden +++ b/internal/format/testdata/markdown/document-WithAnchor.golden @@ -80,6 +80,12 @@ Source: baz Version: 4.5.6 +### [foobar](#module_foobar) + +Source: git@github.com:module/path + +Version: v7.8.9 + ## Resources The following resources are used by this module: diff --git a/internal/format/testdata/markdown/document-WithRequired.golden b/internal/format/testdata/markdown/document-WithRequired.golden index 8fe99569..7444d287 100644 --- a/internal/format/testdata/markdown/document-WithRequired.golden +++ b/internal/format/testdata/markdown/document-WithRequired.golden @@ -80,6 +80,12 @@ Source: baz Version: 4.5.6 +### foobar + +Source: git@github.com:module/path + +Version: v7.8.9 + ## Resources The following resources are used by this module: diff --git a/internal/format/testdata/markdown/table-Base.golden b/internal/format/testdata/markdown/table-Base.golden index 56f2c5d5..ae8177c2 100644 --- a/internal/format/testdata/markdown/table-Base.golden +++ b/internal/format/testdata/markdown/table-Base.golden @@ -60,6 +60,7 @@ followed by another line of text. | bar | baz | 4.5.6 | | foo | bar | 1.2.3 | | baz | baz | 4.5.6 | +| foobar | git@github.com:module/path | v7.8.9 | ## Resources diff --git a/internal/format/testdata/markdown/table-EscapeCharacters.golden b/internal/format/testdata/markdown/table-EscapeCharacters.golden index c3306593..ce62b7e6 100644 --- a/internal/format/testdata/markdown/table-EscapeCharacters.golden +++ b/internal/format/testdata/markdown/table-EscapeCharacters.golden @@ -60,6 +60,7 @@ followed by another line of text. | bar | baz | 4.5.6 | | foo | bar | 1.2.3 | | baz | baz | 4.5.6 | +| foobar | git@github.com:module/path | v7.8.9 | ## Resources diff --git a/internal/format/testdata/markdown/table-IndentationOfFour.golden b/internal/format/testdata/markdown/table-IndentationOfFour.golden index fdb38b32..fdff09a4 100644 --- a/internal/format/testdata/markdown/table-IndentationOfFour.golden +++ b/internal/format/testdata/markdown/table-IndentationOfFour.golden @@ -60,6 +60,7 @@ followed by another line of text. | bar | baz | 4.5.6 | | foo | bar | 1.2.3 | | baz | baz | 4.5.6 | +| foobar | git@github.com:module/path | v7.8.9 | #### Resources diff --git a/internal/format/testdata/markdown/table-OnlyModulecalls.golden b/internal/format/testdata/markdown/table-OnlyModulecalls.golden index e710ac8a..233c728e 100644 --- a/internal/format/testdata/markdown/table-OnlyModulecalls.golden +++ b/internal/format/testdata/markdown/table-OnlyModulecalls.golden @@ -4,4 +4,5 @@ |------|--------|---------| | bar | baz | 4.5.6 | | foo | bar | 1.2.3 | -| baz | baz | 4.5.6 | \ No newline at end of file +| baz | baz | 4.5.6 | +| foobar | git@github.com:module/path | v7.8.9 | \ 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 672aa31f..1d64b1de 100644 --- a/internal/format/testdata/markdown/table-WithAnchor.golden +++ b/internal/format/testdata/markdown/table-WithAnchor.golden @@ -60,6 +60,7 @@ followed by another line of text. | [bar](#module_bar) | baz | 4.5.6 | | [foo](#module_foo) | bar | 1.2.3 | | [baz](#module_baz) | baz | 4.5.6 | +| [foobar](#module_foobar) | git@github.com:module/path | v7.8.9 | ## Resources diff --git a/internal/format/testdata/markdown/table-WithRequired.golden b/internal/format/testdata/markdown/table-WithRequired.golden index 28c65ccc..2f8905f7 100644 --- a/internal/format/testdata/markdown/table-WithRequired.golden +++ b/internal/format/testdata/markdown/table-WithRequired.golden @@ -60,6 +60,7 @@ followed by another line of text. | bar | baz | 4.5.6 | | foo | bar | 1.2.3 | | baz | baz | 4.5.6 | +| foobar | git@github.com:module/path | v7.8.9 | ## Resources diff --git a/internal/format/testdata/pretty/pretty-Base.golden b/internal/format/testdata/pretty/pretty-Base.golden index cea30303..9f74c6f2 100644 --- a/internal/format/testdata/pretty/pretty-Base.golden +++ b/internal/format/testdata/pretty/pretty-Base.golden @@ -51,6 +51,7 @@ provider.null module.bar (baz,4.5.6) module.foo (bar,1.2.3) module.baz (baz,4.5.6) +module.foobar (git@github.com:module/path,v7.8.9) resource.null_resource.foo (resource) (https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) diff --git a/internal/format/testdata/pretty/pretty-OnlyModulecalls.golden b/internal/format/testdata/pretty/pretty-OnlyModulecalls.golden index e1bfab37..0190ea73 100644 --- a/internal/format/testdata/pretty/pretty-OnlyModulecalls.golden +++ b/internal/format/testdata/pretty/pretty-OnlyModulecalls.golden @@ -1,3 +1,4 @@ module.bar (baz,4.5.6) module.foo (bar,1.2.3) -module.baz (baz,4.5.6) \ No newline at end of file +module.baz (baz,4.5.6) +module.foobar (git@github.com:module/path,v7.8.9) \ No newline at end of file diff --git a/internal/format/testdata/pretty/pretty-WithColor.golden b/internal/format/testdata/pretty/pretty-WithColor.golden index a449a5fa..891ad883 100644 --- a/internal/format/testdata/pretty/pretty-WithColor.golden +++ b/internal/format/testdata/pretty/pretty-WithColor.golden @@ -51,6 +51,7 @@ followed by another line of text. module.bar (baz,4.5.6) module.foo (bar,1.2.3) module.baz (baz,4.5.6) +module.foobar (git@github.com:module/path,v7.8.9) resource.null_resource.foo (resource) (https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) diff --git a/internal/format/testdata/toml/toml-Base.golden b/internal/format/testdata/toml/toml-Base.golden index 14f3b602..cef684c7 100644 --- a/internal/format/testdata/toml/toml-Base.golden +++ b/internal/format/testdata/toml/toml-Base.golden @@ -245,6 +245,11 @@ footer = "## This is an example of a footer\n\nIt looks exactly like a header, b source = "baz" version = "4.5.6" +[[modules]] + name = "foobar" + source = "git@github.com:module/path" + version = "v7.8.9" + [[outputs]] name = "unquoted" description = "It's unquoted output." diff --git a/internal/format/testdata/toml/toml-OnlyModulecalls.golden b/internal/format/testdata/toml/toml-OnlyModulecalls.golden index bbdc3ff4..df27b2b5 100644 --- a/internal/format/testdata/toml/toml-OnlyModulecalls.golden +++ b/internal/format/testdata/toml/toml-OnlyModulecalls.golden @@ -19,4 +19,9 @@ resources = [] [[modules]] name = "baz" source = "baz" - version = "4.5.6" \ No newline at end of file + version = "4.5.6" + +[[modules]] + name = "foobar" + source = "git@github.com:module/path" + version = "v7.8.9" \ No newline at end of file diff --git a/internal/format/testdata/xml/xml-Base.golden b/internal/format/testdata/xml/xml-Base.golden index 7e5b1c88..c9e26683 100644 --- a/internal/format/testdata/xml/xml-Base.golden +++ b/internal/format/testdata/xml/xml-Base.golden @@ -261,6 +261,11 @@ baz 4.5.6 + + foobar + git@github.com:module/path + v7.8.9 + diff --git a/internal/format/testdata/xml/xml-OnlyModulecalls.golden b/internal/format/testdata/xml/xml-OnlyModulecalls.golden index ba9d3ca4..a646ec43 100644 --- a/internal/format/testdata/xml/xml-OnlyModulecalls.golden +++ b/internal/format/testdata/xml/xml-OnlyModulecalls.golden @@ -18,6 +18,11 @@ baz 4.5.6 + + foobar + git@github.com:module/path + v7.8.9 + diff --git a/internal/format/testdata/yaml/yaml-Base.golden b/internal/format/testdata/yaml/yaml-Base.golden index 94a498bd..2ee44f62 100644 --- a/internal/format/testdata/yaml/yaml-Base.golden +++ b/internal/format/testdata/yaml/yaml-Base.golden @@ -234,6 +234,9 @@ modules: - name: baz source: baz version: 4.5.6 + - name: foobar + source: git@github.com:module/path + version: v7.8.9 outputs: - name: unquoted description: It's unquoted output. diff --git a/internal/format/testdata/yaml/yaml-OnlyModulecalls.golden b/internal/format/testdata/yaml/yaml-OnlyModulecalls.golden index 6d48d869..939bbf4a 100644 --- a/internal/format/testdata/yaml/yaml-OnlyModulecalls.golden +++ b/internal/format/testdata/yaml/yaml-OnlyModulecalls.golden @@ -11,6 +11,9 @@ modules: - name: baz source: baz version: 4.5.6 + - name: foobar + source: git@github.com:module/path + version: v7.8.9 outputs: [] providers: [] requirements: [] diff --git a/internal/terraform/module.go b/internal/terraform/module.go index f434732e..2775e332 100644 --- a/internal/terraform/module.go +++ b/internal/terraform/module.go @@ -299,13 +299,39 @@ func loadInputs(tfmodule *tfconfig.Module) ([]*Input, []*Input, []*Input) { return inputs, required, optional } +func formatSource(s, v string) (source, version string) { + substr := "?ref=" + + if v != "" { + return s, v + } + + pos := strings.LastIndex(s, substr) + if pos == -1 { + return s, version + } + + adjustedPos := pos + len(substr) + if adjustedPos >= len(s) { + return s, version + } + + source = s[0:pos] + version = s[adjustedPos:] + + return source, version +} + func loadModulecalls(tfmodule *tfconfig.Module) []*ModuleCall { var modules = make([]*ModuleCall, 0) + var source, version string + for _, m := range tfmodule.ModuleCalls { + source, version = formatSource(m.Source, m.Version) modules = append(modules, &ModuleCall{ Name: m.Name, - Source: m.Source, - Version: m.Version, + Source: source, + Version: version, Position: Position{ Filename: m.Pos.Filename, Line: m.Pos.Line, diff --git a/internal/terraform/module_test.go b/internal/terraform/module_test.go index e0c3f34d..c2b9bf66 100644 --- a/internal/terraform/module_test.go +++ b/internal/terraform/module_test.go @@ -515,7 +515,7 @@ func TestLoadModulecalls(t *testing.T) { { name: "load modulecalls from path", path: "full-example", - expected: 1, + expected: 2, }, { name: "load modulecalls from path", diff --git a/internal/terraform/testdata/full-example/main.tf b/internal/terraform/testdata/full-example/main.tf index 68c29cf2..a05236ad 100644 --- a/internal/terraform/testdata/full-example/main.tf +++ b/internal/terraform/testdata/full-example/main.tf @@ -26,4 +26,8 @@ resource "null_resource" "foo" {} module "foo" { source = "bar" version = "1.2.3" -} \ No newline at end of file +} + +module "foobar" { + source = "git@github.com:module/path?ref=v7.8.9" +}