in module.go [52:101]
func (m *Module) Load() error {
fileNames := m.codeFileNames()
parser := hclparse.NewParser()
for _, n := range fileNames {
content, err := m.fs.ReadFile(n)
if err != nil {
return err
}
var f *hcl.File
var diag hcl.Diagnostics
if fileExt(n) == ".tf" {
f, diag = parser.ParseHCL(content, n)
} else {
f, diag = parser.ParseJSON(content, n)
}
if diag.HasErrors() {
return diag
}
c, _, diag := f.Body.PartialContent(&hcl.BodySchema{
Blocks: []hcl.BlockHeaderSchema{
{
Type: "variable",
LabelNames: []string{"name"},
},
{
Type: "output",
LabelNames: []string{"name"},
},
},
})
if diag.HasErrors() {
return diag
}
for _, b := range c.Blocks {
switch b.Type {
case "variable":
{
v := m.parseVariable(b, f)
m.VariableExts[b.Labels[0]] = v
}
case "output":
{
o := m.parseOutput(b, f)
m.OutputExts[b.Labels[0]] = o
}
}
}
}
return nil
}