Commit Graph

104 Commits

Author SHA1 Message Date
Borys Pierov c811440188 config: Don't log the private key on error in rsadecrypt 2018-06-26 15:19:37 -07:00
Masayuki Morita e873af9337 Fix panic with substr interpolation function by invalid offset
Fixes #17041
2018-01-06 00:59:35 +09:00
David Meyer fe0cc3b0db config: new "rsadecrypt" interpolation function
The primary use-case is to decrypt windows passwords obtained from AWS, but this function is generic and may find other purposes too.
2017-12-05 11:06:32 -08:00
mizuno 01c1142589 config: new "timeadd" interpolation function 2017-12-05 10:46:12 -08:00
Gauthier Wallet ed9ba576e3 core: New interpolation function "chunklist"
This turns a list into a list of lists with each element (apart from possibly the last) being the given length.
2017-10-10 11:56:13 -07:00
Ariel Alonso 550ae05819 config: new "transpose" interpolation function
This function takes a map of lists of strings and inverts it so that
the string values become keys and the keys become items within the
corresponding lists.
2017-09-28 10:29:25 -07:00
Krzysztof Wilczynski 6e7e03f4ea config: new "abs" interpolation function
This new function returns the absolute value for a given number.
2017-09-25 14:19:18 -07:00
Micah Hausler 7fa4b648bb config: multi-line "indent" function
This function prepends a number of spaces on to all but the first line
of a string containing multiple lines of text.
2017-09-14 09:47:48 -07:00
Sunny 06fd5d7a3e config: urlencode interpolation function
This escapes all characters that might have a special interpretation when embedded into a portion of a URL, including slashes, equals signs and ampersands.
2017-08-22 11:26:09 -07:00
Gorka Lerchundi Osa a303817e03 config: base64gzip interpolation function
Since Terraform's internals are not 8-bit clean (it assumes UTF-8
strings), we can't implement raw gzip directly. We're going to add
support where it makes sense for passing data to attributes as
base64 so that the result of this function can be used.
2017-08-22 10:44:55 -07:00
Sebastian Maj 28b5708fef config: jsonencode function to support nested lists and maps 2017-08-18 09:57:57 -07:00
JWal31 117f44bcda config: Add "flatten" interpolation function
This function turns a list of lists or any arbitrary number of nested
lists into a flat list of primitive values.
2017-08-16 13:46:19 -07:00
trung 681661a539 #15291: config/interpolate_funcs: Added contains() function to test if a given element is present in the list 2017-06-16 15:05:19 -07:00
jasminSPC bca159160e Added missing dependencies 2017-05-22 12:02:32 +02:00
Pradeep Bhadani 47b1aaea3a Add pow function 2017-05-17 21:46:33 +00:00
Joshua Spence 38d4d2f9d4 Add a logarithm function
Fixes #9498. Adds a `log` function for calculating logarithms.
2017-05-05 17:06:53 +10:00
Martins Sipenko c7fb9808ef config: sha512 hash functions (#14100) 2017-05-02 16:35:23 -07:00
Jake Champlin 70bc1e1dcc Merge pull request #12537 from Pryz/coalescelist
Add coalescelist interpolation function
2017-04-21 15:23:21 -04:00
Pavel Khusainov f9fb6010ee config: "matchkeys" interpolation function
This new function allows using a search within one list to filter another list. For example, it can be used to find the ids of EC2 instances in a particular AZ.

The interface is made slightly awkward by the constraints of HIL's featureset.

#13847
2017-04-21 10:04:49 -07:00
Joern Barthel 9622b49c45 Support for Windows newlines. 2017-04-07 10:41:55 +02:00
Joern Barthel 059a1b2c0f Added chomp interpolation function. 2017-04-06 13:17:25 +02:00
Joshua Spence af2c84de5a Add `basename` and `dirname` functions
Adds `basename` and `dirname` interpolation. I want to add a `stack` tag to our infrastructure, the value of which is set to `${basename(path.cwd)}`. We currently use `${replace(path.cwd, "/^.+\\//", "")}` instead, but this is extremeley unreadable. The existance of a `basename` function would be very useful for this use case.

I don't have an immediate use case for a `dirname` function, but it seemed reasonable to add it as well.
2017-03-28 09:29:26 -07:00
Joshua Spence e71d6d92ad Add a substring interpolation function (#12870)
Adds a new `substr` interpolation function which can be used to truncate a string.
2017-03-22 11:30:39 -04:00
Pryz 733f1ca1e7 Add coalescelist interpolation function 2017-03-08 12:38:08 -08:00
Kit Ewbank 549cff56d0 Add 'slice' interpolation function. (#9729) 2017-02-13 21:20:02 +00:00
Jake Champlin 0b73b92830
core: Add pathexpand interpolation function
Adds the `pathexpand` interpolation function to allow users to expand `~` to the home directory in filepath strings.
2017-01-18 16:11:19 -05:00
Mitchell Hashimoto 692eadd763
config: nitpicks from #10475
/cc @grubernaut - we put stdlibs above 3rd party libs separated by a
space
2016-12-01 18:02:39 -05:00
Jake Champlin 1f33952330
Add the timestamp interpolation function.
Adds the timestamp interpolation function, tests, and documentation to allow a user to insert an RFC 3339 formatted UTC timestamp.
2016-12-01 14:51:01 -05:00
Mitchell Hashimoto d69b6257df
config: formatlist accepts an empty list
Fixes #7607

An empty list is a valid value for formatlist which means to just return
an empty list as a result. The logic was somewhat convoluted here so I
cleaned that up a bit too. The function overall can definitely be
cleaned up a lot more but I left it mostly as-is to fix the bug.
2016-11-01 22:57:11 -07:00
Jesse Szwedko 0fbd72a355 Add some basic math interpolation functions
Support the following math functions for interpolation:

* ceil
* floor
* max
* min

Fixes #7409
2016-10-28 17:49:31 +00:00
James Nugent 47bce79b29 core: Add zipmap interpolation function
This commit adds a new interpolation function, zipmap, which produces a
map given a list of string keys and a list of values of the same length
as the list of keys.

The name comes from the same operation in Clojure (and likely other
functional langauges).
2016-10-26 11:28:36 -05:00
Gustavo 5910e3b8af Adds ‘tittle’ built-in function. (#9087)
The tittle function returns a copy of the string with the first characters of all the words capitalized.
2016-10-26 13:21:32 +01:00
James Bardin 39bbbb8da6 Add merge interpolation function
Add a `merge` interpolation function, which merges any number of maps.
Duplicate keys are OK, with the last write winning.
2016-08-01 18:30:58 -04:00
James Bardin c9e1522103 Use HIL to limit concat to ast.TypeList
we can remove some type checks in the concat function
2016-08-01 15:24:18 -04:00
James Bardin c15c0eb0cb Disallow strings as arguments to concat
The concat interpolation function now only accepts list arguments.
Strings are no longer supported, for concatenation or appending to
lists. All arguments must be a list, and single elements can be promoted
with the `list` interpolation function.
2016-08-01 15:06:20 -04:00
Paul Hinze 88030764ff
config: Audit all interpolation functions for list/map behavior
- `distinct()` - error on non-flat lists
 - `element()` - error on non-flat lists
 - `join()` - error on non-flat lists
 - `length()` - support maps
 - `lookup()` - error on non-flat maps
 - `values()` - error on non-flat maps
2016-07-28 09:56:30 -05:00
Paul Hinze 1425b34562
config: Add map() interpolation function
* `map(key, value, ...)` - Returns a map consisting of the key/value pairs
  specified as arguments. Every odd argument must be a string key, and every
  even argument must have the same type as the other values specified.
  Duplicate keys are not allowed. Examples:
  * `map("hello", "world")`
  * `map("us-east", list("a", "b", "c"), "us-west", list("b", "c", "d"))`
2016-07-27 13:03:08 -05:00
James Bardin 8dcbc0b0a0 Add concat to accept lists of lists and maps
This will allow the concat interpolation function to accept lists of
lists, and lists of maps as well as strings. We still allow bare strings
for backwards compatibility, but remove some of the old comment wording
as it could cause confusion of this function with actual string
concatenation.

Since maps are now supported in the config, this removes the superfluous
(and failing) TestInterpolationFuncConcatListOfMaps.
2016-07-19 17:45:50 -04:00
James Bardin 2bd7cfd5fe Expand list interpolation to lists and maps
Allow lists and maps within the list interpolation function via variable
interpolation. Since this requires setting the variadic type to TypeAny,
we check for non-heterogeneous lists in the callback.
2016-07-19 13:44:37 -04:00
James Nugent 58dd41f3b1 core: Add list() interpolation function
The list() interpolation function provides a way to add support for list
literals (of strings) to HIL without having to invent new syntax for it
and modify the HIL parser.

It presents as a function, thus:

    - list() -> []
    - list("a") -> ["a"]
    - list("a", "b") -> ["a", "b"]

Thanks to @wr0ngway for the idea of this approach, fixes #7460.
2016-07-18 18:12:11 -04:00
James Nugent 8403a465bc core: Add test and fix for element with empty list
The incldued test previously caused a panic, it now returns an error
message explaining the issue.
2016-06-23 21:15:33 +01:00
James Nugent 4b6a632246 core: Rename uniq -> distinct and add docs 2016-06-15 13:25:17 +02:00
Jan Schumann df3e017f6c fix #7106 2016-06-15 13:25:16 +02:00
Paul Hinze 9bc980f569
core: Fix panic on concat() w/ list of nonprimitives
The `concat()` interpolation function does not yet support types other
than strings / lists of strings. Make it an error message instead of a
panic when a list of non-primitives is supplied.

Fixes the panic in #7030
2016-06-12 13:29:06 -05:00
James Nugent 578ff9569e core: Add sort() interpolation function 2016-06-11 18:03:52 +01:00
David Adams b5d1279107 Allow specifying a default value to lookup()
Fixes #4474, where lookup() calls fail out the entire interpolation when
the provided key value is not found in the map. This will allow using
coalesce() along with lookup() to greatly improve module flexibility.
2016-05-25 19:25:15 -05:00
David Glasser 594ea105d8 config: support lists and maps in jsonencode
For now we only support lists and maps whose values are strings, not
deeply nested data.
2016-05-18 10:46:06 -07:00
James Nugent f49583d25a core: support native list variables in config
This commit adds support for native list variables and outputs, building
up on the previous change to state. Interpolation functions now return
native lists in preference to StringList.

List variables are defined like this:

variable "test" {
    # This can also be inferred
    type = "list"
    default = ["Hello", "World"]
}

output "test_out" {
    value = "${var.a_list}"
}
This results in the following state:

```
...
            "outputs": {
                "test_out": [
                    "hello",
                    "world"
                ]
            },
...
```

And the result of terraform output is as follows:

```
$ terraform output
test_out = [
  hello
  world
]
```

Using the output name, an xargs-friendly representation is output:

```
$ terraform output test_out
hello
world
```

The output command also supports indexing into the list (with
appropriate range checking and no wrapping):

```
$ terraform output test_out 1
world
```

Along with maps, list outputs from one module may be passed as variables
into another, removing the need for the `join(",", var.list_as_string)`
and `split(",", var.list_as_string)` which was previously necessary in
Terraform configuration.

This commit also updates the tests and implementations of built-in
interpolation functions to take and return native lists where
appropriate.

A backwards compatibility note: previously the concat interpolation
function was capable of concatenating either strings or lists. The
strings use case was deprectated a long time ago but still remained.
Because we cannot return `ast.TypeAny` from an interpolation function,
this use case is no longer supported for strings - `concat` is only
capable of concatenating lists. This should not be a huge issue - the
type checker picks up incorrect parameters, and the native HIL string
concatenation - or the `join` function - can be used to replicate the
missing behaviour.
2016-05-10 14:49:14 -04:00
James Nugent e57a399d71 core: Use native HIL maps instead of flatmaps
This changes the representation of maps in the interpolator from the
dotted flatmap form of a string variable named "var.variablename.key"
per map element to use native HIL maps instead.

This involves porting some of the interpolation functions in order to
keep the tests green, and adding support for map outputs.

There is one backwards incompatibility: as a result of an implementation
detail of maps, one could access an indexed map variable using the
syntax "${var.variablename.key}".

This is no longer possible - instead HIL native syntax -
"${var.variablename["key"]}" must be used. This was previously
documented, (though not heavily used) so it must be noted as a backward
compatibility issue for Terraform 0.7.
2016-05-10 14:49:13 -04:00
David Glasser 6cf06bb3ab config: new interpolation function jsonencode 2016-03-29 07:38:58 -07:00