in interfaces/interface_variable.go [83:123]
func (vcr *InterfaceVarCheckRule) Check(r tflint.Runner) error {
path, err := r.GetModulePath()
if err != nil {
return err
}
if !path.IsRoot() {
// This rule does not evaluate child modules.
return nil
}
// Define the schema that we want to pull out of the module content.
body, err := r.GetModuleContent(
variableBodySchema,
&tflint.GetModuleContentOption{ExpandMode: tflint.ExpandModeNone})
if err != nil {
return err
}
// Iterate over the variables and check for the name we are interested in.
for _, b := range body.Blocks {
if b.Labels[0] != vcr.RuleName {
continue
}
typeAttr, c := CheckWithReturnValue(NewChecker(), getAttr(vcr, r, b, "type"))
var defaultAttr *hclext.Attribute
if vcr.Default.IsKnown() {
defaultAttr, c = CheckWithReturnValue(c, getAttr(vcr, r, b, "default"))
} else {
c = c.Check(attributeNotExist(vcr, r, b, "default"))
}
if c = c.Check(checkVarType(vcr, r, typeAttr)).
Check(checkDefaultValue(vcr, r, b, defaultAttr)).
Check(checkNullableValue(vcr, r, b)); c.err != nil {
return c.err
}
// TODO: Check validation rules.
return nil
}
return nil
}