github.com/svenhamers/terraform@v0.11.12-beta1/helper/config/decode.go (about)

     1  package config
     2  
     3  import (
     4  	"github.com/mitchellh/mapstructure"
     5  )
     6  
     7  func Decode(target interface{}, raws ...interface{}) (*mapstructure.Metadata, error) {
     8  	var md mapstructure.Metadata
     9  	decoderConfig := &mapstructure.DecoderConfig{
    10  		Metadata:         &md,
    11  		Result:           target,
    12  		WeaklyTypedInput: true,
    13  	}
    14  
    15  	decoder, err := mapstructure.NewDecoder(decoderConfig)
    16  	if err != nil {
    17  		return nil, err
    18  	}
    19  
    20  	for _, raw := range raws {
    21  		err := decoder.Decode(raw)
    22  		if err != nil {
    23  			return nil, err
    24  		}
    25  	}
    26  
    27  	return &md, nil
    28  }