Skip to content

Commit

Permalink
use InternalValidate on the configschema
Browse files Browse the repository at this point in the history
This wasn't used until now but we should enforce the schema consistency,
especially when providers start generating their own rather than having
it done by helper/schema.

These will be presented as a warning initially to prevent any
unexpected breakage.
  • Loading branch information
jbardin committed Aug 15, 2019
1 parent 5ec519f commit f14c1e3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions terraform/eval_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,34 @@ func (n *EvalValidateProvider) Eval(ctx EvalContext) (interface{}, error) {
return nil, diags.NonFatalErr()
}

// Check that the schema is valid, warning the user for now to prevent
// breaking existing providers.
if err := resp.Provider.Block.InternalValidate(); err != nil {
resp.Diagnostics = resp.Diagnostics.Append(tfdiags.Sourceless(
tfdiags.Warning,
"schema validation error",
fmt.Sprintf("The schema for provider %s failed validation with %s.\n\nThis is a bug in the provider, which should be reported in the provider's own issue tracker.\n", n.Addr, err),
))
}
for name, schema := range resp.ResourceTypes {
if err := schema.Block.InternalValidate(); err != nil {
resp.Diagnostics = resp.Diagnostics.Append(tfdiags.Sourceless(
tfdiags.Warning,
"schema validation error",
fmt.Sprintf("The schema for resource %s in provider %s failed validation with %s.\n\nThis is a bug in the provider, which should be reported in the provider's own issue tracker.\n", name, n.Addr, err),
))
}
}
for name, schema := range resp.DataSources {
if err := schema.Block.InternalValidate(); err != nil {
resp.Diagnostics = resp.Diagnostics.Append(tfdiags.Sourceless(
tfdiags.Warning,
"schema validation error",
fmt.Sprintf("The schema for data source %s in provider %s failed validation with %s.\n\nThis is a bug in the provider, which should be reported in the provider's own issue tracker.\n", name, n.Addr, err),
))
}
}

configSchema := resp.Provider.Block
if configSchema == nil {
// Should never happen in real code, but often comes up in tests where
Expand Down

0 comments on commit f14c1e3

Please sign in to comment.