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:
Martin Atkins 2017-04-14 17:33:18 -07:00
parent 9b4f15c261
commit 7e7d4c70df
3 changed files with 23 additions and 8 deletions

View File

@ -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,10 +364,13 @@ func (c *Config) Validate() error {
}
if p.Version != "" {
errs = append(errs, fmt.Errorf(
"provider.%s: version constraints are not yet supported; remove the 'version' argument from configuration",
name,
))
_, err := semver.ParseRange(p.Version)
if err != nil {
errs = append(errs, fmt.Errorf(
"provider.%s: invalid version constraint %q: %s",
name, p.Version, err,
))
}
}
providerSet[name] = struct{}{}

View File

@ -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",
},
}

View File

@ -0,0 +1,5 @@
provider "aws" {
version = "bananas"
a = "a"
b = "b"
}