@@ -30,19 +30,17 @@ func parseModuleInstance(traversal hcl.Traversal) (ModuleInstance, tfdiags.Diagn
3030 mi , remain , diags := parseModuleInstancePrefix (traversal )
3131 if len (remain ) != 0 {
3232 if len (remain ) == len (traversal ) {
33- diags = diags .Append (& hcl.Diagnostic {
34- Severity : hcl .DiagError ,
35- Summary : "Invalid module instance address" ,
36- Detail : "A module instance address must begin with \" module.\" ." ,
37- Subject : remain .SourceRange ().Ptr (),
38- })
33+ diags = append (diags , tfdiags .Diag (
34+ tfdiags .Error ,
35+ "Invalid module instance address" ,
36+ "A module instance address must begin with \" module.\" ." ,
37+ ))
3938 } else {
40- diags = diags .Append (& hcl.Diagnostic {
41- Severity : hcl .DiagError ,
42- Summary : "Invalid module instance address" ,
43- Detail : "The module instance address is followed by additional invalid content." ,
44- Subject : remain .SourceRange ().Ptr (),
45- })
39+ diags = append (diags , tfdiags .Diag (
40+ tfdiags .Error ,
41+ "Invalid module instance address" ,
42+ "The module instance address is followed by additional invalid content." ,
43+ ))
4644 }
4745 }
4846 return mi , diags
@@ -67,13 +65,16 @@ func ParseModuleInstanceStr(str string) (ModuleInstance, tfdiags.Diagnostics) {
6765 var diags tfdiags.Diagnostics
6866
6967 traversal , parseDiags := hclsyntax .ParseTraversalAbs ([]byte (str ), "" , hcl.Pos {Line : 1 , Column : 1 })
70- diags = diags .Append (parseDiags )
68+ for _ , err := range parseDiags .Errs () {
69+ // ignore warnings, they don't matter in this case
70+ diags = append (diags , tfdiags .FromError (err ))
71+ }
7172 if parseDiags .HasErrors () {
7273 return nil , diags
7374 }
7475
7576 addr , addrDiags := parseModuleInstance (traversal )
76- diags = diags . Append ( addrDiags )
77+ diags = append ( diags , addrDiags ... )
7778 return addr , diags
7879}
7980
@@ -90,31 +91,28 @@ func parseModuleInstancePrefix(traversal hcl.Traversal) (ModuleInstance, hcl.Tra
9091 case hcl.TraverseAttr :
9192 next = tt .Name
9293 default :
93- diags = diags .Append (& hcl.Diagnostic {
94- Severity : hcl .DiagError ,
95- Summary : "Invalid address operator" ,
96- Detail : "Module address prefix must be followed by dot and then a name." ,
97- Subject : remain [0 ].SourceRange ().Ptr (),
98- })
94+ diags = append (diags , tfdiags .Diag (
95+ tfdiags .Error ,
96+ "Invalid address operator" ,
97+ "Module address prefix must be followed by dot and then a name." ,
98+ ))
9999 break
100100 }
101101
102102 if next != "module" {
103103 break
104104 }
105105
106- kwRange := remain [0 ].SourceRange ()
107106 remain = remain [1 :]
108107 // If we have the prefix "module" then we should be followed by an
109108 // module call name, as an attribute, and then optionally an index step
110109 // giving the instance key.
111110 if len (remain ) == 0 {
112- diags = diags .Append (& hcl.Diagnostic {
113- Severity : hcl .DiagError ,
114- Summary : "Invalid address operator" ,
115- Detail : "Prefix \" module.\" must be followed by a module name." ,
116- Subject : & kwRange ,
117- })
111+ diags = append (diags , tfdiags .Diag (
112+ tfdiags .Error ,
113+ "Invalid address operator" ,
114+ "Prefix \" module.\" must be followed by a module name." ,
115+ ))
118116 break
119117 }
120118
@@ -123,12 +121,11 @@ func parseModuleInstancePrefix(traversal hcl.Traversal) (ModuleInstance, hcl.Tra
123121 case hcl.TraverseAttr :
124122 moduleName = tt .Name
125123 default :
126- diags = diags .Append (& hcl.Diagnostic {
127- Severity : hcl .DiagError ,
128- Summary : "Invalid address operator" ,
129- Detail : "Prefix \" module.\" must be followed by a module name." ,
130- Subject : remain [0 ].SourceRange ().Ptr (),
131- })
124+ diags = append (diags , tfdiags .Diag (
125+ tfdiags .Error ,
126+ "Invalid address operator" ,
127+ "Prefix \" module.\" must be followed by a module name." ,
128+ ))
132129 break
133130 }
134131 remain = remain [1 :]
@@ -149,21 +146,19 @@ func parseModuleInstancePrefix(traversal hcl.Traversal) (ModuleInstance, hcl.Tra
149146 if err == nil {
150147 step .InstanceKey = intKey (idxInt )
151148 } else {
152- diags = diags .Append (& hcl.Diagnostic {
153- Severity : hcl .DiagError ,
154- Summary : "Invalid address operator" ,
155- Detail : fmt .Sprintf ("Invalid module index: %s." , err ),
156- Subject : idx .SourceRange ().Ptr (),
157- })
149+ diags = append (diags , tfdiags .Diag (
150+ tfdiags .Error ,
151+ "Invalid address operator" ,
152+ fmt .Sprintf ("Invalid module index: %s." , err ),
153+ ))
158154 }
159155 default :
160156 // Should never happen, because no other types are allowed in traversal indices.
161- diags = diags .Append (& hcl.Diagnostic {
162- Severity : hcl .DiagError ,
163- Summary : "Invalid address operator" ,
164- Detail : "Invalid module key: must be either a string or an integer." ,
165- Subject : idx .SourceRange ().Ptr (),
166- })
157+ diags = append (diags , tfdiags .Diag (
158+ tfdiags .Error ,
159+ "Invalid address operator" ,
160+ "Invalid module key: must be either a string or an integer." ,
161+ ))
167162 }
168163 }
169164 }
0 commit comments