Esempio n. 1
0
// Validate validates the configuration and returns any warnings or errors.
func (c *Context) Validate() ([]string, []error) {
	var rerr *multierror.Error

	// Validate the configuration itself
	if err := c.config.Validate(); err != nil {
		rerr = multierror.ErrorAppend(rerr, err)
	}

	// Validate the user variables
	if errs := smcUserVariables(c.config, c.variables); len(errs) > 0 {
		rerr = multierror.ErrorAppend(rerr, errs...)
	}

	// Validate the graph
	g, err := c.graph()
	if err != nil {
		rerr = multierror.ErrorAppend(rerr, fmt.Errorf(
			"Error creating graph: %s", err))
	}

	// Walk the graph and validate all the configs
	var warns []string
	var errs []error
	if g != nil {
		err = g.Walk(c.validateWalkFn(&warns, &errs))
		if err != nil {
			rerr = multierror.ErrorAppend(rerr, fmt.Errorf(
				"Error validating resources in graph: %s", err))
		}
		if len(errs) > 0 {
			rerr = multierror.ErrorAppend(rerr, errs...)
		}
	}

	errs = nil
	if rerr != nil && len(rerr.Errors) > 0 {
		errs = rerr.Errors
	}

	return warns, errs
}
Esempio n. 2
0
// Validate validates the configuration and returns any warnings or errors.
func (c *Context) Validate() ([]string, []error) {
	var rerr *multierror.Error

	// Validate the configuration itself
	if err := c.module.Validate(); err != nil {
		rerr = multierror.ErrorAppend(rerr, err)
	}

	// This only needs to be done for the root module, since inter-module
	// variables are validated in the module tree.
	if config := c.module.Config(); config != nil {
		// Validate the user variables
		if errs := smcUserVariables(config, c.variables); len(errs) > 0 {
			rerr = multierror.ErrorAppend(rerr, errs...)
		}
	}

	// Validate the entire graph
	walkMeta := new(walkValidateMeta)
	wc := c.walkContext(walkValidate, rootModulePath)
	wc.Meta = walkMeta
	if err := wc.Walk(); err != nil {
		rerr = multierror.ErrorAppend(rerr, err)
	}

	// Flatten the warns/errs so that we get all the module errors as well,
	// then aggregate.
	warns, errs := walkMeta.Flatten()
	if len(errs) > 0 {
		rerr = multierror.ErrorAppend(rerr, errs...)
	}

	errs = nil
	if rerr != nil && len(rerr.Errors) > 0 {
		errs = rerr.Errors
	}

	return warns, errs
}
Esempio n. 3
0
// ExprParse parses the given expression and returns an executable
// Interpolation.
func ExprParse(v string) (Interpolation, error) {
	exprLock.Lock()
	defer exprLock.Unlock()
	exprErrors = nil
	exprResult = nil

	// Parse
	lex := &exprLex{Input: v}
	exprParse(lex)

	// Build up the errors
	var err error
	if lex.Err != nil {
		err = multierror.ErrorAppend(err, lex.Err)
	}
	if len(exprErrors) > 0 {
		err = multierror.ErrorAppend(err, exprErrors...)
	}
	if err != nil {
		exprResult = nil
	}

	return exprResult, err
}