core: EvalValidate calls appropriate validator for resource mode

data resources are a separate namespace of resources than managed
resources, so we need to call a different provider method depending on
what mode of resource we're visiting.

Managed resources use ValidateResource, while data resources use
ValidateDataSource, since at the provider level of abstraction each
provider has separate sets of resources and data sources respectively.
This commit is contained in:
Martin Atkins 2016-05-01 19:01:48 -07:00
parent 844e1abdd3
commit c1315b3f09
2 changed files with 13 additions and 1 deletions

View File

@ -107,6 +107,7 @@ type EvalValidateResource struct {
Config **ResourceConfig
ResourceName string
ResourceType string
ResourceMode config.ResourceMode
}
func (n *EvalValidateResource) Eval(ctx EvalContext) (interface{}, error) {
@ -114,7 +115,17 @@ func (n *EvalValidateResource) Eval(ctx EvalContext) (interface{}, error) {
provider := *n.Provider
cfg := *n.Config
warns, errs := provider.ValidateResource(n.ResourceType, cfg)
var warns []string
var errs []error
// Provider entry point varies depending on resource mode, because
// managed resources and data resources are two distinct concepts
// in the provider abstraction.
switch n.ResourceMode {
case config.ManagedResourceMode:
warns, errs = provider.ValidateResource(n.ResourceType, cfg)
case config.DataResourceMode:
warns, errs = provider.ValidateDataSource(n.ResourceType, cfg)
}
// If the resouce name doesn't match the name regular
// expression, show a warning.

View File

@ -230,6 +230,7 @@ func (n *graphNodeExpandedResource) EvalTree() EvalNode {
Config: &resourceConfig,
ResourceName: n.Resource.Name,
ResourceType: n.Resource.Type,
ResourceMode: n.Resource.Mode,
})
// Validate all the provisioners