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"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/blang/semver"
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
"github.com/hashicorp/hil"
|
"github.com/hashicorp/hil"
|
||||||
"github.com/hashicorp/hil/ast"
|
"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
|
// Check that providers aren't declared multiple times and that their
|
||||||
// aren't used yet since they aren't properly supported.
|
// version constraints, where present, are syntactically valid.
|
||||||
providerSet := make(map[string]struct{})
|
providerSet := make(map[string]struct{})
|
||||||
for _, p := range c.ProviderConfigs {
|
for _, p := range c.ProviderConfigs {
|
||||||
name := p.FullName()
|
name := p.FullName()
|
||||||
|
@ -363,11 +364,14 @@ func (c *Config) Validate() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.Version != "" {
|
if p.Version != "" {
|
||||||
|
_, err := semver.ParseRange(p.Version)
|
||||||
|
if err != nil {
|
||||||
errs = append(errs, fmt.Errorf(
|
errs = append(errs, fmt.Errorf(
|
||||||
"provider.%s: version constraints are not yet supported; remove the 'version' argument from configuration",
|
"provider.%s: invalid version constraint %q: %s",
|
||||||
name,
|
name, p.Version, err,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
providerSet[name] = struct{}{}
|
providerSet[name] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,10 +208,16 @@ func TestConfigValidate_table(t *testing.T) {
|
||||||
"",
|
"",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"provider with version constraint",
|
"provider with valid version constraint",
|
||||||
"provider-version",
|
"provider-version",
|
||||||
|
false,
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"provider with invalid version constraint",
|
||||||
|
"provider-version-invalid",
|
||||||
true,
|
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