terraform/configs/configupgrade
Martin Atkins f93f7e5b5c configs/configupgrade: Remove redundant list brackets
In early versions of Terraform where the interpolation language didn't
have any real list support, list brackets around a single string was the
signal to split the string on a special uuid separator to produce a list
just in time for processing, giving expressions like this:

    foo = ["${test_instance.foo.*.id}"]

Logically this is weird because it looks like it should produce a list
of lists of strings. When we added real list support in Terraform 0.7 we
retained support for this behavior by trimming off extra levels of list
during evaluation, and inadvertently continued relying on this notation
for correct type checking.

During the Terraform 0.10 line we fixed the type checker bugs (a few
remaining issues notwithstanding) so that it was finally possible to
use the more intuitive form:

    foo = "${test_instance.foo.*.id}"

...but we continued trimming off extra levels of list for backward
compatibility.

Terraform 0.12 finally removes that compatibility shim, causing redundant
list brackets to be interpreted as a list of lists.

This upgrade rule attempts to identify situations that are relying on the
old compatibility behavior and trim off the redundant extra brackets. It's
not possible to do this fully-generally using only static analysis, but
we can gather enough information through or partial type inference
mechanism here to deal with the most common situations automatically and
produce a TF-UPGRADE-TODO comment for more complex scenarios where the
user intent isn't decidable with only static analysis.

In particular, this handles by far the most common situation of wrapping
list brackets around a splat expression like the first example above.
After this and the other upgrade rules are applied, the first example
above will become:

    foo = test_instance.foo.*.id
2018-12-07 17:05:36 -08:00
..
test-fixtures configs/configupgrade: Remove redundant list brackets 2018-12-07 17:05:36 -08:00
analysis.go configs/configupgrade: Do type inference with input variables 2018-12-07 17:05:36 -08:00
analysis_expr.go configs/configupgrade: Do type inference with input variables 2018-12-07 17:05:36 -08:00
doc.go configupgrade: new package for upgrading configs for 0.12 2018-10-16 18:50:29 -07:00
module_sources.go configupgrade: Load source code for a module and detect already upgraded 2018-10-16 18:50:29 -07:00
module_sources_test.go configupgrade: Load source code for a module and detect already upgraded 2018-10-16 18:50:29 -07:00
upgrade.go configs/configupgrade: Retain any .tf.json files unchanged 2018-12-04 11:37:39 -08:00
upgrade_body.go configs/configupgrade: Remove redundant list brackets 2018-12-07 17:05:36 -08:00
upgrade_expr.go configs/configupgrade: Remove redundant list brackets 2018-12-07 17:05:36 -08:00
upgrade_native.go configs/configupgrade: Pass through connection and provisioner blocks 2018-12-05 10:25:01 -08:00
upgrade_test.go configs/configupgrade: Remove redundant list brackets 2018-12-07 17:05:36 -08:00
upgrader.go terraform: More wiring in of new provider types 2018-10-16 19:12:54 -07:00