github.com/gavinw2006/hashicorp-terraform@v0.11.12-beta1/configs/configload/loader_init_from_module_test.go (about) 1 package configload 2 3 import ( 4 "os" 5 "path/filepath" 6 "strings" 7 "testing" 8 9 version "github.com/hashicorp/go-version" 10 "github.com/hashicorp/terraform/configs" 11 ) 12 13 func TestLoaderInitDirFromModule_registry(t *testing.T) { 14 if os.Getenv("TF_ACC") == "" { 15 t.Skip("this test accesses registry.terraform.io and github.com; set TF_ACC=1 to run it") 16 } 17 18 fixtureDir := filepath.Clean("test-fixtures/empty") 19 loader, done := tempChdirLoader(t, fixtureDir) 20 defer done() 21 22 hooks := &testInstallHooks{} 23 24 diags := loader.InitDirFromModule(".", "hashicorp/module-installer-acctest/aws//examples/main", hooks) 25 assertNoDiagnostics(t, diags) 26 27 v := version.Must(version.NewVersion("0.0.1")) 28 29 wantCalls := []testInstallHookCall{ 30 // The module specified to populate the root directory is not mentioned 31 // here, because the hook mechanism is defined to talk about descendent 32 // modules only and so a caller to InitDirFromModule is expected to 33 // produce its own user-facing announcement about the root module being 34 // installed. 35 36 // Note that "root" in the following examples is, confusingly, the 37 // label on the module block in the example we've installed here: 38 // module "root" { 39 40 { 41 Name: "Download", 42 ModuleAddr: "root", 43 PackageAddr: "hashicorp/module-installer-acctest/aws", 44 Version: v, 45 }, 46 { 47 Name: "Install", 48 ModuleAddr: "root", 49 Version: v, 50 LocalPath: ".terraform/modules/root/hashicorp-terraform-aws-module-installer-acctest-5e87aff", 51 }, 52 { 53 Name: "Install", 54 ModuleAddr: "root.child_a", 55 LocalPath: ".terraform/modules/root/hashicorp-terraform-aws-module-installer-acctest-5e87aff/modules/child_a", 56 }, 57 { 58 Name: "Install", 59 ModuleAddr: "root.child_a.child_b", 60 LocalPath: ".terraform/modules/root/hashicorp-terraform-aws-module-installer-acctest-5e87aff/modules/child_b", 61 }, 62 } 63 64 if assertResultDeepEqual(t, hooks.Calls, wantCalls) { 65 return 66 } 67 68 // Make sure the configuration is loadable now. 69 // (This ensures that correct information is recorded in the manifest.) 70 config, loadDiags := loader.LoadConfig(".") 71 if assertNoDiagnostics(t, loadDiags) { 72 return 73 } 74 75 wantTraces := map[string]string{ 76 "": "in example", 77 "root": "in root module", 78 "root.child_a": "in child_a module", 79 "root.child_a.child_b": "in child_b module", 80 } 81 gotTraces := map[string]string{} 82 config.DeepEach(func(c *configs.Config) { 83 path := strings.Join(c.Path, ".") 84 if c.Module.Variables["v"] == nil { 85 gotTraces[path] = "<missing>" 86 return 87 } 88 varDesc := c.Module.Variables["v"].Description 89 gotTraces[path] = varDesc 90 }) 91 assertResultDeepEqual(t, gotTraces, wantTraces) 92 }