terraform/config
Martin Atkins 410b60cb7f Stop requiring multi-vars (splats) to be in array brackets
Prior to Terraform 0.7, lists in Terraform were just a shallow abstraction
on top of strings with a magic delimiter between items. Wrapping a single
string in brackets in the configuration was Terraform's prompt that it
needed to split the string on that delimiter during interpolation.

In 0.7, when first-class lists were added, this convention was preserved
by flattening lists-of-lists by one level when they were encountered in
configuration. However, there was an oversight in that change where it
did not correctly handle the case where the inner list was unknown.

In #14135 we removed some code that was flattening partially-unknown lists
into fully-unknown (untyped) values. This inadvertently exposed the missed
case from the previous paragraph, causing issues for list-wrapped splat
expressions with unknown members. While this worked fine for resources,
due to some fixup done inside helper/schema, this did not work for other
interpolation contexts such as module blocks.

Various attempts to fix this up and restore the flattening behavior
selectively were unsuccessful, due to a proliferation of assumptions all
over the core code that would be too risky to change just to fix this bug.

This change, then, takes the different approach of removing the
requirement that splats be presented inside list brackets. This
requirement didn't make much sense anymore anyway, since no other
list-returning expression had this constraint and so the rest of Terraform
was already successfully dealing with both cases.

This leaves us with two different scenarios:

- For resource arguments, existing normalization code in helper/schema
  does its own flattening that preserves compatibility with the common
  practice of using bracketed splats. This change proves this with a test
  within the "test" provider that exercises the whole Terraform core and
  helper/schema stack that assigns bracketed splats to list and set
  attributes.

- For arguments in other blocks, such as in module callsites, the
  interpolator's own flattening behavior applies to known lists,
  preserving compatibility with configurations from before
  partially-computed splats were possible, but those wishing to use
  partially-computed splats are required to drop the surrounding brackets.
  This is less concerning because this scenario was introduced only in
  0.9.5, so the scope for breakage is limited to those who adopted this
  new feature quickly after upgrading.

As of this commit, the recommendation is to stop using brackets around
splats but the old form continues to be supported for backward
compatibility. In a future _major_ version of Terraform we will probably
phase out this legacy form to improve consistency, but for now both
forms are acceptable at the expense of some (pre-existing) weird behavior
when _actual_ lists-of-lists are used.

This addresses #14521 by officially adopting the suggested workaround of
dropping the brackets around the splat. However, it doesn't yet allow
passing of a partially-unknown list between modules: that still violates
assumptions in Terraform's core, so for the moment partially-unknown lists
work only within a _single_ interpolation expression, and cannot be
passed around between expressions. Until more holistic work is done to
improve Terraform's type handling, passing a partially-unknown splat
through to a module will result in a fully-unknown list emerging on
the other side, just as was the case before #14135; this change just
addresses the fact that this was failing with an error in 0.9.5.
2017-05-23 11:22:37 -07:00
..
module config/module: don't panic when referencing undefined module 2017-03-16 20:14:20 -07:00
test-fixtures Stop requiring multi-vars (splats) to be in array brackets 2017-05-23 11:22:37 -07:00
append.go merge config.Terraform fields in config.Append 2017-03-21 15:43:55 -04:00
append_test.go add terraform config merge logic to config.Merge 2017-03-22 09:01:54 -04:00
config.go Stop requiring multi-vars (splats) to be in array brackets 2017-05-23 11:22:37 -07:00
config_string.go config: add "backend" loading to the Terraform section 2017-01-26 14:33:49 -08:00
config_terraform.go add Rehash to terraform.BackendState 2017-03-29 15:53:42 -04:00
config_terraform_test.go config: add "backend" loading to the Terraform section 2017-01-26 14:33:49 -08:00
config_test.go Stop requiring multi-vars (splats) to be in array brackets 2017-05-23 11:22:37 -07:00
config_tree.go config: make Merge an exported func 2014-07-18 17:05:22 -07:00
import_tree.go Condense switch fallthroughs into expr lists 2015-05-26 21:52:36 -04:00
interpolate.go config: parse TerraformVariables 2017-03-13 16:09:06 -07:00
interpolate_funcs.go Add pow function 2017-05-17 21:46:33 +00:00
interpolate_funcs_test.go Add fail test - one parameter, non-numeric parameter 2017-05-18 14:30:10 +00:00
interpolate_test.go config: parse TerraformVariables 2017-03-13 16:09:06 -07:00
interpolate_walk.go Fix panic in interpolate_walk 2017-03-07 15:35:40 -05:00
interpolate_walk_test.go config: use ast.TypeUnknown and don't remove computed values 2016-11-09 14:28:15 -08:00
lang.go remove config/lang, use hashicorp/hil 2016-02-03 13:24:04 -05:00
loader.go command/import: load configurations and allow empty config dirs 2016-11-09 15:08:22 -08:00
loader_hcl.go config: generate errors for unnamed blocks of various sources 2017-05-02 16:29:57 -07:00
loader_hcl_test.go config: HCL loader 2014-08-11 09:58:53 -07:00
loader_test.go config: generate errors for unnamed blocks of various sources 2017-05-02 16:29:57 -07:00
merge.go add terraform config merge logic to config.Merge 2017-03-22 09:01:54 -04:00
merge_test.go add terraform config merge logic to config.Merge 2017-03-22 09:01:54 -04:00
provisioner_enums.go config: parse "when" and "on_failure" on provisioners 2017-01-19 18:10:21 -08:00
raw_config.go config: Merge respects Terraform blocks, provider aliases, and more 2016-12-13 21:48:59 -08:00
raw_config_test.go config: validate that RawConfig.Copy doesn't copy the interpolated 2016-12-02 13:25:32 -05:00
resource_mode.go config: "ResourceMode" concept for resources 2016-05-14 08:26:35 -07:00
resource_mode_string.go Restore stringer-generated files back to new version 2017-04-21 14:49:18 -07:00
testing.go terraform: rename attach config to only attach provider config 2016-10-19 13:38:51 -07:00