diff options
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/lang/funcs')
3 files changed, 77 insertions, 8 deletions
diff --git a/vendor/github.com/hashicorp/terraform/lang/funcs/collection.go b/vendor/github.com/hashicorp/terraform/lang/funcs/collection.go index 71b7a84..bcccc1f 100644 --- a/vendor/github.com/hashicorp/terraform/lang/funcs/collection.go +++ b/vendor/github.com/hashicorp/terraform/lang/funcs/collection.go | |||
@@ -246,7 +246,7 @@ var CompactFunc = function.New(&function.Spec{ | |||
246 | 246 | ||
247 | for it := listVal.ElementIterator(); it.Next(); { | 247 | for it := listVal.ElementIterator(); it.Next(); { |
248 | _, v := it.Element() | 248 | _, v := it.Element() |
249 | if v.AsString() == "" { | 249 | if v.IsNull() || v.AsString() == "" { |
250 | continue | 250 | continue |
251 | } | 251 | } |
252 | outputList = append(outputList, v) | 252 | outputList = append(outputList, v) |
@@ -363,6 +363,9 @@ var DistinctFunc = function.New(&function.Spec{ | |||
363 | } | 363 | } |
364 | } | 364 | } |
365 | 365 | ||
366 | if len(list) == 0 { | ||
367 | return cty.ListValEmpty(retType.ElementType()), nil | ||
368 | } | ||
366 | return cty.ListVal(list), nil | 369 | return cty.ListVal(list), nil |
367 | }, | 370 | }, |
368 | }) | 371 | }) |
@@ -389,6 +392,10 @@ var ChunklistFunc = function.New(&function.Spec{ | |||
389 | return cty.UnknownVal(retType), nil | 392 | return cty.UnknownVal(retType), nil |
390 | } | 393 | } |
391 | 394 | ||
395 | if listVal.LengthInt() == 0 { | ||
396 | return cty.ListValEmpty(listVal.Type()), nil | ||
397 | } | ||
398 | |||
392 | var size int | 399 | var size int |
393 | err = gocty.FromCtyValue(args[1], &size) | 400 | err = gocty.FromCtyValue(args[1], &size) |
394 | if err != nil { | 401 | if err != nil { |
@@ -686,8 +693,10 @@ var LookupFunc = function.New(&function.Spec{ | |||
686 | return cty.StringVal(v.AsString()), nil | 693 | return cty.StringVal(v.AsString()), nil |
687 | case ty.Equals(cty.Number): | 694 | case ty.Equals(cty.Number): |
688 | return cty.NumberVal(v.AsBigFloat()), nil | 695 | return cty.NumberVal(v.AsBigFloat()), nil |
696 | case ty.Equals(cty.Bool): | ||
697 | return cty.BoolVal(v.True()), nil | ||
689 | default: | 698 | default: |
690 | return cty.NilVal, errors.New("lookup() can only be used with flat lists") | 699 | return cty.NilVal, errors.New("lookup() can only be used with maps of primitive types") |
691 | } | 700 | } |
692 | } | 701 | } |
693 | } | 702 | } |
@@ -797,10 +806,12 @@ var MatchkeysFunc = function.New(&function.Spec{ | |||
797 | }, | 806 | }, |
798 | }, | 807 | }, |
799 | Type: func(args []cty.Value) (cty.Type, error) { | 808 | Type: func(args []cty.Value) (cty.Type, error) { |
800 | if !args[1].Type().Equals(args[2].Type()) { | 809 | ty, _ := convert.UnifyUnsafe([]cty.Type{args[1].Type(), args[2].Type()}) |
801 | return cty.NilType, errors.New("lists must be of the same type") | 810 | if ty == cty.NilType { |
811 | return cty.NilType, errors.New("keys and searchset must be of the same type") | ||
802 | } | 812 | } |
803 | 813 | ||
814 | // the return type is based on args[0] (values) | ||
804 | return args[0].Type(), nil | 815 | return args[0].Type(), nil |
805 | }, | 816 | }, |
806 | Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) { | 817 | Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) { |
@@ -813,10 +824,14 @@ var MatchkeysFunc = function.New(&function.Spec{ | |||
813 | } | 824 | } |
814 | 825 | ||
815 | output := make([]cty.Value, 0) | 826 | output := make([]cty.Value, 0) |
816 | |||
817 | values := args[0] | 827 | values := args[0] |
818 | keys := args[1] | 828 | |
819 | searchset := args[2] | 829 | // Keys and searchset must be the same type. |
830 | // We can skip error checking here because we've already verified that | ||
831 | // they can be unified in the Type function | ||
832 | ty, _ := convert.UnifyUnsafe([]cty.Type{args[1].Type(), args[2].Type()}) | ||
833 | keys, _ := convert.Convert(args[1], ty) | ||
834 | searchset, _ := convert.Convert(args[2], ty) | ||
820 | 835 | ||
821 | // if searchset is empty, return an empty list. | 836 | // if searchset is empty, return an empty list. |
822 | if searchset.LengthInt() == 0 { | 837 | if searchset.LengthInt() == 0 { |
@@ -867,7 +882,6 @@ var MergeFunc = function.New(&function.Spec{ | |||
867 | Name: "maps", | 882 | Name: "maps", |
868 | Type: cty.DynamicPseudoType, | 883 | Type: cty.DynamicPseudoType, |
869 | AllowDynamicType: true, | 884 | AllowDynamicType: true, |
870 | AllowNull: true, | ||
871 | }, | 885 | }, |
872 | Type: function.StaticReturnType(cty.DynamicPseudoType), | 886 | Type: function.StaticReturnType(cty.DynamicPseudoType), |
873 | Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) { | 887 | Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) { |
diff --git a/vendor/github.com/hashicorp/terraform/lang/funcs/crypto.go b/vendor/github.com/hashicorp/terraform/lang/funcs/crypto.go index 5cb4bc5..be006f8 100644 --- a/vendor/github.com/hashicorp/terraform/lang/funcs/crypto.go +++ b/vendor/github.com/hashicorp/terraform/lang/funcs/crypto.go | |||
@@ -14,6 +14,7 @@ import ( | |||
14 | "hash" | 14 | "hash" |
15 | 15 | ||
16 | uuid "github.com/hashicorp/go-uuid" | 16 | uuid "github.com/hashicorp/go-uuid" |
17 | uuidv5 "github.com/satori/go.uuid" | ||
17 | "github.com/zclconf/go-cty/cty" | 18 | "github.com/zclconf/go-cty/cty" |
18 | "github.com/zclconf/go-cty/cty/function" | 19 | "github.com/zclconf/go-cty/cty/function" |
19 | "github.com/zclconf/go-cty/cty/gocty" | 20 | "github.com/zclconf/go-cty/cty/gocty" |
@@ -32,6 +33,39 @@ var UUIDFunc = function.New(&function.Spec{ | |||
32 | }, | 33 | }, |
33 | }) | 34 | }) |
34 | 35 | ||
36 | var UUIDV5Func = function.New(&function.Spec{ | ||
37 | Params: []function.Parameter{ | ||
38 | { | ||
39 | Name: "namespace", | ||
40 | Type: cty.String, | ||
41 | }, | ||
42 | { | ||
43 | Name: "name", | ||
44 | Type: cty.String, | ||
45 | }, | ||
46 | }, | ||
47 | Type: function.StaticReturnType(cty.String), | ||
48 | Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) { | ||
49 | var namespace uuidv5.UUID | ||
50 | switch { | ||
51 | case args[0].AsString() == "dns": | ||
52 | namespace = uuidv5.NamespaceDNS | ||
53 | case args[0].AsString() == "url": | ||
54 | namespace = uuidv5.NamespaceURL | ||
55 | case args[0].AsString() == "oid": | ||
56 | namespace = uuidv5.NamespaceOID | ||
57 | case args[0].AsString() == "x500": | ||
58 | namespace = uuidv5.NamespaceX500 | ||
59 | default: | ||
60 | if namespace, err = uuidv5.FromString(args[0].AsString()); err != nil { | ||
61 | return cty.UnknownVal(cty.String), fmt.Errorf("uuidv5() doesn't support namespace %s (%v)", args[0].AsString(), err) | ||
62 | } | ||
63 | } | ||
64 | val := args[1].AsString() | ||
65 | return cty.StringVal(uuidv5.NewV5(namespace, val).String()), nil | ||
66 | }, | ||
67 | }) | ||
68 | |||
35 | // Base64Sha256Func constructs a function that computes the SHA256 hash of a given string | 69 | // Base64Sha256Func constructs a function that computes the SHA256 hash of a given string |
36 | // and encodes it with Base64. | 70 | // and encodes it with Base64. |
37 | var Base64Sha256Func = makeStringHashFunction(sha256.New, base64.StdEncoding.EncodeToString) | 71 | var Base64Sha256Func = makeStringHashFunction(sha256.New, base64.StdEncoding.EncodeToString) |
@@ -228,6 +262,12 @@ func UUID() (cty.Value, error) { | |||
228 | return UUIDFunc.Call(nil) | 262 | return UUIDFunc.Call(nil) |
229 | } | 263 | } |
230 | 264 | ||
265 | // UUIDV5 generates and returns a Type-5 UUID in the standard hexadecimal string | ||
266 | // format. | ||
267 | func UUIDV5(namespace cty.Value, name cty.Value) (cty.Value, error) { | ||
268 | return UUIDV5Func.Call([]cty.Value{namespace, name}) | ||
269 | } | ||
270 | |||
231 | // Base64Sha256 computes the SHA256 hash of a given string and encodes it with | 271 | // Base64Sha256 computes the SHA256 hash of a given string and encodes it with |
232 | // Base64. | 272 | // Base64. |
233 | // | 273 | // |
diff --git a/vendor/github.com/hashicorp/terraform/lang/funcs/filesystem.go b/vendor/github.com/hashicorp/terraform/lang/funcs/filesystem.go index 7dfc905..016b102 100644 --- a/vendor/github.com/hashicorp/terraform/lang/funcs/filesystem.go +++ b/vendor/github.com/hashicorp/terraform/lang/funcs/filesystem.go | |||
@@ -237,6 +237,21 @@ var DirnameFunc = function.New(&function.Spec{ | |||
237 | }, | 237 | }, |
238 | }) | 238 | }) |
239 | 239 | ||
240 | // AbsPathFunc constructs a function that converts a filesystem path to an absolute path | ||
241 | var AbsPathFunc = function.New(&function.Spec{ | ||
242 | Params: []function.Parameter{ | ||
243 | { | ||
244 | Name: "path", | ||
245 | Type: cty.String, | ||
246 | }, | ||
247 | }, | ||
248 | Type: function.StaticReturnType(cty.String), | ||
249 | Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { | ||
250 | absPath, err := filepath.Abs(args[0].AsString()) | ||
251 | return cty.StringVal(filepath.ToSlash(absPath)), err | ||
252 | }, | ||
253 | }) | ||
254 | |||
240 | // PathExpandFunc constructs a function that expands a leading ~ character to the current user's home directory. | 255 | // PathExpandFunc constructs a function that expands a leading ~ character to the current user's home directory. |
241 | var PathExpandFunc = function.New(&function.Spec{ | 256 | var PathExpandFunc = function.New(&function.Spec{ |
242 | Params: []function.Parameter{ | 257 | Params: []function.Parameter{ |