config: allow version constraints on providers, but validate them
We now accept syntactically-valid version constraints on provider blocks, though we still don't actually do anything with them.
This commit is contained in:
parent
9b4f15c261
commit
7e7d4c70df
|
@ -8,6 +8,7 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/blang/semver"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/hashicorp/hil"
|
||||
"github.com/hashicorp/hil/ast"
|
||||
|
@ -350,8 +351,8 @@ func (c *Config) Validate() error {
|
|||
}
|
||||
}
|
||||
|
||||
// Check that providers aren't declared multiple times, and that versions
|
||||
// aren't used yet since they aren't properly supported.
|
||||
// Check that providers aren't declared multiple times and that their
|
||||
// version constraints, where present, are syntactically valid.
|
||||
providerSet := make(map[string]struct{})
|
||||
for _, p := range c.ProviderConfigs {
|
||||
name := p.FullName()
|
||||
|
@ -363,11 +364,14 @@ func (c *Config) Validate() error {
|
|||
}
|
||||
|
||||
if p.Version != "" {
|
||||
_, err := semver.ParseRange(p.Version)
|
||||
if err != nil {
|
||||
errs = append(errs, fmt.Errorf(
|
||||
"provider.%s: version constraints are not yet supported; remove the 'version' argument from configuration",
|
||||
name,
|
||||
"provider.%s: invalid version constraint %q: %s",
|
||||
name, p.Version, err,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
providerSet[name] = struct{}{}
|
||||
}
|
||||
|
|
|
@ -208,10 +208,16 @@ func TestConfigValidate_table(t *testing.T) {
|
|||
"",
|
||||
},
|
||||
{
|
||||
"provider with version constraint",
|
||||
"provider with valid version constraint",
|
||||
"provider-version",
|
||||
false,
|
||||
"",
|
||||
},
|
||||
{
|
||||
"provider with invalid version constraint",
|
||||
"provider-version-invalid",
|
||||
true,
|
||||
"version constraints are not yet supported",
|
||||
"invalid version constraint",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
provider "aws" {
|
||||
version = "bananas"
|
||||
a = "a"
|
||||
b = "b"
|
||||
}
|
Loading…
Reference in New Issue