diff options
author | Nathan Dench <ndenc2@gmail.com> | 2019-05-24 15:16:44 +1000 |
---|---|---|
committer | Nathan Dench <ndenc2@gmail.com> | 2019-05-24 15:16:44 +1000 |
commit | 107c1cdb09c575aa2f61d97f48d8587eb6bada4c (patch) | |
tree | ca7d008643efc555c388baeaf1d986e0b6b3e28c /vendor/github.com/hashicorp/terraform/configs/version_constraint.go | |
parent | 844b5a68d8af4791755b8f0ad293cc99f5959183 (diff) | |
download | terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.gz terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.zst terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.zip |
Upgrade to 0.12
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/configs/version_constraint.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/configs/version_constraint.go | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/configs/version_constraint.go b/vendor/github.com/hashicorp/terraform/configs/version_constraint.go new file mode 100644 index 0000000..7aa19ef --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/configs/version_constraint.go | |||
@@ -0,0 +1,64 @@ | |||
1 | package configs | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | |||
6 | version "github.com/hashicorp/go-version" | ||
7 | "github.com/hashicorp/hcl2/hcl" | ||
8 | "github.com/zclconf/go-cty/cty" | ||
9 | "github.com/zclconf/go-cty/cty/convert" | ||
10 | ) | ||
11 | |||
12 | // VersionConstraint represents a version constraint on some resource | ||
13 | // (e.g. Terraform Core, a provider, a module, ...) that carries with it | ||
14 | // a source range so that a helpful diagnostic can be printed in the event | ||
15 | // that a particular constraint does not match. | ||
16 | type VersionConstraint struct { | ||
17 | Required version.Constraints | ||
18 | DeclRange hcl.Range | ||
19 | } | ||
20 | |||
21 | func decodeVersionConstraint(attr *hcl.Attribute) (VersionConstraint, hcl.Diagnostics) { | ||
22 | ret := VersionConstraint{ | ||
23 | DeclRange: attr.Range, | ||
24 | } | ||
25 | |||
26 | val, diags := attr.Expr.Value(nil) | ||
27 | if diags.HasErrors() { | ||
28 | return ret, diags | ||
29 | } | ||
30 | var err error | ||
31 | val, err = convert.Convert(val, cty.String) | ||
32 | if err != nil { | ||
33 | diags = append(diags, &hcl.Diagnostic{ | ||
34 | Severity: hcl.DiagError, | ||
35 | Summary: "Invalid version constraint", | ||
36 | Detail: fmt.Sprintf("A string value is required for %s.", attr.Name), | ||
37 | Subject: attr.Expr.Range().Ptr(), | ||
38 | }) | ||
39 | return ret, diags | ||
40 | } | ||
41 | |||
42 | if val.IsNull() { | ||
43 | // A null version constraint is strange, but we'll just treat it | ||
44 | // like an empty constraint set. | ||
45 | return ret, diags | ||
46 | } | ||
47 | |||
48 | constraintStr := val.AsString() | ||
49 | constraints, err := version.NewConstraint(constraintStr) | ||
50 | if err != nil { | ||
51 | // NewConstraint doesn't return user-friendly errors, so we'll just | ||
52 | // ignore the provided error and produce our own generic one. | ||
53 | diags = append(diags, &hcl.Diagnostic{ | ||
54 | Severity: hcl.DiagError, | ||
55 | Summary: "Invalid version constraint", | ||
56 | Detail: "This string does not use correct version constraint syntax.", // Not very actionable :( | ||
57 | Subject: attr.Expr.Range().Ptr(), | ||
58 | }) | ||
59 | return ret, diags | ||
60 | } | ||
61 | |||
62 | ret.Required = constraints | ||
63 | return ret, diags | ||
64 | } | ||