diff --git a/internal/funcs/0.12/base_functions.go b/internal/funcs/0.12/base_functions.go new file mode 100644 index 00000000..b86b48d5 --- /dev/null +++ b/internal/funcs/0.12/base_functions.go @@ -0,0 +1,980 @@ +package funcs + +import ( + "github.com/hashicorp/hcl-lang/schema" + "github.com/zclconf/go-cty/cty" + "github.com/zclconf/go-cty/cty/function" +) + +func BaseFunctions() map[string]schema.FuncSignature { + return map[string]schema.FuncSignature{ + "abs": { + Params: []function.Parameter{ + { + Name: "num", + Type: cty.Number, + }, + }, + ReturnTypes: cty.Number, + Description: "`abs` returns the absolute value of the given number. In other words, if the number is zero or positive then it is returned as-is, but if it is negative then it is multiplied by -1 to make it positive before returning it.", + }, + "base64decode": { + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`base64decode` takes a string containing a Base64 character sequence and returns the original string.", + }, + "base64encode": { + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`base64encode` applies Base64 encoding to a string.", + }, + "base64gzip": { + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`base64gzip` compresses a string with gzip and then encodes the result in Base64 encoding.", + }, + "base64sha256": { + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`base64sha256` computes the SHA256 hash of a given string and encodes it with Base64. This is not equivalent to `base64encode(sha256("test"))` since `sha256()` returns hexadecimal representation.", + }, + "base64sha512": { + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`base64sha512` computes the SHA512 hash of a given string and encodes it with Base64. This is not equivalent to `base64encode(sha512("test"))` since `sha512()` returns hexadecimal representation.", + }, + "basename": { + Params: []function.Parameter{ + { + Name: "path", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`basename` takes a string containing a filesystem path and removes all except the last portion from it.", + }, + "bcrypt": { + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + }, + VarParam: &function.Parameter{ + Name: "cost", + Description: "The `cost` argument is optional and will default to 10 if unspecified.", + Type: cty.Number, + }, + ReturnTypes: cty.String, + Description: "`bcrypt` computes a hash of the given string using the Blowfish cipher, returning a string in [the _Modular Crypt Format_](https://passlib.readthedocs.io/en/stable/modular_crypt_format.html) usually expected in the shadow password file on many Unix systems.", + }, + "ceil": { + Params: []function.Parameter{ + { + Name: "num", + Type: cty.Number, + }, + }, + ReturnTypes: cty.Number, + Description: "`ceil` returns the closest whole number that is greater than or equal to the given value, which may be a fraction.", + }, + "chomp": { + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`chomp` removes newline characters at the end of a string.", + }, + "chunklist": { + Params: []function.Parameter{ + { + Name: "list", + Type: cty.List(cty.DynamicPseudoType), + }, + { + Name: "size", + Description: "The maximum length of each chunk. All but the last element of the result is guaranteed to be of exactly this size.", + Type: cty.Number, + }, + }, + ReturnTypes: cty.List(cty.List(cty.DynamicPseudoType)), + Description: "`chunklist` splits a single list into fixed-size chunks, returning a list of lists.", + }, + "cidrhost": { + Params: []function.Parameter{ + { + Name: "prefix", + Description: "`prefix` must be given in CIDR notation, as defined in [RFC 4632 section 3.1](https://tools.ietf.org/html/rfc4632#section-3.1).", + Type: cty.String, + }, + { + Name: "hostnum", + Description: "`hostnum` is a whole number that can be represented as a binary integer with no more than the number of digits remaining in the address after the given prefix.", + Type: cty.Number, + }, + }, + ReturnTypes: cty.String, + Description: "`cidrhost` calculates a full host IP address for a given host number within a given IP network address prefix.", + }, + "cidrnetmask": { + Params: []function.Parameter{ + { + Name: "prefix", + Description: "`prefix` must be given in CIDR notation, as defined in [RFC 4632 section 3.1](https://tools.ietf.org/html/rfc4632#section-3.1).", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`cidrnetmask` converts an IPv4 address prefix given in CIDR notation into a subnet mask address.", + }, + "cidrsubnet": { + Params: []function.Parameter{ + { + Name: "prefix", + Description: "`prefix` must be given in CIDR notation, as defined in [RFC 4632 section 3.1](https://tools.ietf.org/html/rfc4632#section-3.1).", + Type: cty.String, + }, + { + Name: "newbits", + Description: "`newbits` is the number of additional bits with which to extend the prefix.", + Type: cty.Number, + }, + { + Name: "netnum", + Description: "`netnum` is a whole number that can be represented as a binary integer with no more than `newbits` binary digits, which will be used to populate the additional bits added to the prefix.", + Type: cty.Number, + }, + }, + ReturnTypes: cty.String, + Description: "`cidrsubnet` calculates a subnet address within given IP network address prefix.", + }, + "coalesce": { + VarParam: &function.Parameter{ + Name: "vals", + Type: cty.DynamicPseudoType, + }, + ReturnTypes: cty.DynamicPseudoType, + Description: "`coalesce` takes any number of arguments and returns the first one that isn't null or an empty string.", + }, + "coalescelist": { + VarParam: &function.Parameter{ + Name: "vals", + Description: "List or tuple values to test in the given order.", + Type: cty.DynamicPseudoType, + }, + ReturnTypes: cty.DynamicPseudoType, + Description: "`coalescelist` takes any number of list arguments and returns the first one that isn't empty.", + }, + "compact": { + Params: []function.Parameter{ + { + Name: "list", + Type: cty.List(cty.String), + }, + }, + ReturnTypes: cty.List(cty.String), + Description: "`compact` takes a list of strings and returns a new list with any empty string elements removed.", + }, + "concat": { + VarParam: &function.Parameter{ + Name: "seqs", + Type: cty.DynamicPseudoType, + }, + ReturnTypes: cty.DynamicPseudoType, + Description: "`concat` takes two or more lists and combines them into a single list.", + }, + "contains": { + Params: []function.Parameter{ + { + Name: "list", + Type: cty.DynamicPseudoType, + }, + { + Name: "value", + Type: cty.DynamicPseudoType, + }, + }, + ReturnTypes: cty.DynamicPseudoType, + Description: "`contains` determines whether a given list or set contains a given single value as one of its elements.", + }, + "csvdecode": { + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + }, + ReturnTypes: cty.DynamicPseudoType, + Description: "`csvdecode` decodes a string containing CSV-formatted data and produces a list of maps representing that data.", + }, + "dirname": { + Params: []function.Parameter{ + { + Name: "path", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`dirname` takes a string containing a filesystem path and removes the last portion from it.", + }, + "distinct": { + Params: []function.Parameter{ + { + Name: "list", + Type: cty.List(cty.DynamicPseudoType), + }, + }, + ReturnTypes: cty.List(cty.DynamicPseudoType), + Description: "`distinct` takes a list and returns a new list with any duplicate elements removed.", + }, + "element": { + Params: []function.Parameter{ + { + Name: "list", + Type: cty.DynamicPseudoType, + }, + { + Name: "index", + Type: cty.Number, + }, + }, + ReturnTypes: cty.DynamicPseudoType, + Description: "`element` retrieves a single element from a list.", + }, + "file": { + Params: []function.Parameter{ + { + Name: "path", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`file` reads the contents of a file at the given path and returns them as a string.", + }, + "filebase64": { + Params: []function.Parameter{ + { + Name: "path", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`filebase64` reads the contents of a file at the given path and returns them as a base64-encoded string.", + }, + "filebase64sha256": { + Params: []function.Parameter{ + { + Name: "path", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`filebase64sha256` is a variant of `base64sha256` that hashes the contents of a given file rather than a literal string.", + }, + "filebase64sha512": { + Params: []function.Parameter{ + { + Name: "path", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`filebase64sha512` is a variant of `base64sha512` that hashes the contents of a given file rather than a literal string.", + }, + "fileexists": { + Params: []function.Parameter{ + { + Name: "path", + Type: cty.String, + }, + }, + ReturnTypes: cty.Bool, + Description: "`fileexists` determines whether a file exists at a given path.", + }, + "filemd5": { + Params: []function.Parameter{ + { + Name: "path", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`filemd5` is a variant of `md5` that hashes the contents of a given file rather than a literal string.", + }, + "filesha1": { + Params: []function.Parameter{ + { + Name: "path", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`filesha1` is a variant of `sha1` that hashes the contents of a given file rather than a literal string.", + }, + "filesha256": { + Params: []function.Parameter{ + { + Name: "path", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`filesha256` is a variant of `sha256` that hashes the contents of a given file rather than a literal string.", + }, + "filesha512": { + Params: []function.Parameter{ + { + Name: "path", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`filesha512` is a variant of `sha512` that hashes the contents of a given file rather than a literal string.", + }, + "flatten": { + Params: []function.Parameter{ + { + Name: "list", + Type: cty.DynamicPseudoType, + }, + }, + ReturnTypes: cty.DynamicPseudoType, + Description: "`flatten` takes a list and replaces any elements that are lists with a flattened sequence of the list contents.", + }, + "floor": { + Params: []function.Parameter{ + { + Name: "num", + Type: cty.Number, + }, + }, + ReturnTypes: cty.Number, + Description: "`floor` returns the closest whole number that is less than or equal to the given value, which may be a fraction.", + }, + "format": { + Params: []function.Parameter{ + { + Name: "format", + Type: cty.String, + }, + }, + VarParam: &function.Parameter{ + Name: "args", + Type: cty.DynamicPseudoType, + }, + ReturnTypes: cty.DynamicPseudoType, + Description: "The `format` function produces a string by formatting a number of other values according to a specification string. It is similar to the `printf` function in C, and other similar functions in other programming languages.", + }, + "formatdate": { + Params: []function.Parameter{ + { + Name: "format", + Type: cty.String, + }, + { + Name: "time", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`formatdate` converts a timestamp into a different time format.", + }, + "formatlist": { + Params: []function.Parameter{ + { + Name: "format", + Type: cty.String, + }, + }, + VarParam: &function.Parameter{ + Name: "args", + Type: cty.DynamicPseudoType, + }, + ReturnTypes: cty.DynamicPseudoType, + Description: "`formatlist` produces a list of strings by formatting a number of other values according to a specification string.", + }, + "indent": { + Params: []function.Parameter{ + { + Name: "spaces", + Description: "Number of spaces to add after each newline character.", + Type: cty.Number, + }, + { + Name: "str", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`indent` adds a given number of spaces to the beginnings of all but the first line in a given multi-line string.", + }, + "index": { + Params: []function.Parameter{ + { + Name: "list", + Type: cty.DynamicPseudoType, + }, + { + Name: "value", + Type: cty.DynamicPseudoType, + }, + }, + ReturnTypes: cty.DynamicPseudoType, + Description: "`index` finds the element index for a given value in a list.", + }, + "join": { + Params: []function.Parameter{ + { + Name: "separator", + Description: "Delimiter to insert between the given strings.", + Type: cty.String, + }, + }, + VarParam: &function.Parameter{ + Name: "lists", + Description: "One or more lists of strings to join.", + Type: cty.List(cty.String), + }, + ReturnTypes: cty.String, + Description: "`join` produces a string by concatenating together all elements of a given list of strings with the given delimiter.", + }, + "jsondecode": { + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + }, + ReturnTypes: cty.DynamicPseudoType, + Description: "`jsondecode` interprets a given string as JSON, returning a representation of the result of decoding that string.", + }, + "jsonencode": { + Params: []function.Parameter{ + { + Name: "val", + Type: cty.DynamicPseudoType, + }, + }, + ReturnTypes: cty.String, + Description: "`jsonencode` encodes a given value to a string using JSON syntax.", + }, + "keys": { + Params: []function.Parameter{ + { + Name: "inputMap", + Description: "The map to extract keys from. May instead be an object-typed value, in which case the result is a tuple of the object attributes.", + Type: cty.DynamicPseudoType, + }, + }, + ReturnTypes: cty.DynamicPseudoType, + Description: "`keys` takes a map and returns a list containing the keys from that map.", + }, + "length": { + Params: []function.Parameter{ + { + Name: "value", + Type: cty.DynamicPseudoType, + }, + }, + ReturnTypes: cty.Number, + Description: "`length` determines the length of a given list, map, or string.", + }, + // "list": {} // TODO! + "log": { + Params: []function.Parameter{ + { + Name: "num", + Type: cty.Number, + }, + { + Name: "base", + Type: cty.Number, + }, + }, + ReturnTypes: cty.Number, + Description: "`log` returns the logarithm of a given number in a given base.", + }, + "lookup": { + Params: []function.Parameter{ + { + Name: "inputMap", + Type: cty.DynamicPseudoType, + }, + { + Name: "key", + Type: cty.String, + }, + }, + VarParam: &function.Parameter{ + Name: "default", + Type: cty.DynamicPseudoType, + }, + ReturnTypes: cty.DynamicPseudoType, + Description: "`lookup` retrieves the value of a single element from a map, given its key. If the given key does not exist, the given default value is returned instead.", + }, + "lower": { + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`lower` converts all cased letters in the given string to lowercase.", + }, + // "map": {} // TODO! + "matchkeys": { + Params: []function.Parameter{ + { + Name: "values", + Type: cty.List(cty.DynamicPseudoType), + }, + { + Name: "keys", + Type: cty.List(cty.DynamicPseudoType), + }, + { + Name: "searchset", + Type: cty.List(cty.DynamicPseudoType), + }, + }, + ReturnTypes: cty.List(cty.DynamicPseudoType), + Description: "`matchkeys` constructs a new list by taking a subset of elements from one list whose indexes match the corresponding indexes of values in another list.", + }, + "max": { + VarParam: &function.Parameter{ + Name: "numbers", + Type: cty.Number, + }, + ReturnTypes: cty.Number, + Description: "`max` takes one or more numbers and returns the greatest number from the set.", + }, + "md5": { + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`md5` computes the MD5 hash of a given string and encodes it with hexadecimal digits.", + }, + "merge": { + VarParam: &function.Parameter{ + Name: "maps", + Type: cty.DynamicPseudoType, + }, + ReturnTypes: cty.DynamicPseudoType, + Description: "`merge` takes an arbitrary number of maps or objects, and returns a single map or object that contains a merged set of elements from all arguments.", + }, + "min": { + VarParam: &function.Parameter{ + Name: "numbers", + Type: cty.Number, + }, + ReturnTypes: cty.Number, + Description: "`min` takes one or more numbers and returns the smallest number from the set.", + }, + "pathexpand": { + Params: []function.Parameter{ + { + Name: "path", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`pathexpand` takes a filesystem path that might begin with a `~` segment, and if so it replaces that segment with the current user's home directory path.", + }, + "pow": { + Params: []function.Parameter{ + { + Name: "num", + Type: cty.Number, + }, + { + Name: "power", + Type: cty.Number, + }, + }, + ReturnTypes: cty.Number, + Description: "`pow` calculates an exponent, by raising its first argument to the power of the second argument.", + }, + "replace": { + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + { + Name: "substr", + Type: cty.String, + }, + { + Name: "replace", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`replace` searches a given string for another given substring, and replaces each occurrence with a given replacement string.", + }, + "reverse": { + Params: []function.Parameter{ + { + Name: "list", + Type: cty.DynamicPseudoType, + }, + }, + ReturnTypes: cty.DynamicPseudoType, + Description: "`reverse` takes a sequence and produces a new sequence of the same length with all of the same elements as the given sequence but in reverse order.", + }, + "rsadecrypt": { + Params: []function.Parameter{ + { + Name: "ciphertext", + Type: cty.String, + }, + { + Name: "privatekey", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`rsadecrypt` decrypts an RSA-encrypted ciphertext, returning the corresponding cleartext.", + }, + "setintersection": { + Params: []function.Parameter{ + { + Name: "first_set", + Type: cty.Set(cty.DynamicPseudoType), + }, + }, + VarParam: &function.Parameter{ + Name: "other_sets", + Type: cty.Set(cty.DynamicPseudoType), + }, + ReturnTypes: cty.Set(cty.DynamicPseudoType), + Description: "The `setintersection` function takes multiple sets and produces a single set containing only the elements that all of the given sets have in common. In other words, it computes the [intersection](https://en.wikipedia.org/wiki/Intersection_\\(set_theory\\)) of the sets.", + }, + "setproduct": { + VarParam: &function.Parameter{ + Name: "sets", + Description: "The sets to consider. Also accepts lists and tuples, and if all arguments are of list or tuple type then the result will preserve the input ordering", + Type: cty.DynamicPseudoType, + }, + ReturnTypes: cty.DynamicPseudoType, + Description: "The `setproduct` function finds all of the possible combinations of elements from all of the given sets by computing the [Cartesian product](https://en.wikipedia.org/wiki/Cartesian_product).", + }, + "setunion": { + Params: []function.Parameter{ + { + Name: "first_set", + Type: cty.Set(cty.DynamicPseudoType), + }, + }, + VarParam: &function.Parameter{ + Name: "other_sets", + Type: cty.Set(cty.DynamicPseudoType), + }, + ReturnTypes: cty.Set(cty.DynamicPseudoType), + Description: "The `setunion` function takes multiple sets and produces a single set containing the elements from all of the given sets. In other words, it computes the [union](https://en.wikipedia.org/wiki/Union_\\(set_theory\\)) of the sets.", + }, + "sha1": { + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`sha1` computes the SHA1 hash of a given string and encodes it with hexadecimal digits.", + }, + "sha256": { + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`sha256` computes the SHA256 hash of a given string and encodes it with hexadecimal digits.", + }, + "sha512": { + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`sha512` computes the SHA512 hash of a given string and encodes it with hexadecimal digits.", + }, + "signum": { + Params: []function.Parameter{ + { + Name: "num", + Type: cty.Number, + }, + }, + ReturnTypes: cty.Number, + Description: "`signum` determines the sign of a number, returning a number between -1 and 1 to represent the sign.", + }, + "slice": { + Params: []function.Parameter{ + { + Name: "list", + Type: cty.DynamicPseudoType, + }, + { + Name: "start_index", + Type: cty.Number, + }, + { + Name: "end_index", + Type: cty.Number, + }, + }, + ReturnTypes: cty.DynamicPseudoType, + Description: "`slice` extracts some consecutive elements from within a list.", + }, + "sort": { + Params: []function.Parameter{ + { + Name: "list", + Type: cty.List(cty.String), + }, + }, + ReturnTypes: cty.List(cty.String), + Description: "`sort` takes a list of strings and returns a new list with those strings sorted lexicographically.", + }, + "split": { + Params: []function.Parameter{ + { + Name: "separator", + Type: cty.String, + }, + { + Name: "str", + Type: cty.String, + }, + }, + ReturnTypes: cty.List(cty.String), + Description: "`split` produces a list by dividing a given string at all occurrences of a given separator.", + }, + "strrev": { + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`strrev` reverses the characters in a string. Note that the characters are treated as _Unicode characters_ (in technical terms, Unicode [grapheme cluster boundaries](https://unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries) are respected).", + }, + "substr": { + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + { + Name: "offset", + Type: cty.Number, + }, + { + Name: "length", + Type: cty.Number, + }, + }, + ReturnTypes: cty.String, + Description: "`substr` extracts a substring from a given string by offset and (maximum) length.", + }, + "templatefile": { + Params: []function.Parameter{ + { + Name: "path", + Type: cty.String, + }, + { + Name: "vars", + Type: cty.DynamicPseudoType, + }, + }, + ReturnTypes: cty.DynamicPseudoType, + Description: "`templatefile` reads the file at the given path and renders its content as a template using a supplied set of template variables.", + }, + "timeadd": { + Params: []function.Parameter{ + { + Name: "timestamp", + Type: cty.String, + }, + { + Name: "duration", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`timeadd` adds a duration to a timestamp, returning a new timestamp.", + }, + "timestamp": { + ReturnTypes: cty.String, + Description: "`timestamp` returns a UTC timestamp string in [RFC 3339](https://tools.ietf.org/html/rfc3339) format.", + }, + "title": { + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`title` converts the first letter of each word in the given string to uppercase.", + }, + "tobool": { + Params: []function.Parameter{ + { + Name: "v", + Type: cty.DynamicPseudoType, + }, + }, + ReturnTypes: cty.Bool, + Description: "`tobool` converts its argument to a boolean value.", + }, + "tolist": { + Params: []function.Parameter{ + { + Name: "v", + Type: cty.DynamicPseudoType, + }, + }, + ReturnTypes: cty.List(cty.DynamicPseudoType), + Description: "`tolist` converts its argument to a list value.", + }, + "tomap": { + Params: []function.Parameter{ + { + Name: "v", + Type: cty.DynamicPseudoType, + }, + }, + ReturnTypes: cty.Map(cty.DynamicPseudoType), + Description: "`tomap` converts its argument to a map value.", + }, + "tonumber": { + Params: []function.Parameter{ + { + Name: "v", + Type: cty.DynamicPseudoType, + }, + }, + ReturnTypes: cty.Number, + Description: "`tonumber` converts its argument to a number value.", + }, + "toset": { + Params: []function.Parameter{ + { + Name: "v", + Type: cty.DynamicPseudoType, + }, + }, + ReturnTypes: cty.Set(cty.DynamicPseudoType), + Description: "`toset` converts its argument to a set value.", + }, + "tostring": { + Params: []function.Parameter{ + { + Name: "v", + Type: cty.DynamicPseudoType, + }, + }, + ReturnTypes: cty.String, + Description: "`tostring` converts its argument to a string value.", + }, + "transpose": { + Params: []function.Parameter{ + { + Name: "values", + Type: cty.Map(cty.List(cty.String)), + }, + }, + ReturnTypes: cty.Map(cty.List(cty.String)), + Description: "`transpose` takes a map of lists of strings and swaps the keys and values to produce a new map of lists of strings.", + }, + "upper": { + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`upper` converts all cased letters in the given string to uppercase.", + }, + "urlencode": { + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`urlencode` applies URL encoding to a given string.", + }, + "uuid": { + ReturnTypes: cty.String, + Description: "`uuid` generates a unique identifier string.", + }, + "values": { + Params: []function.Parameter{ + { + Name: "mapping", + Type: cty.DynamicPseudoType, + }, + }, + ReturnTypes: cty.DynamicPseudoType, + Description: "`values` takes a map and returns a list containing the values of the elements in that map.", + }, + "zipmap": { + Params: []function.Parameter{ + { + Name: "keys", + Type: cty.List(cty.String), + }, + { + Name: "values", + Type: cty.DynamicPseudoType, + }, + }, + ReturnTypes: cty.DynamicPseudoType, + Description: "`zipmap` constructs a map from a list of keys and a corresponding list of values.", + }, + } +} diff --git a/internal/funcs/0.12/base_stdlib_gen.go b/internal/funcs/0.12/base_stdlib_gen.go deleted file mode 100755 index 9ae53298..00000000 --- a/internal/funcs/0.12/base_stdlib_gen.go +++ /dev/null @@ -1,512 +0,0 @@ -// Code generated by "funcgen"; DO NOT EDIT. -package funcs - -import ( - "github.com/hashicorp/hcl-lang/schema" - "github.com/zclconf/go-cty/cty" - "github.com/zclconf/go-cty/cty/function" -) - -func BaseStdlibFunctions() map[string]schema.FuncSignature { - return map[string]schema.FuncSignature{ - "abs": { - Params: []function.Parameter{ - { - Name: "num", - Type: cty.Number, - }, - }, - ReturnTypes: cty.Number, - Description: "`abs` returns the absolute value of the given number. In other words, if the number is zero or positive then it is returned as-is, but if it is negative then it is multiplied by -1 to make it positive before returning it.", - }, - "ceil": { - Params: []function.Parameter{ - { - Name: "num", - Type: cty.Number, - }, - }, - ReturnTypes: cty.Number, - Description: "`ceil` returns the closest whole number that is greater than or equal to the given value, which may be a fraction.", - }, - "chomp": { - Params: []function.Parameter{ - { - Name: "str", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`chomp` removes newline characters at the end of a string.", - }, - "chunklist": { - Params: []function.Parameter{ - { - Name: "list", - Type: cty.List(cty.DynamicPseudoType), - }, - { - Name: "size", - Description: "The maximum length of each chunk. All but the last element of the result is guaranteed to be of exactly this size.", - Type: cty.Number, - }, - }, - ReturnTypes: cty.List(cty.List(cty.DynamicPseudoType)), - Description: "`chunklist` splits a single list into fixed-size chunks, returning a list of lists.", - }, - "coalescelist": { - VarParam: &function.Parameter{ - Name: "vals", - Description: "List or tuple values to test in the given order.", - Type: cty.DynamicPseudoType, - }, - ReturnTypes: cty.DynamicPseudoType, - Description: "`coalescelist` takes any number of list arguments and returns the first one that isn't empty.", - }, - "compact": { - Params: []function.Parameter{ - { - Name: "list", - Type: cty.List(cty.String), - }, - }, - ReturnTypes: cty.List(cty.String), - Description: "`compact` takes a list of strings and returns a new list with any empty string elements removed.", - }, - "concat": { - VarParam: &function.Parameter{ - Name: "seqs", - Description: "", - Type: cty.DynamicPseudoType, - }, - ReturnTypes: cty.DynamicPseudoType, - Description: "`concat` takes two or more lists and combines them into a single list.", - }, - "contains": { - Params: []function.Parameter{ - { - Name: "list", - Type: cty.DynamicPseudoType, - }, - { - Name: "value", - Type: cty.DynamicPseudoType, - }, - }, - ReturnTypes: cty.DynamicPseudoType, - Description: "`contains` determines whether a given list or set contains a given single value as one of its elements.", - }, - "csvdecode": { - Params: []function.Parameter{ - { - Name: "str", - Type: cty.String, - }, - }, - ReturnTypes: cty.DynamicPseudoType, - Description: "`csvdecode` decodes a string containing CSV-formatted data and produces a list of maps representing that data.", - }, - "distinct": { - Params: []function.Parameter{ - { - Name: "list", - Type: cty.List(cty.DynamicPseudoType), - }, - }, - ReturnTypes: cty.List(cty.DynamicPseudoType), - Description: "`distinct` takes a list and returns a new list with any duplicate elements removed.", - }, - "element": { - Params: []function.Parameter{ - { - Name: "list", - Type: cty.DynamicPseudoType, - }, - { - Name: "index", - Type: cty.Number, - }, - }, - ReturnTypes: cty.DynamicPseudoType, - Description: "`element` retrieves a single element from a list.", - }, - "flatten": { - Params: []function.Parameter{ - { - Name: "list", - Type: cty.DynamicPseudoType, - }, - }, - ReturnTypes: cty.DynamicPseudoType, - Description: "`flatten` takes a list and replaces any elements that are lists with a flattened sequence of the list contents.", - }, - "floor": { - Params: []function.Parameter{ - { - Name: "num", - Type: cty.Number, - }, - }, - ReturnTypes: cty.Number, - Description: "`floor` returns the closest whole number that is less than or equal to the given value, which may be a fraction.", - }, - "format": { - Params: []function.Parameter{ - { - Name: "format", - Type: cty.String, - }, - }, - VarParam: &function.Parameter{ - Name: "args", - Description: "", - Type: cty.DynamicPseudoType, - }, - ReturnTypes: cty.DynamicPseudoType, - Description: "The `format` function produces a string by formatting a number of other values according to a specification string. It is similar to the `printf` function in C, and other similar functions in other programming languages.", - }, - "formatdate": { - Params: []function.Parameter{ - { - Name: "format", - Type: cty.String, - }, - { - Name: "time", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`formatdate` converts a timestamp into a different time format.", - }, - "formatlist": { - Params: []function.Parameter{ - { - Name: "format", - Type: cty.String, - }, - }, - VarParam: &function.Parameter{ - Name: "args", - Description: "", - Type: cty.DynamicPseudoType, - }, - ReturnTypes: cty.DynamicPseudoType, - Description: "`formatlist` produces a list of strings by formatting a number of other values according to a specification string.", - }, - "indent": { - Params: []function.Parameter{ - { - Name: "spaces", - Description: "Number of spaces to add after each newline character.", - Type: cty.Number, - }, - { - Name: "str", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`indent` adds a given number of spaces to the beginnings of all but the first line in a given multi-line string.", - }, - "join": { - Params: []function.Parameter{ - { - Name: "separator", - Description: "Delimiter to insert between the given strings.", - Type: cty.String, - }, - }, - VarParam: &function.Parameter{ - Name: "lists", - Description: "One or more lists of strings to join.", - Type: cty.List(cty.String), - }, - ReturnTypes: cty.String, - Description: "`join` produces a string by concatenating together all elements of a given list of strings with the given delimiter.", - }, - "jsondecode": { - Params: []function.Parameter{ - { - Name: "str", - Type: cty.String, - }, - }, - ReturnTypes: cty.DynamicPseudoType, - Description: "`jsondecode` interprets a given string as JSON, returning a representation of the result of decoding that string.", - }, - "jsonencode": { - Params: []function.Parameter{ - { - Name: "val", - Type: cty.DynamicPseudoType, - }, - }, - ReturnTypes: cty.String, - Description: "`jsonencode` encodes a given value to a string using JSON syntax.", - }, - "keys": { - Params: []function.Parameter{ - { - Name: "inputMap", - Description: "The map to extract keys from. May instead be an object-typed value, in which case the result is a tuple of the object attributes.", - Type: cty.DynamicPseudoType, - }, - }, - ReturnTypes: cty.DynamicPseudoType, - Description: "`keys` takes a map and returns a list containing the keys from that map.", - }, - "log": { - Params: []function.Parameter{ - { - Name: "num", - Type: cty.Number, - }, - { - Name: "base", - Type: cty.Number, - }, - }, - ReturnTypes: cty.Number, - Description: "`log` returns the logarithm of a given number in a given base.", - }, - "lower": { - Params: []function.Parameter{ - { - Name: "str", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`lower` converts all cased letters in the given string to lowercase.", - }, - "max": { - VarParam: &function.Parameter{ - Name: "numbers", - Description: "", - Type: cty.Number, - }, - ReturnTypes: cty.Number, - Description: "`max` takes one or more numbers and returns the greatest number from the set.", - }, - "merge": { - VarParam: &function.Parameter{ - Name: "maps", - Description: "", - Type: cty.DynamicPseudoType, - }, - ReturnTypes: cty.DynamicPseudoType, - Description: "`merge` takes an arbitrary number of maps or objects, and returns a single map or object that contains a merged set of elements from all arguments.", - }, - "min": { - VarParam: &function.Parameter{ - Name: "numbers", - Description: "", - Type: cty.Number, - }, - ReturnTypes: cty.Number, - Description: "`min` takes one or more numbers and returns the smallest number from the set.", - }, - "pow": { - Params: []function.Parameter{ - { - Name: "num", - Type: cty.Number, - }, - { - Name: "power", - Type: cty.Number, - }, - }, - ReturnTypes: cty.Number, - Description: "`pow` calculates an exponent, by raising its first argument to the power of the second argument.", - }, - "reverse": { - Params: []function.Parameter{ - { - Name: "list", - Type: cty.DynamicPseudoType, - }, - }, - ReturnTypes: cty.DynamicPseudoType, - Description: "`reverse` takes a sequence and produces a new sequence of the same length with all of the same elements as the given sequence but in reverse order.", - }, - "setintersection": { - Params: []function.Parameter{ - { - Name: "first_set", - Type: cty.Set(cty.DynamicPseudoType), - }, - }, - VarParam: &function.Parameter{ - Name: "other_sets", - Description: "", - Type: cty.Set(cty.DynamicPseudoType), - }, - ReturnTypes: cty.Set(cty.DynamicPseudoType), - Description: "The `setintersection` function takes multiple sets and produces a single set containing only the elements that all of the given sets have in common. In other words, it computes the [intersection](https://en.wikipedia.org/wiki/Intersection_\\(set_theory\\)) of the sets.", - }, - "setproduct": { - VarParam: &function.Parameter{ - Name: "sets", - Description: "The sets to consider. Also accepts lists and tuples, and if all arguments are of list or tuple type then the result will preserve the input ordering", - Type: cty.DynamicPseudoType, - }, - ReturnTypes: cty.DynamicPseudoType, - Description: "The `setproduct` function finds all of the possible combinations of elements from all of the given sets by computing the [Cartesian product](https://en.wikipedia.org/wiki/Cartesian_product).", - }, - "setunion": { - Params: []function.Parameter{ - { - Name: "first_set", - Type: cty.Set(cty.DynamicPseudoType), - }, - }, - VarParam: &function.Parameter{ - Name: "other_sets", - Description: "", - Type: cty.Set(cty.DynamicPseudoType), - }, - ReturnTypes: cty.Set(cty.DynamicPseudoType), - Description: "The `setunion` function takes multiple sets and produces a single set containing the elements from all of the given sets. In other words, it computes the [union](https://en.wikipedia.org/wiki/Union_\\(set_theory\\)) of the sets.", - }, - "signum": { - Params: []function.Parameter{ - { - Name: "num", - Type: cty.Number, - }, - }, - ReturnTypes: cty.Number, - Description: "`signum` determines the sign of a number, returning a number between -1 and 1 to represent the sign.", - }, - "slice": { - Params: []function.Parameter{ - { - Name: "list", - Type: cty.DynamicPseudoType, - }, - { - Name: "start_index", - Type: cty.Number, - }, - { - Name: "end_index", - Type: cty.Number, - }, - }, - ReturnTypes: cty.DynamicPseudoType, - Description: "`slice` extracts some consecutive elements from within a list.", - }, - "sort": { - Params: []function.Parameter{ - { - Name: "list", - Type: cty.List(cty.String), - }, - }, - ReturnTypes: cty.List(cty.String), - Description: "`sort` takes a list of strings and returns a new list with those strings sorted lexicographically.", - }, - "split": { - Params: []function.Parameter{ - { - Name: "separator", - Type: cty.String, - }, - { - Name: "str", - Type: cty.String, - }, - }, - ReturnTypes: cty.List(cty.String), - Description: "`split` produces a list by dividing a given string at all occurrences of a given separator.", - }, - "strrev": { - Params: []function.Parameter{ - { - Name: "str", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`strrev` reverses the characters in a string. Note that the characters are treated as _Unicode characters_ (in technical terms, Unicode [grapheme cluster boundaries](https://unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries) are respected).", - }, - "substr": { - Params: []function.Parameter{ - { - Name: "str", - Type: cty.String, - }, - { - Name: "offset", - Type: cty.Number, - }, - { - Name: "length", - Type: cty.Number, - }, - }, - ReturnTypes: cty.String, - Description: "`substr` extracts a substring from a given string by offset and (maximum) length.", - }, - "timeadd": { - Params: []function.Parameter{ - { - Name: "timestamp", - Type: cty.String, - }, - { - Name: "duration", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`timeadd` adds a duration to a timestamp, returning a new timestamp.", - }, - "title": { - Params: []function.Parameter{ - { - Name: "str", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`title` converts the first letter of each word in the given string to uppercase.", - }, - "upper": { - Params: []function.Parameter{ - { - Name: "str", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`upper` converts all cased letters in the given string to uppercase.", - }, - "values": { - Params: []function.Parameter{ - { - Name: "mapping", - Type: cty.DynamicPseudoType, - }, - }, - ReturnTypes: cty.DynamicPseudoType, - Description: "`values` takes a map and returns a list containing the values of the elements in that map.", - }, - "zipmap": { - Params: []function.Parameter{ - { - Name: "keys", - Type: cty.List(cty.String), - }, - { - Name: "values", - Type: cty.DynamicPseudoType, - }, - }, - ReturnTypes: cty.DynamicPseudoType, - Description: "`zipmap` constructs a map from a list of keys and a corresponding list of values.", - }, - } -} diff --git a/internal/funcs/0.12/base_terraform.go b/internal/funcs/0.12/base_terraform.go deleted file mode 100644 index 20b8f29f..00000000 --- a/internal/funcs/0.12/base_terraform.go +++ /dev/null @@ -1,491 +0,0 @@ -package funcs - -import ( - "github.com/hashicorp/hcl-lang/schema" - "github.com/zclconf/go-cty/cty" - "github.com/zclconf/go-cty/cty/function" -) - -func BaseTerraformFunctions() map[string]schema.FuncSignature { - return map[string]schema.FuncSignature{ - "base64decode": { - Params: []function.Parameter{ - { - Name: "str", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`base64decode` takes a string containing a Base64 character sequence and returns the original string.", - }, - "base64encode": { - Params: []function.Parameter{ - { - Name: "str", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`base64encode` applies Base64 encoding to a string.", - }, - "base64gzip": { - Params: []function.Parameter{ - { - Name: "str", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`base64gzip` compresses a string with gzip and then encodes the result in Base64 encoding.", - }, - "base64sha256": { - Params: []function.Parameter{ - { - Name: "str", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`base64sha256` computes the SHA256 hash of a given string and encodes it with Base64. This is not equivalent to `base64encode(sha256("test"))` since `sha256()` returns hexadecimal representation.", - }, - "base64sha512": { - Params: []function.Parameter{ - { - Name: "str", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`base64sha512` computes the SHA512 hash of a given string and encodes it with Base64. This is not equivalent to `base64encode(sha512("test"))` since `sha512()` returns hexadecimal representation.", - }, - "basename": { - Params: []function.Parameter{ - { - Name: "path", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`basename` takes a string containing a filesystem path and removes all except the last portion from it.", - }, - "bcrypt": { - Params: []function.Parameter{ - { - Name: "str", - Type: cty.String, - }, - }, - VarParam: &function.Parameter{ - Name: "cost", - Description: "The `cost` argument is optional and will default to 10 if unspecified.", - Type: cty.Number, - }, - ReturnTypes: cty.String, - Description: "`bcrypt` computes a hash of the given string using the Blowfish cipher, returning a string in [the _Modular Crypt Format_](https://passlib.readthedocs.io/en/stable/modular_crypt_format.html) usually expected in the shadow password file on many Unix systems.", - }, - "cidrhost": { - Params: []function.Parameter{ - { - Name: "prefix", - Description: "`prefix` must be given in CIDR notation, as defined in [RFC 4632 section 3.1](https://tools.ietf.org/html/rfc4632#section-3.1).", - Type: cty.String, - }, - { - Name: "hostnum", - Description: "`hostnum` is a whole number that can be represented as a binary integer with no more than the number of digits remaining in the address after the given prefix.", - Type: cty.Number, - }, - }, - ReturnTypes: cty.String, - Description: "`cidrhost` calculates a full host IP address for a given host number within a given IP network address prefix.", - }, - "cidrnetmask": { - Params: []function.Parameter{ - { - Name: "prefix", - Description: "`prefix` must be given in CIDR notation, as defined in [RFC 4632 section 3.1](https://tools.ietf.org/html/rfc4632#section-3.1).", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`cidrnetmask` converts an IPv4 address prefix given in CIDR notation into a subnet mask address.", - }, - "cidrsubnet": { - Params: []function.Parameter{ - { - Name: "prefix", - Description: "`prefix` must be given in CIDR notation, as defined in [RFC 4632 section 3.1](https://tools.ietf.org/html/rfc4632#section-3.1).", - Type: cty.String, - }, - { - Name: "newbits", - Description: "`newbits` is the number of additional bits with which to extend the prefix.", - Type: cty.Number, - }, - { - Name: "netnum", - Description: "`netnum` is a whole number that can be represented as a binary integer with no more than `newbits` binary digits, which will be used to populate the additional bits added to the prefix.", - Type: cty.Number, - }, - }, - ReturnTypes: cty.String, - Description: "`cidrsubnet` calculates a subnet address within given IP network address prefix.", - }, - "coalesce": { - VarParam: &function.Parameter{ - Name: "vals", - Description: "", - Type: cty.DynamicPseudoType, - }, - ReturnTypes: cty.DynamicPseudoType, - Description: "`coalesce` takes any number of arguments and returns the first one that isn't null or an empty string.", - }, - "dirname": { - Params: []function.Parameter{ - { - Name: "path", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`dirname` takes a string containing a filesystem path and removes the last portion from it.", - }, - "file": { - Params: []function.Parameter{ - { - Name: "path", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`file` reads the contents of a file at the given path and returns them as a string.", - }, - "filebase64": { - Params: []function.Parameter{ - { - Name: "path", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`filebase64` reads the contents of a file at the given path and returns them as a base64-encoded string.", - }, - "filebase64sha256": { - Params: []function.Parameter{ - { - Name: "path", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`filebase64sha256` is a variant of `base64sha256` that hashes the contents of a given file rather than a literal string.", - }, - "filebase64sha512": { - Params: []function.Parameter{ - { - Name: "path", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`filebase64sha512` is a variant of `base64sha512` that hashes the contents of a given file rather than a literal string.", - }, - "fileexists": { - Params: []function.Parameter{ - { - Name: "path", - Type: cty.String, - }, - }, - ReturnTypes: cty.Bool, - Description: "`fileexists` determines whether a file exists at a given path.", - }, - "filemd5": { - Params: []function.Parameter{ - { - Name: "path", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`filemd5` is a variant of `md5` that hashes the contents of a given file rather than a literal string.", - }, - "filesha1": { - Params: []function.Parameter{ - { - Name: "path", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`filesha1` is a variant of `sha1` that hashes the contents of a given file rather than a literal string.", - }, - "filesha256": { - Params: []function.Parameter{ - { - Name: "path", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`filesha256` is a variant of `sha256` that hashes the contents of a given file rather than a literal string.", - }, - "filesha512": { - Params: []function.Parameter{ - { - Name: "path", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`filesha512` is a variant of `sha512` that hashes the contents of a given file rather than a literal string.", - }, - "index": { - Params: []function.Parameter{ - { - Name: "list", - Type: cty.DynamicPseudoType, - }, - { - Name: "value", - Type: cty.DynamicPseudoType, - }, - }, - ReturnTypes: cty.DynamicPseudoType, - Description: "`index` finds the element index for a given value in a list.", - }, - "length": { - Params: []function.Parameter{ - { - Name: "value", - Type: cty.DynamicPseudoType, - }, - }, - ReturnTypes: cty.Number, - Description: "`length` determines the length of a given list, map, or string.", - }, - // TODO! "list": {}, - "lookup": { - Params: []function.Parameter{ - { - Name: "inputMap", - Type: cty.DynamicPseudoType, - }, - { - Name: "key", - Type: cty.String, - }, - }, - VarParam: &function.Parameter{ - Name: "default", - Description: "", - Type: cty.DynamicPseudoType, - }, - ReturnTypes: cty.DynamicPseudoType, - Description: "`lookup` retrieves the value of a single element from a map, given its key. If the given key does not exist, the given default value is returned instead.", - }, - // TODO! "map": {} - "matchkeys": { - Params: []function.Parameter{ - { - Name: "values", - Type: cty.List(cty.DynamicPseudoType), - }, - { - Name: "keys", - Type: cty.List(cty.DynamicPseudoType), - }, - { - Name: "searchset", - Type: cty.List(cty.DynamicPseudoType), - }, - }, - ReturnTypes: cty.List(cty.DynamicPseudoType), - Description: "`matchkeys` constructs a new list by taking a subset of elements from one list whose indexes match the corresponding indexes of values in another list.", - }, - "md5": { - Params: []function.Parameter{ - { - Name: "str", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`md5` computes the MD5 hash of a given string and encodes it with hexadecimal digits.", - }, - "pathexpand": { - Params: []function.Parameter{ - { - Name: "path", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`pathexpand` takes a filesystem path that might begin with a `~` segment, and if so it replaces that segment with the current user's home directory path.", - }, - "replace": { - Params: []function.Parameter{ - { - Name: "str", - Type: cty.String, - }, - { - Name: "substr", - Type: cty.String, - }, - { - Name: "replace", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`replace` searches a given string for another given substring, and replaces each occurrence with a given replacement string.", - }, - "rsadecrypt": { - Params: []function.Parameter{ - { - Name: "ciphertext", - Type: cty.String, - }, - { - Name: "privatekey", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`rsadecrypt` decrypts an RSA-encrypted ciphertext, returning the corresponding cleartext.", - }, - "sha1": { - Params: []function.Parameter{ - { - Name: "str", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`sha1` computes the SHA1 hash of a given string and encodes it with hexadecimal digits.", - }, - "sha256": { - Params: []function.Parameter{ - { - Name: "str", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`sha256` computes the SHA256 hash of a given string and encodes it with hexadecimal digits.", - }, - "sha512": { - Params: []function.Parameter{ - { - Name: "str", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`sha512` computes the SHA512 hash of a given string and encodes it with hexadecimal digits.", - }, - "templatefile": { - Params: []function.Parameter{ - { - Name: "path", - Type: cty.String, - }, - { - Name: "vars", - Type: cty.DynamicPseudoType, - }, - }, - ReturnTypes: cty.DynamicPseudoType, - Description: "`templatefile` reads the file at the given path and renders its content as a template using a supplied set of template variables.", - }, - "timestamp": { - ReturnTypes: cty.String, - Description: "`timestamp` returns a UTC timestamp string in [RFC 3339](https://tools.ietf.org/html/rfc3339) format.", - }, - "tobool": { - Params: []function.Parameter{ - { - Name: "v", - Type: cty.DynamicPseudoType, - }, - }, - ReturnTypes: cty.Bool, - Description: "`tobool` converts its argument to a boolean value.", - }, - "tolist": { - Params: []function.Parameter{ - { - Name: "v", - Type: cty.DynamicPseudoType, - }, - }, - ReturnTypes: cty.List(cty.DynamicPseudoType), - Description: "`tolist` converts its argument to a list value.", - }, - "tomap": { - Params: []function.Parameter{ - { - Name: "v", - Type: cty.DynamicPseudoType, - }, - }, - ReturnTypes: cty.Map(cty.DynamicPseudoType), - Description: "`tomap` converts its argument to a map value.", - }, - "tonumber": { - Params: []function.Parameter{ - { - Name: "v", - Type: cty.DynamicPseudoType, - }, - }, - ReturnTypes: cty.Number, - Description: "`tonumber` converts its argument to a number value.", - }, - "toset": { - Params: []function.Parameter{ - { - Name: "v", - Type: cty.DynamicPseudoType, - }, - }, - ReturnTypes: cty.Set(cty.DynamicPseudoType), - Description: "`toset` converts its argument to a set value.", - }, - "tostring": { - Params: []function.Parameter{ - { - Name: "v", - Type: cty.DynamicPseudoType, - }, - }, - ReturnTypes: cty.String, - Description: "`tostring` converts its argument to a string value.", - }, - "transpose": { - Params: []function.Parameter{ - { - Name: "values", - Type: cty.Map(cty.List(cty.String)), - }, - }, - ReturnTypes: cty.Map(cty.List(cty.String)), - Description: "`transpose` takes a map of lists of strings and swaps the keys and values to produce a new map of lists of strings.", - }, - "urlencode": { - Params: []function.Parameter{ - { - Name: "str", - Type: cty.String, - }, - }, - ReturnTypes: cty.String, - Description: "`urlencode` applies URL encoding to a given string.", - }, - "uuid": { - ReturnTypes: cty.String, - Description: "`uuid` generates a unique identifier string.", - }, - } -} diff --git a/internal/funcs/0.12/funcgen/gen.go b/internal/funcs/0.12/funcgen/gen.go deleted file mode 100644 index 32bde7f2..00000000 --- a/internal/funcs/0.12/funcgen/gen.go +++ /dev/null @@ -1,163 +0,0 @@ -package main - -import ( - "flag" - "log" - "os" - "strings" - "text/template" - - "github.com/hashicorp/terraform-schema/internal/funcs" - "github.com/zclconf/go-cty/cty" - "github.com/zclconf/go-cty/cty/function" - "github.com/zclconf/go-cty/cty/function/stdlib" -) - -var functions = map[string]function.Function{ - "abs": stdlib.AbsoluteFunc, - "ceil": stdlib.CeilFunc, - "chomp": stdlib.ChompFunc, - "chunklist": stdlib.ChunklistFunc, - "coalescelist": stdlib.CoalesceListFunc, - "compact": stdlib.CompactFunc, - "concat": stdlib.ConcatFunc, - "contains": stdlib.ContainsFunc, - "csvdecode": stdlib.CSVDecodeFunc, - "distinct": stdlib.DistinctFunc, - "element": stdlib.ElementFunc, - "flatten": stdlib.FlattenFunc, - "floor": stdlib.FloorFunc, - "format": stdlib.FormatFunc, - "formatdate": stdlib.FormatDateFunc, - "formatlist": stdlib.FormatListFunc, - "indent": stdlib.IndentFunc, - "join": stdlib.JoinFunc, - "jsondecode": stdlib.JSONDecodeFunc, - "jsonencode": stdlib.JSONEncodeFunc, - "keys": stdlib.KeysFunc, - "log": stdlib.LogFunc, - "lower": stdlib.LowerFunc, - "max": stdlib.MaxFunc, - "merge": stdlib.MergeFunc, - "min": stdlib.MinFunc, - "pow": stdlib.PowFunc, - "reverse": stdlib.ReverseListFunc, - "setintersection": stdlib.SetIntersectionFunc, - "setproduct": stdlib.SetProductFunc, - "setunion": stdlib.SetUnionFunc, - "signum": stdlib.SignumFunc, - "slice": stdlib.SliceFunc, - "sort": stdlib.SortFunc, - "split": stdlib.SplitFunc, - "strrev": stdlib.ReverseFunc, - "substr": stdlib.SubstrFunc, - "timeadd": stdlib.TimeAddFunc, - "title": stdlib.TitleFunc, - "upper": stdlib.UpperFunc, - "values": stdlib.ValuesFunc, - "zipmap": stdlib.ZipmapFunc, -} - -func main() { - var writePath string - flag.StringVar(&writePath, "w", "", "Path to write to") - flag.Parse() - - output := os.Stdout - if writePath != "" { - f, err := os.OpenFile(writePath, os.O_RDWR|os.O_CREATE, 0o755) - if err != nil { - log.Fatal(err) - } - output = f - } - - outputTpl := `// Code generated by "funcgen"; DO NOT EDIT. -package funcs - -import ( - "github.com/hashicorp/hcl-lang/schema" - "github.com/zclconf/go-cty/cty" - "github.com/zclconf/go-cty/cty/function" -) - -func BaseStdlibFunctions() map[string]schema.FuncSignature { - return map[string]schema.FuncSignature{ -{{- range $funcName, $func := .Functions }} - {{- $varpar := $func.VarParam }} - {{- $params := $func.Params }} - "{{ $funcName }}": { - {{- with $params }} - Params: []function.Parameter{ - {{- range $key, $value := $params }} - {{- $desc := getParamDescription $funcName $key }} - { - Name: "{{ $value.Name }}", - {{- with $desc }} - Description: "{{ . }}",{{- end }} - Type: {{ $value.Type.GoString }}, - }, - {{- end }} - },{{- end }} - {{- with $varpar }} - VarParam: &function.Parameter{ - Name: "{{ .Name }}", - Description: "{{ .Description }}", - Type: {{ .Type.GoString }}, - },{{- end }} - ReturnTypes: {{ getReturnType $func }}, - Description: "{{ getDescription $funcName }}", - }, -{{- end }} - } -} -` - tpl, err := template.New("output").Funcs(template.FuncMap{ - "getReturnType": getReturnType, - "getDescription": getDescription, - "getParamDescription": getParamDescription, - "getVarParam": getVarParam, - }).Parse(outputTpl) - if err != nil { - log.Fatal(err) - } - - type data struct { - Functions map[string]function.Function - } - - err = tpl.Execute(output, data{ - Functions: functions, - }) - if err != nil { - log.Fatal(err) - } -} - -func getReturnType(f function.Function) (string, error) { - args := make([]cty.Type, 0) - for _, param := range f.Params() { - args = append(args, param.Type) - } - if f.VarParam() != nil { - args = append(args, f.VarParam().Type) - } - - returnType, err := f.ReturnType(args) - if err != nil { - return "", err - } - return returnType.GoString(), nil -} - -func getDescription(name string) string { - return strings.ReplaceAll(funcs.DescriptionList[name].Description, `\`, `\\`) -} - -func getParamDescription(name string, index int) string { - return strings.ReplaceAll(funcs.DescriptionList[name].ParamDescription[index], `\`, `\\`) -} - -func getVarParam(f function.Function) *function.Parameter { - return f.VarParam() -} diff --git a/internal/funcs/0.12/functions.go b/internal/funcs/0.12/functions.go index 733fb43c..bd4c3753 100644 --- a/internal/funcs/0.12/functions.go +++ b/internal/funcs/0.12/functions.go @@ -4,8 +4,7 @@ import ( "github.com/hashicorp/go-version" "github.com/hashicorp/hcl-lang/schema" "github.com/zclconf/go-cty/cty" - "github.com/zclconf/go-cty/cty/function/stdlib" - "golang.org/x/exp/maps" + "github.com/zclconf/go-cty/cty/function" ) var ( @@ -19,85 +18,215 @@ var ( v0_12_21 = version.Must(version.NewVersion("0.12.21")) ) -//go:generate go run ./funcgen -w ./base_stdlib_gen.go func Functions(v *version.Version) map[string]schema.FuncSignature { - f := BaseStdlibFunctions() - maps.Copy(f, BaseTerraformFunctions()) + f := BaseFunctions() if v.GreaterThanOrEqual(v0_12_2) { f["range"] = schema.FuncSignature{ - Params: stdlib.RangeFunc.Params(), - VarParam: stdlib.RangeFunc.VarParam(), + VarParam: &function.Parameter{ + Name: "params", + Type: cty.Number, + }, + ReturnTypes: cty.List(cty.Number), + Description: "`range` generates a list of numbers using a start value, a limit value, and a step value.", + } + f["uuidv5"] = schema.FuncSignature{ + Params: []function.Parameter{ + { + Name: "namespace", + Type: cty.String, + }, + { + Name: "name", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`uuidv5` generates a _name-based_ UUID, as described in [RFC 4122 section 4.3](https://tools.ietf.org/html/rfc4122#section-4.3), also known as a "version 5" UUID.", + } + f["yamldecode"] = schema.FuncSignature{ + Params: []function.Parameter{ + { + Name: "src", + Type: cty.String, + }, + }, ReturnTypes: cty.DynamicPseudoType, - Description: stdlib.RangeFunc.Description(), + Description: "`yamldecode` parses a string as a subset of YAML, and produces a representation of its value.", + } + f["yamlencode"] = schema.FuncSignature{ + Params: []function.Parameter{ + { + Name: "value", + Type: cty.DynamicPseudoType, + }, + }, + ReturnTypes: cty.String, + Description: "`yamlencode` encodes a given value to a string using [YAML 1.2](https://yaml.org/spec/1.2/spec.html) block syntax.", } - f["yamldecode"] = schema.FuncSignature{} // TODO! - f["yamlencode"] = schema.FuncSignature{} // TODO! } if v.GreaterThanOrEqual(v0_12_4) { - f["abspath"] = schema.FuncSignature{} // TODO! + f["abspath"] = schema.FuncSignature{ + Params: []function.Parameter{ + { + Name: "path", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`abspath` takes a string containing a filesystem path and converts it to an absolute path. That is, if the path is not absolute, it will be joined with the current working directory.", + } } if v.GreaterThanOrEqual(v0_12_7) { f["regex"] = schema.FuncSignature{ - Params: stdlib.RegexFunc.Params(), - VarParam: stdlib.RegexFunc.VarParam(), + Params: []function.Parameter{ + { + Name: "pattern", + Type: cty.String, + }, + { + Name: "string", + Type: cty.String, + }, + }, ReturnTypes: cty.DynamicPseudoType, - Description: stdlib.RegexFunc.Description(), + Description: "`regex` applies a [regular expression](https://en.wikipedia.org/wiki/Regular_expression) to a string and returns the matching substrings.", } f["regexall"] = schema.FuncSignature{ - Params: stdlib.RegexAllFunc.Params(), - VarParam: stdlib.RegexAllFunc.VarParam(), - ReturnTypes: cty.DynamicPseudoType, - Description: stdlib.RegexAllFunc.Description(), + Params: []function.Parameter{ + { + Name: "pattern", + Type: cty.String, + }, + { + Name: "string", + Type: cty.String, + }, + }, + ReturnTypes: cty.List(cty.DynamicPseudoType), + Description: "`regexall` applies a [regular expression](https://en.wikipedia.org/wiki/Regular_expression) to a string and returns a list of all matches.", } } if v.GreaterThanOrEqual(v0_12_8) { - f["fileset"] = schema.FuncSignature{} // TODO! + f["fileset"] = schema.FuncSignature{ + Params: []function.Parameter{ + { + Name: "path", + Type: cty.String, + }, + { + Name: "pattern", + Type: cty.String, + }, + }, + ReturnTypes: cty.Set(cty.String), + Description: "`fileset` enumerates a set of regular file names given a path and pattern. The path is automatically removed from the resulting set of file names and any result still containing path separators always returns forward slash (`/`) as the path separator for cross-system compatibility.", + } } if v.GreaterThanOrEqual(v0_12_10) { f["parseint"] = schema.FuncSignature{ - Params: stdlib.ParseIntFunc.Params(), - VarParam: stdlib.ParseIntFunc.VarParam(), + Params: []function.Parameter{ + { + Name: "number", + Type: cty.DynamicPseudoType, + }, + { + Name: "base", + Type: cty.Number, + }, + }, ReturnTypes: cty.DynamicPseudoType, - Description: stdlib.ParseIntFunc.Description(), + Description: "`parseint` parses the given string as a representation of an integer in the specified base and returns the resulting number. The base must be between 2 and 62 inclusive.", + } + f["cidrsubnets"] = schema.FuncSignature{ + Params: []function.Parameter{ + { + Name: "prefix", + Description: "`prefix` must be given in CIDR notation, as defined in [RFC 4632 section 3.1](https://tools.ietf.org/html/rfc4632#section-3.1).", + Type: cty.String, + }, + }, + VarParam: &function.Parameter{ + Name: "newbits", + Type: cty.Number, + }, + ReturnTypes: cty.List(cty.String), + Description: "`cidrsubnets` calculates a sequence of consecutive IP address ranges within a particular CIDR prefix.", } } if v.GreaterThanOrEqual(v0_12_17) { f["trim"] = schema.FuncSignature{ - Params: stdlib.TrimFunc.Params(), - VarParam: stdlib.TrimFunc.VarParam(), - ReturnTypes: cty.DynamicPseudoType, - Description: stdlib.TrimFunc.Description(), + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + { + Name: "cutset", + Description: "A string containing all of the characters to trim. Each character is taken separately, so the order of characters is insignificant.", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`trim` removes the specified set of characters from the start and end of the given string.", } f["trimprefix"] = schema.FuncSignature{ - Params: stdlib.TrimPrefixFunc.Params(), - VarParam: stdlib.TrimPrefixFunc.VarParam(), - ReturnTypes: cty.DynamicPseudoType, - Description: stdlib.TrimPrefixFunc.Description(), + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + { + Name: "prefix", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`trimprefix` removes the specified prefix from the start of the given string. If the string does not start with the prefix, the string is returned unchanged.", } f["trimspace"] = schema.FuncSignature{ - Params: stdlib.TrimSpaceFunc.Params(), - VarParam: stdlib.TrimSpaceFunc.VarParam(), - ReturnTypes: cty.DynamicPseudoType, - Description: stdlib.TrimSpaceFunc.Description(), + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`trimspace` removes any space characters from the start and end of the given string.", } f["trimsuffix"] = schema.FuncSignature{ - Params: stdlib.TrimSuffixFunc.Params(), - VarParam: stdlib.TrimSuffixFunc.VarParam(), - ReturnTypes: cty.DynamicPseudoType, - Description: stdlib.TrimSuffixFunc.Description(), + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + { + Name: "suffix", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`trimsuffix` removes the specified suffix from the end of the given string.", } } if v.GreaterThanOrEqual(v0_12_20) { - f["can"] = schema.FuncSignature{} // TODO! - f["try"] = schema.FuncSignature{} // TODO! + // f["can"] = schema.FuncSignature{} // TODO! + // f["try"] = schema.FuncSignature{} // TODO! } if v.GreaterThanOrEqual(v0_12_21) { f["setsubtract"] = schema.FuncSignature{ - Params: stdlib.SetSubtractFunc.Params(), - VarParam: stdlib.SetSubtractFunc.VarParam(), - ReturnTypes: cty.DynamicPseudoType, - Description: stdlib.SetSubtractFunc.Description(), + Params: []function.Parameter{ + { + Name: "a", + Type: cty.Set(cty.DynamicPseudoType), + }, + { + Name: "b", + Type: cty.Set(cty.DynamicPseudoType), + }, + }, + ReturnTypes: cty.Set(cty.DynamicPseudoType), + Description: "The `setsubtract` function returns a new set containing the elements from the first set that are not present in the second set. In other words, it computes the [relative complement](https://en.wikipedia.org/wiki/Complement_\\(set_theory\\)#Relative_complement) of the second set.", } } diff --git a/internal/funcs/0.13/functions.go b/internal/funcs/0.13/functions.go index 0ffe89e4..3aa0e15d 100644 --- a/internal/funcs/0.13/functions.go +++ b/internal/funcs/0.13/functions.go @@ -3,6 +3,8 @@ package funcs import ( "github.com/hashicorp/go-version" "github.com/hashicorp/hcl-lang/schema" + "github.com/zclconf/go-cty/cty" + "github.com/zclconf/go-cty/cty/function" funcs_v0_12 "github.com/hashicorp/terraform-schema/internal/funcs/0.12" ) @@ -10,7 +12,16 @@ import ( func Functions(v *version.Version) map[string]schema.FuncSignature { f := funcs_v0_12.Functions(v) - f["sum"] = schema.FuncSignature{} // TODO! + f["sum"] = schema.FuncSignature{ + Params: []function.Parameter{ + { + Name: "list", + Type: cty.DynamicPseudoType, + }, + }, + ReturnTypes: cty.DynamicPseudoType, + Description: "`sum` takes a list or set of numbers and returns the sum of those numbers.", + } return f } diff --git a/internal/funcs/0.14/functions.go b/internal/funcs/0.14/functions.go index e5e186c5..06b0a2b9 100644 --- a/internal/funcs/0.14/functions.go +++ b/internal/funcs/0.14/functions.go @@ -3,6 +3,8 @@ package funcs import ( "github.com/hashicorp/go-version" "github.com/hashicorp/hcl-lang/schema" + "github.com/zclconf/go-cty/cty" + "github.com/zclconf/go-cty/cty/function" funcs_v0_13 "github.com/hashicorp/terraform-schema/internal/funcs/0.13" ) @@ -10,10 +12,54 @@ import ( func Functions(v *version.Version) map[string]schema.FuncSignature { f := funcs_v0_13.Functions(v) - f["alltrue"] = schema.FuncSignature{} // TODO! - f["anytrue"] = schema.FuncSignature{} // TODO! - f["textdecodebase64"] = schema.FuncSignature{} // TODO! - f["textencodebase64"] = schema.FuncSignature{} // TODO! + f["alltrue"] = schema.FuncSignature{ + Params: []function.Parameter{ + { + Name: "list", + Type: cty.List(cty.Bool), + }, + }, + ReturnTypes: cty.Bool, + Description: "`alltrue` returns `true` if all elements in a given collection are `true` or `"true"`. It also returns `true` if the collection is empty.", + } + f["anytrue"] = schema.FuncSignature{ + Params: []function.Parameter{ + { + Name: "list", + Type: cty.List(cty.Bool), + }, + }, + ReturnTypes: cty.Bool, + Description: "`anytrue` returns `true` if any element in a given collection is `true` or `"true"`. It also returns `false` if the collection is empty.", + } + f["textdecodebase64"] = schema.FuncSignature{ + Params: []function.Parameter{ + { + Name: "source", + Type: cty.String, + }, + { + Name: "encoding", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`textdecodebase64` function decodes a string that was previously Base64-encoded, and then interprets the result as characters in a specified character encoding.", + } + f["textencodebase64"] = schema.FuncSignature{ + Params: []function.Parameter{ + { + Name: "string", + Type: cty.String, + }, + { + Name: "encoding", + Type: cty.String, + }, + }, + ReturnTypes: cty.String, + Description: "`textencodebase64` encodes the unicode characters in a given string using a specified character encoding, returning the result base64 encoded because Terraform language strings are always sequences of unicode characters.", + } return f } diff --git a/internal/funcs/0.15/functions.go b/internal/funcs/0.15/functions.go index 1f2172fe..f3f2f155 100644 --- a/internal/funcs/0.15/functions.go +++ b/internal/funcs/0.15/functions.go @@ -3,6 +3,8 @@ package funcs import ( "github.com/hashicorp/go-version" "github.com/hashicorp/hcl-lang/schema" + "github.com/zclconf/go-cty/cty" + "github.com/zclconf/go-cty/cty/function" funcs_v0_14 "github.com/hashicorp/terraform-schema/internal/funcs/0.14" ) @@ -10,12 +12,39 @@ import ( func Functions(v *version.Version) map[string]schema.FuncSignature { f := funcs_v0_14.Functions(v) - f["nonsensitive"] = schema.FuncSignature{} // TODO! - f["one"] = schema.FuncSignature{} // TODO! - f["sensitive"] = schema.FuncSignature{} // TODO! + f["nonsensitive"] = schema.FuncSignature{ + Params: []function.Parameter{ + { + Name: "value", + Type: cty.DynamicPseudoType, + }, + }, + ReturnTypes: cty.DynamicPseudoType, + Description: "`nonsensitive` takes a sensitive value and returns a copy of that value with the sensitive marking removed, thereby exposing the sensitive value.", + } + f["one"] = schema.FuncSignature{ + Params: []function.Parameter{ + { + Name: "list", + Type: cty.DynamicPseudoType, + }, + }, + ReturnTypes: cty.DynamicPseudoType, + Description: "`one` takes a list, set, or tuple value with either zero or one elements. If the collection is empty, `one` returns `null`. Otherwise, `one` returns the first element. If there are two or more elements then `one` will return an error.", + } + f["sensitive"] = schema.FuncSignature{ + Params: []function.Parameter{ + { + Name: "value", + Type: cty.DynamicPseudoType, + }, + }, + ReturnTypes: cty.DynamicPseudoType, + Description: "`sensitive` takes any value and returns a copy of it marked so that Terraform will treat it as sensitive, with the same meaning and behavior as for [sensitive input variables](/language/values/variables#suppressing-values-in-cli-output).", + } - // TODO! remove list - // TODO! remove map + delete(f, "list") // list was removed in 0.15 + delete(f, "map") // map was removed in 0.15 return f } diff --git a/internal/funcs/1.3/functions.go b/internal/funcs/1.3/functions.go index 1e6b9caa..b041eafe 100644 --- a/internal/funcs/1.3/functions.go +++ b/internal/funcs/1.3/functions.go @@ -12,23 +12,47 @@ import ( func Functions(v *version.Version) map[string]schema.FuncSignature { f := funcs_v0_15.Functions(v) - f["endswith"] = schema.FuncSignature{} // TODO! - f["startswith"] = schema.FuncSignature{} // TODO! + f["endswith"] = schema.FuncSignature{ + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + { + Name: "suffix", + Type: cty.String, + }, + }, + ReturnTypes: cty.Bool, + Description: "`endswith` takes two values: a string to check and a suffix string. The function returns true if the first string ends with that exact suffix.", + } + f["startswith"] = schema.FuncSignature{ + Params: []function.Parameter{ + { + Name: "str", + Type: cty.String, + }, + { + Name: "prefix", + Type: cty.String, + }, + }, + ReturnTypes: cty.Bool, + Description: "`startswith` takes two values: a string to check and a prefix string. The function returns true if the string begins with that exact prefix.", + } f["timecmp"] = schema.FuncSignature{ - Description: "timecmp compares two timestamps and returns a number that represents the ordering of the instants those timestamps represent.", Params: []function.Parameter{ { - Name: "timestamp_a", - Description: "First timestamp for comparison.", - Type: cty.String, + Name: "timestamp_a", + Type: cty.String, }, { - Name: "timestamp_b", - Description: "Second timestamp for comparison.", - Type: cty.String, + Name: "timestamp_b", + Type: cty.String, }, }, ReturnTypes: cty.Number, + Description: "`timecmp` compares two timestamps and returns a number that represents the ordering of the instants those timestamps represent.", } return f diff --git a/internal/funcs/descriptions.go b/internal/funcs/descriptions.go deleted file mode 100644 index 74b00fea..00000000 --- a/internal/funcs/descriptions.go +++ /dev/null @@ -1,512 +0,0 @@ -package funcs - -type descriptionEntry struct { - // Description is a description for the function. - Description string - - // ParamDescription argument must match the number of parameters of the - // function. If the function has a VarParam then that counts as one - // parameter. The given descriptions will be assigned in order starting - // with the positional arguments in their declared order, followed by the - // variadic parameter if any. - ParamDescription []string -} - -var DescriptionList = map[string]descriptionEntry{ - "abs": { - Description: "`abs` returns the absolute value of the given number. In other words, if the number is zero or positive then it is returned as-is, but if it is negative then it is multiplied by -1 to make it positive before returning it.", - ParamDescription: []string{""}, - }, - "abspath": { - Description: "`abspath` takes a string containing a filesystem path and converts it to an absolute path. That is, if the path is not absolute, it will be joined with the current working directory.", - ParamDescription: []string{""}, - }, - "alltrue": { - Description: "`alltrue` returns `true` if all elements in a given collection are `true` or `"true"`. It also returns `true` if the collection is empty.", - ParamDescription: []string{""}, - }, - "anytrue": { - Description: "`anytrue` returns `true` if any element in a given collection is `true` or `"true"`. It also returns `false` if the collection is empty.", - ParamDescription: []string{""}, - }, - "base64decode": { - Description: "`base64decode` takes a string containing a Base64 character sequence and returns the original string.", - ParamDescription: []string{""}, - }, - "base64encode": { - Description: "`base64encode` applies Base64 encoding to a string.", - ParamDescription: []string{""}, - }, - "base64gzip": { - Description: "`base64gzip` compresses a string with gzip and then encodes the result in Base64 encoding.", - ParamDescription: []string{""}, - }, - "base64sha256": { - Description: "`base64sha256` computes the SHA256 hash of a given string and encodes it with Base64. This is not equivalent to `base64encode(sha256("test"))` since `sha256()` returns hexadecimal representation.", - ParamDescription: []string{""}, - }, - "base64sha512": { - Description: "`base64sha512` computes the SHA512 hash of a given string and encodes it with Base64. This is not equivalent to `base64encode(sha512("test"))` since `sha512()` returns hexadecimal representation.", - ParamDescription: []string{""}, - }, - "basename": { - Description: "`basename` takes a string containing a filesystem path and removes all except the last portion from it.", - ParamDescription: []string{""}, - }, - "bcrypt": { - Description: "`bcrypt` computes a hash of the given string using the Blowfish cipher, returning a string in [the _Modular Crypt Format_](https://passlib.readthedocs.io/en/stable/modular_crypt_format.html) usually expected in the shadow password file on many Unix systems.", - ParamDescription: []string{ - "", - "The `cost` argument is optional and will default to 10 if unspecified.", - }, - }, - "can": { - Description: "`can` evaluates the given expression and returns a boolean value indicating whether the expression produced a result without any errors.", - ParamDescription: []string{""}, - }, - "ceil": { - Description: "`ceil` returns the closest whole number that is greater than or equal to the given value, which may be a fraction.", - ParamDescription: []string{""}, - }, - "chomp": { - Description: "`chomp` removes newline characters at the end of a string.", - ParamDescription: []string{""}, - }, - "chunklist": { - Description: "`chunklist` splits a single list into fixed-size chunks, returning a list of lists.", - ParamDescription: []string{ - "", - "The maximum length of each chunk. All but the last element of the result is guaranteed to be of exactly this size.", - }, - }, - "cidrhost": { - Description: "`cidrhost` calculates a full host IP address for a given host number within a given IP network address prefix.", - ParamDescription: []string{ - "`prefix` must be given in CIDR notation, as defined in [RFC 4632 section 3.1](https://tools.ietf.org/html/rfc4632#section-3.1).", - "`hostnum` is a whole number that can be represented as a binary integer with no more than the number of digits remaining in the address after the given prefix.", - }, - }, - "cidrnetmask": { - Description: "`cidrnetmask` converts an IPv4 address prefix given in CIDR notation into a subnet mask address.", - ParamDescription: []string{ - "`prefix` must be given in CIDR notation, as defined in [RFC 4632 section 3.1](https://tools.ietf.org/html/rfc4632#section-3.1).", - }, - }, - "cidrsubnet": { - Description: "`cidrsubnet` calculates a subnet address within given IP network address prefix.", - ParamDescription: []string{ - "`prefix` must be given in CIDR notation, as defined in [RFC 4632 section 3.1](https://tools.ietf.org/html/rfc4632#section-3.1).", - "`newbits` is the number of additional bits with which to extend the prefix.", - "`netnum` is a whole number that can be represented as a binary integer with no more than `newbits` binary digits, which will be used to populate the additional bits added to the prefix."}, - }, - "cidrsubnets": { - Description: "`cidrsubnets` calculates a sequence of consecutive IP address ranges within a particular CIDR prefix.", - ParamDescription: []string{ - "`prefix` must be given in CIDR notation, as defined in [RFC 4632 section 3.1](https://tools.ietf.org/html/rfc4632#section-3.1).", - "", - }, - }, - "coalesce": { - Description: "`coalesce` takes any number of arguments and returns the first one that isn't null or an empty string.", - ParamDescription: []string{""}, - }, - "coalescelist": { - Description: "`coalescelist` takes any number of list arguments and returns the first one that isn't empty.", - ParamDescription: []string{ - "List or tuple values to test in the given order.", - }, - }, - "compact": { - Description: "`compact` takes a list of strings and returns a new list with any empty string elements removed.", - ParamDescription: []string{""}, - }, - "concat": { - Description: "`concat` takes two or more lists and combines them into a single list.", - ParamDescription: []string{""}, - }, - "contains": { - Description: "`contains` determines whether a given list or set contains a given single value as one of its elements.", - ParamDescription: []string{"", ""}, - }, - "csvdecode": { - Description: "`csvdecode` decodes a string containing CSV-formatted data and produces a list of maps representing that data.", - ParamDescription: []string{""}, - }, - "dirname": { - Description: "`dirname` takes a string containing a filesystem path and removes the last portion from it.", - ParamDescription: []string{""}, - }, - "distinct": { - Description: "`distinct` takes a list and returns a new list with any duplicate elements removed.", - ParamDescription: []string{""}, - }, - "element": { - Description: "`element` retrieves a single element from a list.", - ParamDescription: []string{"", ""}, - }, - "endswith": { - Description: "`endswith` takes two values: a string to check and a suffix string. The function returns true if the first string ends with that exact suffix.", - ParamDescription: []string{"", ""}, - }, - "file": { - Description: "`file` reads the contents of a file at the given path and returns them as a string.", - ParamDescription: []string{""}, - }, - "filebase64": { - Description: "`filebase64` reads the contents of a file at the given path and returns them as a base64-encoded string.", - ParamDescription: []string{""}, - }, - "filebase64sha256": { - Description: "`filebase64sha256` is a variant of `base64sha256` that hashes the contents of a given file rather than a literal string.", - ParamDescription: []string{""}, - }, - "filebase64sha512": { - Description: "`filebase64sha512` is a variant of `base64sha512` that hashes the contents of a given file rather than a literal string.", - ParamDescription: []string{""}, - }, - "fileexists": { - Description: "`fileexists` determines whether a file exists at a given path.", - ParamDescription: []string{""}, - }, - "filemd5": { - Description: "`filemd5` is a variant of `md5` that hashes the contents of a given file rather than a literal string.", - ParamDescription: []string{""}, - }, - "fileset": { - Description: "`fileset` enumerates a set of regular file names given a path and pattern. The path is automatically removed from the resulting set of file names and any result still containing path separators always returns forward slash (`/`) as the path separator for cross-system compatibility.", - ParamDescription: []string{"", ""}, - }, - "filesha1": { - Description: "`filesha1` is a variant of `sha1` that hashes the contents of a given file rather than a literal string.", - ParamDescription: []string{""}, - }, - "filesha256": { - Description: "`filesha256` is a variant of `sha256` that hashes the contents of a given file rather than a literal string.", - ParamDescription: []string{""}, - }, - "filesha512": { - Description: "`filesha512` is a variant of `sha512` that hashes the contents of a given file rather than a literal string.", - ParamDescription: []string{""}, - }, - "flatten": { - Description: "`flatten` takes a list and replaces any elements that are lists with a flattened sequence of the list contents.", - ParamDescription: []string{""}, - }, - "floor": { - Description: "`floor` returns the closest whole number that is less than or equal to the given value, which may be a fraction.", - ParamDescription: []string{""}, - }, - "format": { - Description: "The `format` function produces a string by formatting a number of other values according to a specification string. It is similar to the `printf` function in C, and other similar functions in other programming languages.", - ParamDescription: []string{"", ""}, - }, - "formatdate": { - Description: "`formatdate` converts a timestamp into a different time format.", - ParamDescription: []string{"", ""}, - }, - "formatlist": { - Description: "`formatlist` produces a list of strings by formatting a number of other values according to a specification string.", - ParamDescription: []string{"", ""}, - }, - "indent": { - Description: "`indent` adds a given number of spaces to the beginnings of all but the first line in a given multi-line string.", - ParamDescription: []string{ - "Number of spaces to add after each newline character.", - "", - }, - }, - "index": { - Description: "`index` finds the element index for a given value in a list.", - ParamDescription: []string{"", ""}, - }, - "join": { - Description: "`join` produces a string by concatenating together all elements of a given list of strings with the given delimiter.", - ParamDescription: []string{ - "Delimiter to insert between the given strings.", - "One or more lists of strings to join.", - }, - }, - "jsondecode": { - Description: "`jsondecode` interprets a given string as JSON, returning a representation of the result of decoding that string.", - ParamDescription: []string{""}, - }, - "jsonencode": { - Description: "`jsonencode` encodes a given value to a string using JSON syntax.", - ParamDescription: []string{""}, - }, - "keys": { - Description: "`keys` takes a map and returns a list containing the keys from that map.", - ParamDescription: []string{ - "The map to extract keys from. May instead be an object-typed value, in which case the result is a tuple of the object attributes.", - }, - }, - "length": { - Description: "`length` determines the length of a given list, map, or string.", - ParamDescription: []string{""}, - }, - "list": { - Description: "The `list` function is no longer available. Prior to Terraform v0.12 it was the only available syntax for writing a literal list inside an expression, but Terraform v0.12 introduced a new first-class syntax.", - ParamDescription: []string{""}, - }, - "log": { - Description: "`log` returns the logarithm of a given number in a given base.", - ParamDescription: []string{"", ""}, - }, - "lookup": { - Description: "`lookup` retrieves the value of a single element from a map, given its key. If the given key does not exist, the given default value is returned instead.", - ParamDescription: []string{"", "", ""}, - }, - "lower": { - Description: "`lower` converts all cased letters in the given string to lowercase.", - ParamDescription: []string{""}, - }, - "map": { - Description: "The `map` function is no longer available. Prior to Terraform v0.12 it was the only available syntax for writing a literal map inside an expression, but Terraform v0.12 introduced a new first-class syntax.", - ParamDescription: []string{""}, - }, - "matchkeys": { - Description: "`matchkeys` constructs a new list by taking a subset of elements from one list whose indexes match the corresponding indexes of values in another list.", - ParamDescription: []string{"", "", ""}, - }, - "max": { - Description: "`max` takes one or more numbers and returns the greatest number from the set.", - ParamDescription: []string{""}, - }, - "md5": { - Description: "`md5` computes the MD5 hash of a given string and encodes it with hexadecimal digits.", - ParamDescription: []string{""}, - }, - "merge": { - Description: "`merge` takes an arbitrary number of maps or objects, and returns a single map or object that contains a merged set of elements from all arguments.", - ParamDescription: []string{""}, - }, - "min": { - Description: "`min` takes one or more numbers and returns the smallest number from the set.", - ParamDescription: []string{""}, - }, - "nonsensitive": { - Description: "`nonsensitive` takes a sensitive value and returns a copy of that value with the sensitive marking removed, thereby exposing the sensitive value.", - ParamDescription: []string{""}, - }, - "one": { - Description: "`one` takes a list, set, or tuple value with either zero or one elements. If the collection is empty, `one` returns `null`. Otherwise, `one` returns the first element. If there are two or more elements then `one` will return an error.", - ParamDescription: []string{""}, - }, - "parseint": { - Description: "`parseint` parses the given string as a representation of an integer in the specified base and returns the resulting number. The base must be between 2 and 62 inclusive.", - ParamDescription: []string{"", ""}, - }, - "pathexpand": { - Description: "`pathexpand` takes a filesystem path that might begin with a `~` segment, and if so it replaces that segment with the current user's home directory path.", - ParamDescription: []string{""}, - }, - "pow": { - Description: "`pow` calculates an exponent, by raising its first argument to the power of the second argument.", - ParamDescription: []string{"", ""}, - }, - "range": { - Description: "`range` generates a list of numbers using a start value, a limit value, and a step value.", - ParamDescription: []string{""}, - }, - "regex": { - Description: "`regex` applies a [regular expression](https://en.wikipedia.org/wiki/Regular_expression) to a string and returns the matching substrings.", - ParamDescription: []string{"", ""}, - }, - "regexall": { - Description: "`regexall` applies a [regular expression](https://en.wikipedia.org/wiki/Regular_expression) to a string and returns a list of all matches.", - ParamDescription: []string{"", ""}, - }, - "replace": { - Description: "`replace` searches a given string for another given substring, and replaces each occurrence with a given replacement string.", - ParamDescription: []string{"", "", ""}, - }, - "reverse": { - Description: "`reverse` takes a sequence and produces a new sequence of the same length with all of the same elements as the given sequence but in reverse order.", - ParamDescription: []string{""}, - }, - "rsadecrypt": { - Description: "`rsadecrypt` decrypts an RSA-encrypted ciphertext, returning the corresponding cleartext.", - ParamDescription: []string{"", ""}, - }, - "sensitive": { - Description: "`sensitive` takes any value and returns a copy of it marked so that Terraform will treat it as sensitive, with the same meaning and behavior as for [sensitive input variables](/language/values/variables#suppressing-values-in-cli-output).", - ParamDescription: []string{""}, - }, - "setintersection": { - Description: "The `setintersection` function takes multiple sets and produces a single set containing only the elements that all of the given sets have in common. In other words, it computes the [intersection](https://en.wikipedia.org/wiki/Intersection_\\(set_theory\\)) of the sets.", - ParamDescription: []string{"", ""}, - }, - "setproduct": { - Description: "The `setproduct` function finds all of the possible combinations of elements from all of the given sets by computing the [Cartesian product](https://en.wikipedia.org/wiki/Cartesian_product).", - ParamDescription: []string{ - "The sets to consider. Also accepts lists and tuples, and if all arguments are of list or tuple type then the result will preserve the input ordering", - }, - }, - "setsubtract": { - Description: "The `setsubtract` function returns a new set containing the elements from the first set that are not present in the second set. In other words, it computes the [relative complement](https://en.wikipedia.org/wiki/Complement_\\(set_theory\\)#Relative_complement) of the second set.", - ParamDescription: []string{"", ""}, - }, - "setunion": { - Description: "The `setunion` function takes multiple sets and produces a single set containing the elements from all of the given sets. In other words, it computes the [union](https://en.wikipedia.org/wiki/Union_\\(set_theory\\)) of the sets.", - ParamDescription: []string{"", ""}, - }, - "sha1": { - Description: "`sha1` computes the SHA1 hash of a given string and encodes it with hexadecimal digits.", - ParamDescription: []string{""}, - }, - "sha256": { - Description: "`sha256` computes the SHA256 hash of a given string and encodes it with hexadecimal digits.", - ParamDescription: []string{""}, - }, - "sha512": { - Description: "`sha512` computes the SHA512 hash of a given string and encodes it with hexadecimal digits.", - ParamDescription: []string{""}, - }, - "signum": { - Description: "`signum` determines the sign of a number, returning a number between -1 and 1 to represent the sign.", - ParamDescription: []string{""}, - }, - "slice": { - Description: "`slice` extracts some consecutive elements from within a list.", - ParamDescription: []string{"", "", ""}, - }, - "sort": { - Description: "`sort` takes a list of strings and returns a new list with those strings sorted lexicographically.", - ParamDescription: []string{""}, - }, - "split": { - Description: "`split` produces a list by dividing a given string at all occurrences of a given separator.", - ParamDescription: []string{"", ""}, - }, - "startswith": { - Description: "`startswith` takes two values: a string to check and a prefix string. The function returns true if the string begins with that exact prefix.", - ParamDescription: []string{"", ""}, - }, - "strrev": { - Description: "`strrev` reverses the characters in a string. Note that the characters are treated as _Unicode characters_ (in technical terms, Unicode [grapheme cluster boundaries](https://unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries) are respected).", - ParamDescription: []string{""}, - }, - "substr": { - Description: "`substr` extracts a substring from a given string by offset and (maximum) length.", - ParamDescription: []string{"", "", ""}, - }, - "sum": { - Description: "`sum` takes a list or set of numbers and returns the sum of those numbers.", - ParamDescription: []string{""}, - }, - "templatefile": { - Description: "`templatefile` reads the file at the given path and renders its content as a template using a supplied set of template variables.", - ParamDescription: []string{"", ""}, - }, - "textdecodebase64": { - Description: "`textdecodebase64` function decodes a string that was previously Base64-encoded, and then interprets the result as characters in a specified character encoding.", - ParamDescription: []string{"", ""}, - }, - "textencodebase64": { - Description: "`textencodebase64` encodes the unicode characters in a given string using a specified character encoding, returning the result base64 encoded because Terraform language strings are always sequences of unicode characters.", - ParamDescription: []string{"", ""}, - }, - "timeadd": { - Description: "`timeadd` adds a duration to a timestamp, returning a new timestamp.", - ParamDescription: []string{"", ""}, - }, - "timecmp": { - Description: "`timecmp` compares two timestamps and returns a number that represents the ordering of the instants those timestamps represent.", - ParamDescription: []string{"", ""}, - }, - "timestamp": { - Description: "`timestamp` returns a UTC timestamp string in [RFC 3339](https://tools.ietf.org/html/rfc3339) format.", - ParamDescription: []string{}, - }, - "title": { - Description: "`title` converts the first letter of each word in the given string to uppercase.", - ParamDescription: []string{""}, - }, - "tobool": { - Description: "`tobool` converts its argument to a boolean value.", - ParamDescription: []string{""}, - }, - "tolist": { - Description: "`tolist` converts its argument to a list value.", - ParamDescription: []string{""}, - }, - "tomap": { - Description: "`tomap` converts its argument to a map value.", - ParamDescription: []string{""}, - }, - "tonumber": { - Description: "`tonumber` converts its argument to a number value.", - ParamDescription: []string{""}, - }, - "toset": { - Description: "`toset` converts its argument to a set value.", - ParamDescription: []string{""}, - }, - "tostring": { - Description: "`tostring` converts its argument to a string value.", - ParamDescription: []string{""}, - }, - "transpose": { - Description: "`transpose` takes a map of lists of strings and swaps the keys and values to produce a new map of lists of strings.", - ParamDescription: []string{""}, - }, - "trim": { - Description: "`trim` removes the specified set of characters from the start and end of the given string.", - ParamDescription: []string{ - "", - "A string containing all of the characters to trim. Each character is taken separately, so the order of characters is insignificant.", - }, - }, - "trimprefix": { - Description: "`trimprefix` removes the specified prefix from the start of the given string. If the string does not start with the prefix, the string is returned unchanged.", - ParamDescription: []string{"", ""}, - }, - "trimspace": { - Description: "`trimspace` removes any space characters from the start and end of the given string.", - ParamDescription: []string{""}, - }, - "trimsuffix": { - Description: "`trimsuffix` removes the specified suffix from the end of the given string.", - ParamDescription: []string{"", ""}, - }, - "try": { - Description: "`try` evaluates all of its argument expressions in turn and returns the result of the first one that does not produce any errors.", - ParamDescription: []string{""}, - }, - "type": { - Description: "`type` returns the type of a given value.", - ParamDescription: []string{""}, - }, - "upper": { - Description: "`upper` converts all cased letters in the given string to uppercase.", - ParamDescription: []string{""}, - }, - "urlencode": { - Description: "`urlencode` applies URL encoding to a given string.", - ParamDescription: []string{""}, - }, - "uuid": { - Description: "`uuid` generates a unique identifier string.", - ParamDescription: []string{}, - }, - "uuidv5": { - Description: "`uuidv5` generates a _name-based_ UUID, as described in [RFC 4122 section 4.3](https://tools.ietf.org/html/rfc4122#section-4.3), also known as a "version 5" UUID.", - ParamDescription: []string{"", ""}, - }, - "values": { - Description: "`values` takes a map and returns a list containing the values of the elements in that map.", - ParamDescription: []string{""}, - }, - "yamldecode": { - Description: "`yamldecode` parses a string as a subset of YAML, and produces a representation of its value.", - ParamDescription: []string{""}, - }, - "yamlencode": { - Description: "`yamlencode` encodes a given value to a string using [YAML 1.2](https://yaml.org/spec/1.2/spec.html) block syntax.", - ParamDescription: []string{""}, - }, - "zipmap": { - Description: "`zipmap` constructs a map from a list of keys and a corresponding list of values.", - ParamDescription: []string{"", ""}, - }, -}