func ParseVariables()

in hcl/parse.go [266:306]


func ParseVariables(f hcl.File) (*map[string]Variable, []error) {
	content, _, diags := f.Body.PartialContent(&VarBlockSchema)
	if diags.HasErrors() {
		logrus.Error(diags)
	}

	results := make(map[string]Variable, 0)
	for _, block := range content.Blocks {
		attrs, diags := block.Body.JustAttributes()
		if diags.HasErrors() {
			diags := skipJustAttributesDiags(diags)
			if diags.HasErrors() {
				return nil, diags.Errs()
			}
		}

		var hasDefault bool
		if p := attrs["default"]; p != nil {
			hasDefault = true
		}

		var isSensitive bool
		if p := attrs["sensitive"]; p != nil {
			value, diags := p.Expr.Value(nil)
			if diags.HasErrors() {
				return nil, diags.Errs()
			}
			isSensitive = value.True()
		}

		results[block.Labels[0]] = Variable{
			Name:        block.Labels[0],
			FileName:    block.DefRange.Filename,
			LineNumber:  block.DefRange.Start.Line,
			IsSensitive: isSensitive,
			HasDefault:  hasDefault,
		}
	}

	return &results, nil
}