Commit Graph

26 Commits

Author SHA1 Message Date
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
James Nugent
6aac79e194 state: Add support for outputs of multiple types
This commit adds the groundwork for supporting module outputs of types
other than string. In order to do so, the state version is increased
from 1 to 2 (though the "public-facing" state version is actually as the
first state file was binary).

Tests are added to ensure that V2 (1) state is upgraded to V3 (2) state,
though no separate read path is required since the V2 JSON will
unmarshal correctly into the V3 structure.

Outputs in a ModuleState are now of type map[string]interface{}, and a
test covers round-tripping string, []string and map[string]string, which
should cover all of the types in question.

Type switches have been added where necessary to deal with the
interface{} value, but they currently default to panicking when the input
is not a string.
2016-05-10 14:40:12 -04:00
Paul Hinze
024dcc9d32 terraform: share graph walker's variables lock w/ interpolater
The ContextGraphWalker struct includes a lock that's passed down to
BuiltinEvalContext and guards access to interpolation variables as
they're written using SetVariables.

The likely problem being expressed in #5733 is that the same map
reference is also passed down to the Interpolater.Variables field, which
is used for variable lookup.

Here, we plumb the same lock we're using to guard access for writes down
and acquire it before doing variable reads as well. It's not as fine
grained as perhaps it could be, but all the context tests pass and I
believe this should address #5733.
2016-03-21 18:21:44 -05:00
Paul Hinze
fbc9cf9ddb core: error instead of panic on self var in wrong scope
Fixes #4808
Fixes #5174
2016-02-23 11:44:24 -06:00
Mitchell Hashimoto
8be4afacf8 terraform: replace config/lang usage 2016-02-03 13:24:04 -05:00
Paul Hinze
48b172aa86 core: treat refs to unknown set resource attrs as unknown
References to computed list-ish attributes (set, list, map) were being
improperly resolved as an empty list `[]` during the plan phase (when
the value of the reference is not yet known) instead of as an
UnknownValue.

A "diffs didn't match" failure in an AWS DirectoryServices test led to
this discovery (and this commit fixes the failing test):

https://travis-ci.org/hashicorp/terraform/jobs/104812951

Refs #2157 which has the original work to support computed list
attributes at all. This is just a simple tweak to that work.

/cc @radeksimko
2016-01-26 13:50:44 -06: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
Radek Simko
3a05f01553 Treat missing variables during destroy as unknown 2015-10-03 14:16:40 -07:00
Paul Hinze
c39fdd2917 Merge pull request #2988 from hashicorp/b-input-var-partially-computed
core: don't error on computed value during input walk
2015-09-24 15:07:49 -05:00
Radek Simko
91d750d2df interpolate: Expand computed TypeList attributes properly 2015-08-27 13:02:02 +01:00
Paul Hinze
b928777cac core: don't error on computed value during input walk
fixes #2987
2015-08-12 14:23:33 -05:00
Mitchell Hashimoto
4d361c839e terraform: prune resources and variables 2015-07-20 08:57:34 -07:00
Mitchell Hashimoto
7735847579 terraform: splatting with computed values is computed [GH-2744] 2015-07-19 17:27:38 -07: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
592df714eb Merge pull request #2478 from hashicorp/b-invalid-var-should-error
terraform: error if resource not found in module [GH-1997]
2015-06-25 08:56:20 -07:00
Mitchell Hashimoto
fcc710ca06 terraform: error if resource not found in module [GH-1997] 2015-06-24 22:25:48 -07:00
Mitchell Hashimoto
54b961630d terraform: module computed vars with splat vars don't error 2015-06-24 21:23:37 -07:00
Mitchell Hashimoto
fe74d69852 terraform: validation should succeed if env var set [GH-1930] 2015-05-13 20:09:05 -07:00
Mitchell Hashimoto
f86dc22caf terraform: return unknown if resource not found 2015-05-11 14:57:20 -07:00
Mitchell Hashimoto
5ae9ee4d27 terraform: allow TF_VAR_name to be set to set variables 2015-04-22 06:31:53 +02:00
Paul Hinze
347690a73e core: don't crash when count.index is used in the wrong context
It's bad manners! :)

Also adds a validation error up at the configuration layer so the user
sees the case from #1528 as an error message.

fixes #1528
2015-04-15 10:23:53 -05:00
Mitchell Hashimoto
4c3923e32a terraform: return value for resource interpolation on refresh
Instead of returning UnknownVariableValue every time, attempt to return
the real value. If we don't find it, return unknown value. This fixes
removing outputs from state on refresh.
2015-04-10 13:51:22 -07:00
Mitchell Hashimoto
0e59acc2c9 terraform: enable self vars 2015-02-23 14:56:02 -08:00
Mitchell Hashimoto
d9118007ea terraform: fix some failing tess 2015-02-19 12:08:02 -08:00
Mitchell Hashimoto
3908b6319a terraform: pulling out everything into Interpolater 2015-02-19 12:07:56 -08:00
Mitchell Hashimoto
76ce6e45f7 terraform: extract interpolation to its own struct
This is not really improving the way we do interpolation so much as its
just shuffling bits around. I don't want to refactor interpolation in
this branch so I needed to make the current way reusable so that I can
reuse it in the new Context.
2015-02-19 12:07:56 -08:00