diff --git a/configs/configload/loader_install_test.go b/configs/configload/loader_install_test.go index 2be85a6ba..e0e6bdf98 100644 --- a/configs/configload/loader_install_test.go +++ b/configs/configload/loader_install_test.go @@ -3,9 +3,11 @@ package configload import ( "os" "path/filepath" + "strings" "testing" version "github.com/hashicorp/go-version" + "github.com/hashicorp/terraform/configs" ) func TestLoaderInstallModules_local(t *testing.T) { @@ -39,8 +41,25 @@ func TestLoaderInstallModules_local(t *testing.T) { // Make sure the configuration is loadable now. // (This ensures that correct information is recorded in the manifest.) - _, loadDiags := loader.LoadConfig(".") + config, loadDiags := loader.LoadConfig(".") assertNoDiagnostics(t, loadDiags) + + wantTraces := map[string]string{ + "": "in root module", + "child_a": "in child_a module", + "child_a.child_b": "in child_b module", + } + gotTraces := map[string]string{} + config.DeepEach(func(c *configs.Config) { + path := strings.Join(c.Path, ".") + if c.Module.Variables["v"] == nil { + gotTraces[path] = "" + return + } + varDesc := c.Module.Variables["v"].Description + gotTraces[path] = varDesc + }) + assertResultDeepEqual(t, gotTraces, wantTraces) } func TestLoaderInstallModules_registry(t *testing.T) { @@ -136,8 +155,30 @@ func TestLoaderInstallModules_registry(t *testing.T) { // Make sure the configuration is loadable now. // (This ensures that correct information is recorded in the manifest.) - _, loadDiags := loader.LoadConfig(".") + config, loadDiags := loader.LoadConfig(".") assertNoDiagnostics(t, loadDiags) + + wantTraces := map[string]string{ + "": "in local caller for registry-modules", + "acctest_root": "in root module", + "acctest_root.child_a": "in child_a module", + "acctest_root.child_a.child_b": "in child_b module", + "acctest_child_a": "in child_a module", + "acctest_child_a.child_b": "in child_b module", + "acctest_child_b": "in child_b module", + } + gotTraces := map[string]string{} + config.DeepEach(func(c *configs.Config) { + path := strings.Join(c.Path, ".") + if c.Module.Variables["v"] == nil { + gotTraces[path] = "" + return + } + varDesc := c.Module.Variables["v"].Description + gotTraces[path] = varDesc + }) + assertResultDeepEqual(t, gotTraces, wantTraces) + } func TestLoaderInstallModules_goGetter(t *testing.T) { @@ -225,8 +266,30 @@ func TestLoaderInstallModules_goGetter(t *testing.T) { // Make sure the configuration is loadable now. // (This ensures that correct information is recorded in the manifest.) - _, loadDiags := loader.LoadConfig(".") + config, loadDiags := loader.LoadConfig(".") assertNoDiagnostics(t, loadDiags) + + wantTraces := map[string]string{ + "": "in local caller for go-getter-modules", + "acctest_root": "in root module", + "acctest_root.child_a": "in child_a module", + "acctest_root.child_a.child_b": "in child_b module", + "acctest_child_a": "in child_a module", + "acctest_child_a.child_b": "in child_b module", + "acctest_child_b": "in child_b module", + } + gotTraces := map[string]string{} + config.DeepEach(func(c *configs.Config) { + path := strings.Join(c.Path, ".") + if c.Module.Variables["v"] == nil { + gotTraces[path] = "" + return + } + varDesc := c.Module.Variables["v"].Description + gotTraces[path] = varDesc + }) + assertResultDeepEqual(t, gotTraces, wantTraces) + } type testInstallHooks struct { diff --git a/configs/configload/test-fixtures/go-getter-modules/root.tf b/configs/configload/test-fixtures/go-getter-modules/root.tf index 3c92ef1db..9b174a7a5 100644 --- a/configs/configload/test-fixtures/go-getter-modules/root.tf +++ b/configs/configload/test-fixtures/go-getter-modules/root.tf @@ -3,6 +3,11 @@ # ...and expects its v0.0.1 tag to be pointing at the following commit: # d676ab2559d4e0621d59e3c3c4cbb33958ac4608 +variable "v" { + description = "in local caller for go-getter-modules" + default = "" +} + module "acctest_root" { source = "github.com/hashicorp/terraform-aws-module-installer-acctest?ref=v0.0.1" } diff --git a/configs/configload/test-fixtures/local-modules/child_a/child_a.tf b/configs/configload/test-fixtures/local-modules/child_a/child_a.tf index eb2c0044f..68ebb8e40 100644 --- a/configs/configload/test-fixtures/local-modules/child_a/child_a.tf +++ b/configs/configload/test-fixtures/local-modules/child_a/child_a.tf @@ -1,4 +1,9 @@ +variable "v" { + description = "in child_a module" + default = "" +} + module "child_b" { source = "./child_b" } diff --git a/configs/configload/test-fixtures/local-modules/child_a/child_b/child_b.tf b/configs/configload/test-fixtures/local-modules/child_a/child_b/child_b.tf index 4900e9796..e2e220916 100644 --- a/configs/configload/test-fixtures/local-modules/child_a/child_b/child_b.tf +++ b/configs/configload/test-fixtures/local-modules/child_a/child_b/child_b.tf @@ -1,4 +1,9 @@ +variable "v" { + description = "in child_b module" + default = "" +} + output "hello" { value = "Hello from child_b!" } diff --git a/configs/configload/test-fixtures/local-modules/root.tf b/configs/configload/test-fixtures/local-modules/root.tf index 1a6721b5d..3b4c6416d 100644 --- a/configs/configload/test-fixtures/local-modules/root.tf +++ b/configs/configload/test-fixtures/local-modules/root.tf @@ -1,4 +1,9 @@ +variable "v" { + description = "in root module" + default = "" +} + module "child_a" { source = "./child_a" } diff --git a/configs/configload/test-fixtures/registry-modules/root.tf b/configs/configload/test-fixtures/registry-modules/root.tf index 786966494..4b5ad1f1e 100644 --- a/configs/configload/test-fixtures/registry-modules/root.tf +++ b/configs/configload/test-fixtures/registry-modules/root.tf @@ -11,6 +11,12 @@ # 853d03855b3290a3ca491d4c3a7684572dd42237 # (this particular assumption is encoded in the tests that use this fixture) + +variable "v" { + description = "in local caller for registry-modules" + default = "" +} + module "acctest_root" { source = "hashicorp/module-installer-acctest/aws" version = "0.0.1"