github.com/hashicorp/terraform-plugin-sdk@v1.17.2/internal/configs/module_call_test.go (about) 1 package configs 2 3 import ( 4 "io/ioutil" 5 "testing" 6 7 "github.com/go-test/deep" 8 "github.com/hashicorp/hcl/v2" 9 ) 10 11 func TestLoadModuleCall(t *testing.T) { 12 src, err := ioutil.ReadFile("testdata/invalid-files/module-calls.tf") 13 if err != nil { 14 t.Fatal(err) 15 } 16 17 parser := testParser(map[string]string{ 18 "module-calls.tf": string(src), 19 }) 20 21 file, diags := parser.LoadConfigFile("module-calls.tf") 22 assertExactDiagnostics(t, diags, []string{ 23 `module-calls.tf:19,3-8: Reserved argument name in module block; The name "count" is reserved for use in a future version of Terraform.`, 24 `module-calls.tf:20,3-11: Reserved argument name in module block; The name "for_each" is reserved for use in a future version of Terraform.`, 25 `module-calls.tf:22,3-13: Reserved argument name in module block; The name "depends_on" is reserved for use in a future version of Terraform.`, 26 }) 27 28 gotModules := file.ModuleCalls 29 wantModules := []*ModuleCall{ 30 { 31 Name: "foo", 32 SourceAddr: "./foo", 33 SourceSet: true, 34 SourceAddrRange: hcl.Range{ 35 Filename: "module-calls.tf", 36 Start: hcl.Pos{Line: 3, Column: 12, Byte: 27}, 37 End: hcl.Pos{Line: 3, Column: 19, Byte: 34}, 38 }, 39 DeclRange: hcl.Range{ 40 Filename: "module-calls.tf", 41 Start: hcl.Pos{Line: 2, Column: 1, Byte: 1}, 42 End: hcl.Pos{Line: 2, Column: 13, Byte: 13}, 43 }, 44 }, 45 { 46 Name: "bar", 47 SourceAddr: "hashicorp/bar/aws", 48 SourceSet: true, 49 SourceAddrRange: hcl.Range{ 50 Filename: "module-calls.tf", 51 Start: hcl.Pos{Line: 8, Column: 12, Byte: 113}, 52 End: hcl.Pos{Line: 8, Column: 31, Byte: 132}, 53 }, 54 DeclRange: hcl.Range{ 55 Filename: "module-calls.tf", 56 Start: hcl.Pos{Line: 7, Column: 1, Byte: 87}, 57 End: hcl.Pos{Line: 7, Column: 13, Byte: 99}, 58 }, 59 }, 60 { 61 Name: "baz", 62 SourceAddr: "git::https://example.com/", 63 SourceSet: true, 64 SourceAddrRange: hcl.Range{ 65 Filename: "module-calls.tf", 66 Start: hcl.Pos{Line: 15, Column: 12, Byte: 193}, 67 End: hcl.Pos{Line: 15, Column: 39, Byte: 220}, 68 }, 69 DependsOn: []hcl.Traversal{ 70 { 71 hcl.TraverseRoot{ 72 Name: "module", 73 SrcRange: hcl.Range{ 74 Filename: "module-calls.tf", 75 Start: hcl.Pos{Line: 23, Column: 5, Byte: 295}, 76 End: hcl.Pos{Line: 23, Column: 11, Byte: 301}, 77 }, 78 }, 79 hcl.TraverseAttr{ 80 Name: "bar", 81 SrcRange: hcl.Range{ 82 Filename: "module-calls.tf", 83 Start: hcl.Pos{Line: 23, Column: 11, Byte: 301}, 84 End: hcl.Pos{Line: 23, Column: 15, Byte: 305}, 85 }, 86 }, 87 }, 88 }, 89 Providers: []PassedProviderConfig{ 90 { 91 InChild: &ProviderConfigRef{ 92 Name: "aws", 93 NameRange: hcl.Range{ 94 Filename: "module-calls.tf", 95 Start: hcl.Pos{Line: 27, Column: 5, Byte: 332}, 96 End: hcl.Pos{Line: 27, Column: 8, Byte: 335}, 97 }, 98 }, 99 InParent: &ProviderConfigRef{ 100 Name: "aws", 101 NameRange: hcl.Range{ 102 Filename: "module-calls.tf", 103 Start: hcl.Pos{Line: 27, Column: 11, Byte: 338}, 104 End: hcl.Pos{Line: 27, Column: 14, Byte: 341}, 105 }, 106 Alias: "foo", 107 AliasRange: &hcl.Range{ 108 Filename: "module-calls.tf", 109 Start: hcl.Pos{Line: 27, Column: 14, Byte: 341}, 110 End: hcl.Pos{Line: 27, Column: 18, Byte: 345}, 111 }, 112 }, 113 }, 114 }, 115 DeclRange: hcl.Range{ 116 Filename: "module-calls.tf", 117 Start: hcl.Pos{Line: 14, Column: 1, Byte: 167}, 118 End: hcl.Pos{Line: 14, Column: 13, Byte: 179}, 119 }, 120 }, 121 } 122 123 // We'll hide all of the bodies/exprs since we're treating them as opaque 124 // here anyway... the point of this test is to ensure we handle everything 125 // else properly. 126 for _, m := range gotModules { 127 m.Config = nil 128 m.Count = nil 129 m.ForEach = nil 130 } 131 132 for _, problem := range deep.Equal(gotModules, wantModules) { 133 t.Error(problem) 134 } 135 }