Commit Graph

25 Commits

Author SHA1 Message Date
Paul Hinze ffa29090ec
core: Better error for dot indexing on user vars
Dot indexing worked in the "regexps and strings" world of 0.6.x, but it
no longer works on the 0.7 series w/ proper List / Map types.

There is plenty of dot-indexed config out in the wild, so we need to do
what we can to point users to the new syntax.

Here is one place we can do it for user variables (`var.somemap`). We'll
also need to address Resource Variables and Module Variables in a
separate PR.

This fixes the panic in #7103 - a proper error message is now returned.
2016-06-12 10:45:48 -05:00
Martin Atkins 718cdda77b config: Parsing of data.TYPE.NAME.FIELD variables
This allows ${data.TYPE.NAME.FIELD} interpolation syntax at the
configuration level, though since there is no special handling of them
in the core package this currently just acts as an alias for
${TYPE.NAME.FIELD}.
2016-05-14 08:26:35 -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
Mitchell Hashimoto 5f3de02fa9 remove config/lang, use hashicorp/hil 2016-02-03 13:24:04 -05:00
Paul Hinze 928f534cfc template_file: source contents instead of path
Building on the work of #3846, deprecate `filename` in favor of a
`template` attribute that accepts file contents instead of a path.

Required a bit of work in the interpolation code to prevent Terraform
from assuming that template interpolations were resource variables that
needed to be resolved. Leaving them as "Unknown Variables" prevents
interpolation from happening early and lets the `template_file` resource
do its thing.
2015-11-13 11:24:20 -06:00
Mitchell Hashimoto 9c612964d8 config: self variables 2015-02-23 14:34:25 -08:00
Mitchell Hashimoto 2abeb2d9ac config: use new API 2015-01-14 22:03:15 -08:00
Mitchell Hashimoto 49fe0d5c7f config: remove a lot of unused stuff 2015-01-13 11:54:30 -08:00
Mitchell Hashimoto 1ccad4d729 config: convert fucntions, put functions into Scope 2015-01-13 11:50:44 -08:00
Mitchell Hashimoto aa2c7b2764 config: DetectVariables to detect interpolated variables in an AST 2015-01-12 12:09:43 -08:00
Mitchell Hashimoto d714c6f2f1 terraform: test path variables 2014-10-07 20:09:30 -07:00
Mitchell Hashimoto 679ab1d515 config: parse ${path.module} 2014-10-07 18:03:11 -07:00
Mitchell Hashimoto 8756d52124 config: count.index parses 2014-10-02 18:20:55 -07:00
Mitchell Hashimoto 46c140c797 config: can parse module variables 2014-09-15 11:40:25 -07:00
Mitchell Hashimoto bff5c09164 config: test nested function calls 2014-07-22 16:16:46 -07:00
Mitchell Hashimoto 4f57437144 config: parser fixes and application 2014-07-22 15:59:53 -07:00
Mitchell Hashimoto 1dcefba5c4 config: parser 2014-07-22 15:23:01 -07:00
Mitchell Hashimoto db160a0249 config: add LiteralInterpolation 2014-07-22 14:21:47 -07:00
Mitchell Hashimoto 7b3a462ad1 config: remove UserMapVariable 2014-07-22 08:51:50 -07:00
Mitchell Hashimoto e59ff6e92c terraform: fix tests 2014-07-22 08:29:49 -07:00
Mitchell Hashimoto aeb085c5f0 config: error if variable interpolation can't find variable 2014-07-22 06:51:02 -07:00
Mitchell Hashimoto 7578fb8bdc config: interpolationWalker detects functions 2014-07-22 06:43:04 -07:00
Mitchell Hashimoto 6a191d7395 config: function calls work 2014-07-21 12:56:41 -07:00
Mitchell Hashimoto 4c9e0f395c config: basic interpolationWalker 2014-07-21 11:24:44 -07:00
Mitchell Hashimoto 582b0cf43e config: introduce Interpolation, not hooked up completely yet 2014-07-21 10:39:55 -07:00