diff options
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/config/module/versions.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/config/module/versions.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/config/module/versions.go b/vendor/github.com/hashicorp/terraform/config/module/versions.go index 8348d4b..29701b9 100644 --- a/vendor/github.com/hashicorp/terraform/config/module/versions.go +++ b/vendor/github.com/hashicorp/terraform/config/module/versions.go | |||
@@ -3,7 +3,9 @@ package module | |||
3 | import ( | 3 | import ( |
4 | "errors" | 4 | "errors" |
5 | "fmt" | 5 | "fmt" |
6 | "regexp" | ||
6 | "sort" | 7 | "sort" |
8 | "strings" | ||
7 | 9 | ||
8 | version "github.com/hashicorp/go-version" | 10 | version "github.com/hashicorp/go-version" |
9 | "github.com/hashicorp/terraform/registry/response" | 11 | "github.com/hashicorp/terraform/registry/response" |
@@ -11,6 +13,8 @@ import ( | |||
11 | 13 | ||
12 | const anyVersion = ">=0.0.0" | 14 | const anyVersion = ">=0.0.0" |
13 | 15 | ||
16 | var explicitEqualityConstraint = regexp.MustCompile("^=[0-9]") | ||
17 | |||
14 | // return the newest version that satisfies the provided constraint | 18 | // return the newest version that satisfies the provided constraint |
15 | func newest(versions []string, constraint string) (string, error) { | 19 | func newest(versions []string, constraint string) (string, error) { |
16 | if constraint == "" { | 20 | if constraint == "" { |
@@ -21,6 +25,30 @@ func newest(versions []string, constraint string) (string, error) { | |||
21 | return "", err | 25 | return "", err |
22 | } | 26 | } |
23 | 27 | ||
28 | // Find any build metadata in the constraints, and | ||
29 | // store whether the constraint is an explicit equality that | ||
30 | // contains a build metadata requirement, so we can return a specific, | ||
31 | // if requested, build metadata version | ||
32 | var constraintMetas []string | ||
33 | var equalsConstraint bool | ||
34 | for i := range cs { | ||
35 | constraintMeta := strings.SplitAfterN(cs[i].String(), "+", 2) | ||
36 | if len(constraintMeta) > 1 { | ||
37 | constraintMetas = append(constraintMetas, constraintMeta[1]) | ||
38 | } | ||
39 | } | ||
40 | |||
41 | if len(cs) == 1 { | ||
42 | equalsConstraint = explicitEqualityConstraint.MatchString(cs.String()) | ||
43 | } | ||
44 | |||
45 | // If the version string includes metadata, this is valid in go-version, | ||
46 | // However, it's confusing as to what expected behavior should be, | ||
47 | // so give an error so the user can do something more logical | ||
48 | if (len(cs) > 1 || !equalsConstraint) && len(constraintMetas) > 0 { | ||
49 | return "", fmt.Errorf("Constraints including build metadata must have explicit equality, or are otherwise too ambiguous: %s", cs.String()) | ||
50 | } | ||
51 | |||
24 | switch len(versions) { | 52 | switch len(versions) { |
25 | case 0: | 53 | case 0: |
26 | return "", errors.New("no versions found") | 54 | return "", errors.New("no versions found") |
@@ -58,6 +86,12 @@ func newest(versions []string, constraint string) (string, error) { | |||
58 | continue | 86 | continue |
59 | } | 87 | } |
60 | if cs.Check(v) { | 88 | if cs.Check(v) { |
89 | // Constraint has metadata and is explicit equality | ||
90 | if equalsConstraint && len(constraintMetas) > 0 { | ||
91 | if constraintMetas[0] != v.Metadata() { | ||
92 | continue | ||
93 | } | ||
94 | } | ||
61 | return versions[i], nil | 95 | return versions[i], nil |
62 | } | 96 | } |
63 | } | 97 | } |