diff options
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/lang')
8 files changed, 100 insertions, 13 deletions
diff --git a/vendor/github.com/hashicorp/terraform/lang/blocktoattr/schema.go b/vendor/github.com/hashicorp/terraform/lang/blocktoattr/schema.go index 2f2463a..47a0256 100644 --- a/vendor/github.com/hashicorp/terraform/lang/blocktoattr/schema.go +++ b/vendor/github.com/hashicorp/terraform/lang/blocktoattr/schema.go | |||
@@ -55,10 +55,11 @@ func effectiveSchema(given *hcl.BodySchema, body hcl.Body, ambiguousNames map[st | |||
55 | }, | 55 | }, |
56 | } | 56 | } |
57 | content, _, _ = body.PartialContent(&probeSchema) | 57 | content, _, _ = body.PartialContent(&probeSchema) |
58 | if len(content.Blocks) > 0 { | 58 | if len(content.Blocks) > 0 || dynamicExpanded { |
59 | // No attribute present and at least one block present, so | 59 | // A dynamic block with an empty iterator returns nothing. |
60 | // we'll need to rewrite this one as a block for a successful | 60 | // If there's no attribute and we have either a block or a |
61 | // result. | 61 | // dynamic expansion, we need to rewrite this one as a |
62 | // block for a successful result. | ||
62 | appearsAsBlock[name] = struct{}{} | 63 | appearsAsBlock[name] = struct{}{} |
63 | } | 64 | } |
64 | } | 65 | } |
diff --git a/vendor/github.com/hashicorp/terraform/lang/blocktoattr/variables.go b/vendor/github.com/hashicorp/terraform/lang/blocktoattr/variables.go index e123b8a..b172805 100644 --- a/vendor/github.com/hashicorp/terraform/lang/blocktoattr/variables.go +++ b/vendor/github.com/hashicorp/terraform/lang/blocktoattr/variables.go | |||
@@ -33,7 +33,7 @@ func walkVariables(node dynblock.WalkVariablesNode, body hcl.Body, schema *confi | |||
33 | for _, child := range children { | 33 | for _, child := range children { |
34 | if blockS, exists := schema.BlockTypes[child.BlockTypeName]; exists { | 34 | if blockS, exists := schema.BlockTypes[child.BlockTypeName]; exists { |
35 | vars = append(vars, walkVariables(child.Node, child.Body(), &blockS.Block)...) | 35 | vars = append(vars, walkVariables(child.Node, child.Body(), &blockS.Block)...) |
36 | } else if attrS, exists := schema.Attributes[child.BlockTypeName]; exists { | 36 | } else if attrS, exists := schema.Attributes[child.BlockTypeName]; exists && attrS.Type.ElementType().IsObjectType() { |
37 | synthSchema := SchemaForCtyElementType(attrS.Type.ElementType()) | 37 | synthSchema := SchemaForCtyElementType(attrS.Type.ElementType()) |
38 | vars = append(vars, walkVariables(child.Node, child.Body(), synthSchema)...) | 38 | vars = append(vars, walkVariables(child.Node, child.Body(), synthSchema)...) |
39 | } | 39 | } |
diff --git a/vendor/github.com/hashicorp/terraform/lang/data.go b/vendor/github.com/hashicorp/terraform/lang/data.go index 80313d6..eca588e 100644 --- a/vendor/github.com/hashicorp/terraform/lang/data.go +++ b/vendor/github.com/hashicorp/terraform/lang/data.go | |||
@@ -23,6 +23,7 @@ type Data interface { | |||
23 | StaticValidateReferences(refs []*addrs.Reference, self addrs.Referenceable) tfdiags.Diagnostics | 23 | StaticValidateReferences(refs []*addrs.Reference, self addrs.Referenceable) tfdiags.Diagnostics |
24 | 24 | ||
25 | GetCountAttr(addrs.CountAttr, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics) | 25 | GetCountAttr(addrs.CountAttr, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics) |
26 | GetForEachAttr(addrs.ForEachAttr, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics) | ||
26 | GetResourceInstance(addrs.ResourceInstance, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics) | 27 | GetResourceInstance(addrs.ResourceInstance, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics) |
27 | GetLocalValue(addrs.LocalValue, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics) | 28 | GetLocalValue(addrs.LocalValue, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics) |
28 | GetModuleInstance(addrs.ModuleCallInstance, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics) | 29 | GetModuleInstance(addrs.ModuleCallInstance, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics) |
diff --git a/vendor/github.com/hashicorp/terraform/lang/eval.go b/vendor/github.com/hashicorp/terraform/lang/eval.go index a3fb363..a8fe8b6 100644 --- a/vendor/github.com/hashicorp/terraform/lang/eval.go +++ b/vendor/github.com/hashicorp/terraform/lang/eval.go | |||
@@ -203,6 +203,7 @@ func (s *Scope) evalContext(refs []*addrs.Reference, selfAddr addrs.Referenceabl | |||
203 | pathAttrs := map[string]cty.Value{} | 203 | pathAttrs := map[string]cty.Value{} |
204 | terraformAttrs := map[string]cty.Value{} | 204 | terraformAttrs := map[string]cty.Value{} |
205 | countAttrs := map[string]cty.Value{} | 205 | countAttrs := map[string]cty.Value{} |
206 | forEachAttrs := map[string]cty.Value{} | ||
206 | var self cty.Value | 207 | var self cty.Value |
207 | 208 | ||
208 | for _, ref := range refs { | 209 | for _, ref := range refs { |
@@ -334,6 +335,14 @@ func (s *Scope) evalContext(refs []*addrs.Reference, selfAddr addrs.Referenceabl | |||
334 | self = val | 335 | self = val |
335 | } | 336 | } |
336 | 337 | ||
338 | case addrs.ForEachAttr: | ||
339 | val, valDiags := normalizeRefValue(s.Data.GetForEachAttr(subj, rng)) | ||
340 | diags = diags.Append(valDiags) | ||
341 | forEachAttrs[subj.Name] = val | ||
342 | if isSelf { | ||
343 | self = val | ||
344 | } | ||
345 | |||
337 | default: | 346 | default: |
338 | // Should never happen | 347 | // Should never happen |
339 | panic(fmt.Errorf("Scope.buildEvalContext cannot handle address type %T", rawSubj)) | 348 | panic(fmt.Errorf("Scope.buildEvalContext cannot handle address type %T", rawSubj)) |
@@ -350,6 +359,7 @@ func (s *Scope) evalContext(refs []*addrs.Reference, selfAddr addrs.Referenceabl | |||
350 | vals["path"] = cty.ObjectVal(pathAttrs) | 359 | vals["path"] = cty.ObjectVal(pathAttrs) |
351 | vals["terraform"] = cty.ObjectVal(terraformAttrs) | 360 | vals["terraform"] = cty.ObjectVal(terraformAttrs) |
352 | vals["count"] = cty.ObjectVal(countAttrs) | 361 | vals["count"] = cty.ObjectVal(countAttrs) |
362 | vals["each"] = cty.ObjectVal(forEachAttrs) | ||
353 | if self != cty.NilVal { | 363 | if self != cty.NilVal { |
354 | vals["self"] = self | 364 | vals["self"] = self |
355 | } | 365 | } |
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{ |
diff --git a/vendor/github.com/hashicorp/terraform/lang/functions.go b/vendor/github.com/hashicorp/terraform/lang/functions.go index 2c7b548..b77a55f 100644 --- a/vendor/github.com/hashicorp/terraform/lang/functions.go +++ b/vendor/github.com/hashicorp/terraform/lang/functions.go | |||
@@ -3,6 +3,7 @@ package lang | |||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | 5 | ||
6 | ctyyaml "github.com/zclconf/go-cty-yaml" | ||
6 | "github.com/zclconf/go-cty/cty" | 7 | "github.com/zclconf/go-cty/cty" |
7 | "github.com/zclconf/go-cty/cty/function" | 8 | "github.com/zclconf/go-cty/cty/function" |
8 | "github.com/zclconf/go-cty/cty/function/stdlib" | 9 | "github.com/zclconf/go-cty/cty/function/stdlib" |
@@ -30,6 +31,7 @@ func (s *Scope) Functions() map[string]function.Function { | |||
30 | 31 | ||
31 | s.funcs = map[string]function.Function{ | 32 | s.funcs = map[string]function.Function{ |
32 | "abs": stdlib.AbsoluteFunc, | 33 | "abs": stdlib.AbsoluteFunc, |
34 | "abspath": funcs.AbsPathFunc, | ||
33 | "basename": funcs.BasenameFunc, | 35 | "basename": funcs.BasenameFunc, |
34 | "base64decode": funcs.Base64DecodeFunc, | 36 | "base64decode": funcs.Base64DecodeFunc, |
35 | "base64encode": funcs.Base64EncodeFunc, | 37 | "base64encode": funcs.Base64EncodeFunc, |
@@ -85,6 +87,7 @@ func (s *Scope) Functions() map[string]function.Function { | |||
85 | "min": stdlib.MinFunc, | 87 | "min": stdlib.MinFunc, |
86 | "pathexpand": funcs.PathExpandFunc, | 88 | "pathexpand": funcs.PathExpandFunc, |
87 | "pow": funcs.PowFunc, | 89 | "pow": funcs.PowFunc, |
90 | "range": stdlib.RangeFunc, | ||
88 | "replace": funcs.ReplaceFunc, | 91 | "replace": funcs.ReplaceFunc, |
89 | "reverse": funcs.ReverseFunc, | 92 | "reverse": funcs.ReverseFunc, |
90 | "rsadecrypt": funcs.RsaDecryptFunc, | 93 | "rsadecrypt": funcs.RsaDecryptFunc, |
@@ -114,7 +117,10 @@ func (s *Scope) Functions() map[string]function.Function { | |||
114 | "upper": stdlib.UpperFunc, | 117 | "upper": stdlib.UpperFunc, |
115 | "urlencode": funcs.URLEncodeFunc, | 118 | "urlencode": funcs.URLEncodeFunc, |
116 | "uuid": funcs.UUIDFunc, | 119 | "uuid": funcs.UUIDFunc, |
120 | "uuidv5": funcs.UUIDV5Func, | ||
117 | "values": funcs.ValuesFunc, | 121 | "values": funcs.ValuesFunc, |
122 | "yamldecode": ctyyaml.YAMLDecodeFunc, | ||
123 | "yamlencode": ctyyaml.YAMLEncodeFunc, | ||
118 | "zipmap": funcs.ZipmapFunc, | 124 | "zipmap": funcs.ZipmapFunc, |
119 | } | 125 | } |
120 | 126 | ||