diff --git a/config/config.go b/config/config.go index 0648d6917..3f756dcf4 100644 --- a/config/config.go +++ b/config/config.go @@ -8,11 +8,11 @@ import ( "strconv" "strings" - "github.com/blang/semver" "github.com/hashicorp/go-multierror" "github.com/hashicorp/hil" "github.com/hashicorp/hil/ast" "github.com/hashicorp/terraform/helper/hilmapstructure" + "github.com/hashicorp/terraform/plugin/discovery" "github.com/mitchellh/reflectwalk" ) @@ -391,7 +391,7 @@ func (c *Config) Validate() error { } if p.Version != "" { - _, err := semver.ParseRange(p.Version) + _, err := discovery.ConstraintStr(p.Version).Parse() if err != nil { errs = append(errs, fmt.Errorf( "provider.%s: invalid version constraint %q: %s", diff --git a/config/config_test.go b/config/config_test.go index db62e1c54..edcf36af2 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -626,6 +626,13 @@ func TestConfigValidate_varModuleInvalid(t *testing.T) { } } +func TestConfigValidate_varProviderVersionInvalid(t *testing.T) { + c := testConfig(t, "validate-provider-version-invalid") + if err := c.Validate(); err == nil { + t.Fatal("should not be valid") + } +} + func TestNameRegexp(t *testing.T) { cases := []struct { Input string diff --git a/config/test-fixtures/validate-provider-version-invalid/main.tf b/config/test-fixtures/validate-provider-version-invalid/main.tf new file mode 100644 index 000000000..9a251a3b2 --- /dev/null +++ b/config/test-fixtures/validate-provider-version-invalid/main.tf @@ -0,0 +1,3 @@ +provider "test" { + version = "bananas!" +}