opentofu/terraform/eval_validate.go

69 lines
1.6 KiB
Go
Raw Normal View History

2015-02-04 17:44:23 -06:00
package terraform
// EvalValidateError is the error structure returned if there were
// validation errors.
type EvalValidateError struct {
Warnings []string
Errors []error
}
func (e *EvalValidateError) Error() string {
return ""
}
2015-02-04 19:23:26 -06:00
// EvalValidateProvider is an EvalNode implementation that validates
// the configuration of a resource.
type EvalValidateProvider struct {
Provider EvalNode
Config EvalNode
}
func (n *EvalValidateProvider) Args() ([]EvalNode, []EvalType) {
return []EvalNode{n.Provider, n.Config},
[]EvalType{EvalTypeResourceProvider, EvalTypeConfig}
}
func (n *EvalValidateProvider) Eval(
ctx EvalContext, args []interface{}) (interface{}, error) {
provider := args[0].(ResourceProvider)
config := args[1].(*ResourceConfig)
warns, errs := provider.Validate(config)
if len(warns) == 0 && len(errs) == 0 {
return nil, nil
}
return nil, &EvalValidateError{
Warnings: warns,
Errors: errs,
}
}
func (n *EvalValidateProvider) Type() EvalType {
return EvalTypeNull
}
2015-02-04 17:44:23 -06:00
// EvalValidateResource is an EvalNode implementation that validates
// the configuration of a resource.
type EvalValidateResource struct {
2015-02-04 19:02:18 -06:00
Provider EvalNode
2015-02-04 19:23:26 -06:00
Config EvalNode
2015-02-04 19:02:18 -06:00
ProviderType string
2015-02-04 17:44:23 -06:00
}
func (n *EvalValidateResource) Args() ([]EvalNode, []EvalType) {
2015-02-04 19:23:26 -06:00
return []EvalNode{n.Provider, n.Config},
[]EvalType{EvalTypeResourceProvider, EvalTypeConfig}
2015-02-04 17:44:23 -06:00
}
func (n *EvalValidateResource) Eval(
ctx EvalContext, args []interface{}) (interface{}, error) {
2015-02-04 19:02:18 -06:00
// TODO: test
2015-02-04 17:44:23 -06:00
//provider := args[0].(ResourceProvider)
2015-02-04 19:02:18 -06:00
return nil, nil
2015-02-04 17:44:23 -06:00
}
func (n *EvalValidateResource) Type() EvalType {
return EvalTypeNull
}