4 "github.com/hashicorp/hcl2/hcl"
5 "github.com/zclconf/go-cty/cty"
8 // LoadValuesFile reads the file at the given path and parses it as a "values
9 // file", which is an HCL config file whose top-level attributes are treated
10 // as arbitrary key.value pairs.
12 // If the file cannot be read -- for example, if it does not exist -- then
13 // a nil map will be returned along with error diagnostics. Callers may wish
14 // to disregard the returned diagnostics in this case and instead generate
15 // their own error message(s) with additional context.
17 // If the returned diagnostics has errors when a non-nil map is returned
18 // then the map may be incomplete but should be valid enough for careful
21 // This method wraps LoadHCLFile, and so it inherits the syntax selection
22 // behaviors documented for that method.
23 func (p *Parser) LoadValuesFile(path string) (map[string]cty.Value, hcl.Diagnostics) {
24 body, diags := p.LoadHCLFile(path)
29 vals := make(map[string]cty.Value)
30 attrs, attrDiags := body.JustAttributes()
31 diags = append(diags, attrDiags...)
36 for name, attr := range attrs {
37 val, valDiags := attr.Expr.Value(nil)
38 diags = append(diags, valDiags...)