From 863486a6b71ed0e562a3965bed56465d007b1418 Mon Sep 17 00:00:00 2001 From: Alexandre Garand Date: Fri, 9 Aug 2019 15:59:15 +0200 Subject: update vendor and go.mod --- .../hashicorp/terraform/lang/funcs/collection.go | 30 +++++++++++----- .../hashicorp/terraform/lang/funcs/crypto.go | 40 ++++++++++++++++++++++ .../hashicorp/terraform/lang/funcs/filesystem.go | 15 ++++++++ 3 files changed, 77 insertions(+), 8 deletions(-) (limited to 'vendor/github.com/hashicorp/terraform/lang/funcs') 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{ for it := listVal.ElementIterator(); it.Next(); { _, v := it.Element() - if v.AsString() == "" { + if v.IsNull() || v.AsString() == "" { continue } outputList = append(outputList, v) @@ -363,6 +363,9 @@ var DistinctFunc = function.New(&function.Spec{ } } + if len(list) == 0 { + return cty.ListValEmpty(retType.ElementType()), nil + } return cty.ListVal(list), nil }, }) @@ -389,6 +392,10 @@ var ChunklistFunc = function.New(&function.Spec{ return cty.UnknownVal(retType), nil } + if listVal.LengthInt() == 0 { + return cty.ListValEmpty(listVal.Type()), nil + } + var size int err = gocty.FromCtyValue(args[1], &size) if err != nil { @@ -686,8 +693,10 @@ var LookupFunc = function.New(&function.Spec{ return cty.StringVal(v.AsString()), nil case ty.Equals(cty.Number): return cty.NumberVal(v.AsBigFloat()), nil + case ty.Equals(cty.Bool): + return cty.BoolVal(v.True()), nil default: - return cty.NilVal, errors.New("lookup() can only be used with flat lists") + return cty.NilVal, errors.New("lookup() can only be used with maps of primitive types") } } } @@ -797,10 +806,12 @@ var MatchkeysFunc = function.New(&function.Spec{ }, }, Type: func(args []cty.Value) (cty.Type, error) { - if !args[1].Type().Equals(args[2].Type()) { - return cty.NilType, errors.New("lists must be of the same type") + ty, _ := convert.UnifyUnsafe([]cty.Type{args[1].Type(), args[2].Type()}) + if ty == cty.NilType { + return cty.NilType, errors.New("keys and searchset must be of the same type") } + // the return type is based on args[0] (values) return args[0].Type(), nil }, Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) { @@ -813,10 +824,14 @@ var MatchkeysFunc = function.New(&function.Spec{ } output := make([]cty.Value, 0) - values := args[0] - keys := args[1] - searchset := args[2] + + // Keys and searchset must be the same type. + // We can skip error checking here because we've already verified that + // they can be unified in the Type function + ty, _ := convert.UnifyUnsafe([]cty.Type{args[1].Type(), args[2].Type()}) + keys, _ := convert.Convert(args[1], ty) + searchset, _ := convert.Convert(args[2], ty) // if searchset is empty, return an empty list. if searchset.LengthInt() == 0 { @@ -867,7 +882,6 @@ var MergeFunc = function.New(&function.Spec{ Name: "maps", Type: cty.DynamicPseudoType, AllowDynamicType: true, - AllowNull: true, }, Type: function.StaticReturnType(cty.DynamicPseudoType), 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 ( "hash" uuid "github.com/hashicorp/go-uuid" + uuidv5 "github.com/satori/go.uuid" "github.com/zclconf/go-cty/cty" "github.com/zclconf/go-cty/cty/function" "github.com/zclconf/go-cty/cty/gocty" @@ -32,6 +33,39 @@ var UUIDFunc = function.New(&function.Spec{ }, }) +var UUIDV5Func = function.New(&function.Spec{ + Params: []function.Parameter{ + { + Name: "namespace", + Type: cty.String, + }, + { + Name: "name", + Type: cty.String, + }, + }, + Type: function.StaticReturnType(cty.String), + Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) { + var namespace uuidv5.UUID + switch { + case args[0].AsString() == "dns": + namespace = uuidv5.NamespaceDNS + case args[0].AsString() == "url": + namespace = uuidv5.NamespaceURL + case args[0].AsString() == "oid": + namespace = uuidv5.NamespaceOID + case args[0].AsString() == "x500": + namespace = uuidv5.NamespaceX500 + default: + if namespace, err = uuidv5.FromString(args[0].AsString()); err != nil { + return cty.UnknownVal(cty.String), fmt.Errorf("uuidv5() doesn't support namespace %s (%v)", args[0].AsString(), err) + } + } + val := args[1].AsString() + return cty.StringVal(uuidv5.NewV5(namespace, val).String()), nil + }, +}) + // Base64Sha256Func constructs a function that computes the SHA256 hash of a given string // and encodes it with Base64. var Base64Sha256Func = makeStringHashFunction(sha256.New, base64.StdEncoding.EncodeToString) @@ -228,6 +262,12 @@ func UUID() (cty.Value, error) { return UUIDFunc.Call(nil) } +// UUIDV5 generates and returns a Type-5 UUID in the standard hexadecimal string +// format. +func UUIDV5(namespace cty.Value, name cty.Value) (cty.Value, error) { + return UUIDV5Func.Call([]cty.Value{namespace, name}) +} + // Base64Sha256 computes the SHA256 hash of a given string and encodes it with // Base64. // 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{ }, }) +// AbsPathFunc constructs a function that converts a filesystem path to an absolute path +var AbsPathFunc = function.New(&function.Spec{ + Params: []function.Parameter{ + { + Name: "path", + Type: cty.String, + }, + }, + Type: function.StaticReturnType(cty.String), + Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { + absPath, err := filepath.Abs(args[0].AsString()) + return cty.StringVal(filepath.ToSlash(absPath)), err + }, +}) + // PathExpandFunc constructs a function that expands a leading ~ character to the current user's home directory. var PathExpandFunc = function.New(&function.Spec{ Params: []function.Parameter{ -- cgit v1.2.3