Commit Graph

24 Commits

Author SHA1 Message Date
Mitchell Hashimoto b979d8927e
config: use ast.TypeUnknown and don't remove computed values 2016-11-09 14:28:15 -08:00
Mitchell Hashimoto 37c880c377
Update reflectwalk to fix failing tests
As part of working on ResourceConfig.DeepCopy, Equal I updated
reflectwalk (to fix some issues in the new functions) but this
introduced more issues in other parts of Terraform. This update fixes
those.
2016-09-27 19:16:29 -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
Mitchell Hashimoto 5f3de02fa9 remove config/lang, use hashicorp/hil 2016-02-03 13:24:04 -05:00
Mitchell Hashimoto 693736b52a config: fix tests 2016-01-19 13:17:47 -08:00
Paul Hinze e88aeede9b core: allow distinguishing between empty lists and strings
Had to handle a lot of implicit leaning on a few properties of the old
representation:

 * Old representation allowed plain strings to be treated as lists
   without problem (i.e. shoved into strings.Split), now strings need to
   be checked whether they are a list before they are treated as one
   (i.e. shoved into StringList(s).Slice()).
 * Tested behavior of 0 and 1 length lists in formatlist() was a side
   effect of the representation. Needs to be special cased now to
   maintain the behavior.
 * Found a pretty old context test failure that was wrong in several
   different ways. It's covered by TestContext2Apply_multiVar so I
   removed it.
2015-06-25 18:53:35 -05:00
Paul Hinze 7238b3b4af core: encapsulate representation of StringList
Now the only code that cares about how StringLists are represented lives
inside string_list.go

...which gives us the ability to change it! :)
2015-06-25 17:55:57 -05:00
Paul Hinze 10b3abf405 config: introduce StringList to abstract over list hack
This is the initial pure "all tests passing without a diff" stage. The
plan is to change the internal representation of StringList to include a
suffix delimiter, which will allow us to recognize empty and
single-element lists.
2015-06-25 17:55:56 -05:00
Mitchell Hashimoto 740c25d4ea config: convert to config/lang 2015-01-13 10:27:57 -08:00
Luke Amdor e970eea3cd adding literal colon to interpolated regex 2014-12-21 14:13:41 -06:00
Mitchell Hashimoto 61b46c8612 config: add join() function 2014-10-09 21:22:35 -07:00
Mitchell Hashimoto a931707a6a config: removeCurrent finds the proper map 2014-10-09 17:23:10 -07:00
Mitchell Hashimoto 5c7ce2d003 config: make the tests more robust 2014-10-09 16:13:43 -07:00
Mitchell Hashimoto 22908d67ba config: first pass at replacing lists within a slice 2014-10-09 15:55:22 -07:00
Mitchell Hashimoto eac01c2ac8 config: replace interpolations in block keys [GH-234] 2014-08-27 13:29:02 -07:00
Mitchell Hashimoto 4a3dff2441 config: allow '/' in string args 2014-08-21 11:33:52 -07:00
Mitchell Hashimoto 742e33c672 config: accept file("test.txt") [GH-145] 2014-08-05 10:28:20 -07:00
Mitchell Hashimoto b19a976696 config: additional tests for sanity 2014-08-05 10:11:56 -07:00
Mitchell Hashimoto 4f57437144 config: parser fixes and application 2014-07-22 15:59:53 -07:00
Mitchell Hashimoto 7578fb8bdc config: interpolationWalker detects functions 2014-07-22 06:43:04 -07:00
Mitchell Hashimoto cabc007ec4 config: get rid of the variable*Walkers, replace with more generic 2014-07-21 11:45:56 -07:00
Mitchell Hashimoto e8fe26488a config: interpolationWalk seems to work 2014-07-21 11:30:43 -07:00
Mitchell Hashimoto 4c9e0f395c config: basic interpolationWalker 2014-07-21 11:24:44 -07:00