From 444cb96b48e3b6bd26279efa9ade9c8aaef0720e Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 29 Nov 2018 11:56:55 -0800 Subject: [PATCH] core: Reject provider schemas with version < 0 There's no reason for a negative version, so by blocking it now we'll ensure that none creep in. The more practical short-term motivation for this is that we're still using uint64 for these internally in some cases and so this restriction ensures that we won't run into rough edges when converting from int64 to uint64 at those boundaries until we later fix everything to use int64 consistently. --- terraform/schemas.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/terraform/schemas.go b/terraform/schemas.go index 21d803b53..cf373f6a3 100644 --- a/terraform/schemas.go +++ b/terraform/schemas.go @@ -131,13 +131,33 @@ func loadProviderSchemas(schemas map[string]*ProviderSchema, config *configs.Con ResourceTypeSchemaVersions: make(map[string]uint64), } + if resp.Provider.Version < 0 { + // We're not using the version numbers here yet, but we'll check + // for validity anyway in case we start using them in future. + diags = diags.Append( + fmt.Errorf("invalid negative schema version provider configuration for provider %q", typeName), + ) + } + for t, r := range resp.ResourceTypes { s.ResourceTypes[t] = r.Block s.ResourceTypeSchemaVersions[t] = r.Version + if r.Version < 0 { + diags = diags.Append( + fmt.Errorf("invalid negative schema version for resource type %s in provider %q", t, typeName), + ) + } } for t, d := range resp.DataSources { s.DataSources[t] = d.Block + if d.Version < 0 { + // We're not using the version numbers here yet, but we'll check + // for validity anyway in case we start using them in future. + diags = diags.Append( + fmt.Errorf("invalid negative schema version for data source %s in provider %q", t, typeName), + ) + } } schemas[typeName] = s