Commit Graph

1176 Commits

Author SHA1 Message Date
James Nugent fa64ac7815 release: clean up after v0.7.0 2016-08-02 18:17:05 +00:00
James Nugent e822a79165
v0.7.0 2016-08-02 17:59:44 +00:00
James Bardin 1af7ee87a2 Silence log output when not verbose
Set the default log package output to iotuil.Discard during tests if the
`-v` flag isn't set. If we are verbose, then apply the filter according
to the TF_LOG env variable.
2016-08-01 17:19:14 -04:00
Paul Stack 2e38467213 release: clean up after v0.7.0-rc4 2016-07-30 00:53:38 +00:00
Paul Stack abfd2c1daf
v0.7.0-rc4 2016-07-29 23:40:54 +00:00
James Bardin 2747d964cb Merge pull request #7877 from hashicorp/jbardin/races
core: Fix race conditions, mostly around diffs
2016-07-29 18:42:31 -04:00
Paul Hinze 46b78286bc Merge pull request #7865 from hashicorp/b-filter-untargeted-variables
terraform: Filter untargeted variable nodes
2016-07-29 17:08:08 -05:00
Paul Hinze 24c45fcd5d
terraform: Filter untargeted variable nodes
When targeting, only Addressable untargeted nodes were being removed
from the graph. Variable nodes are not directly Addressable, so they
were hanging around. This caused problems with module variables that
referred to Resource nodes. The Resource node would be filtered out of
the graph, but the module Variable node would not, so it would try to
interpolate during the graph walk and be unable to find it's referent.

This would present itself as strange "cannot find variable" errors for
variables that were uninvolved with the currently targeted set of
resources.

Here, we introduce a new interface that can be implemented by graph
nodes to indicate they should be filtered out from targeting even though
they are not directly addressable themselves.
2016-07-29 16:55:30 -05:00
James Nugent 9034196baf Merge pull request #7875 from hashicorp/b-outputs-by-module
core: Fix -module for terraform output command
2016-07-29 16:40:24 -05:00
James Nugent 0e4e94a86f core: Fix -module for terraform output command
The behaviour whereby outputs for a particular nested module can be
output was broken by the changes for lists and maps. This commit
restores the previous behaviour by passing the module path into the
outputsAsString function.

We also add a new test of this since the code path for indivdual output
vs all outputs for a module has diverged.
2016-07-29 16:39:59 -05:00
James Bardin 5802f76eaa Make all terraform package tests pass under -race
This isn't a pretty refactor, but fixes the race issues in this package
for now.

Fix race on RawConfig.Config()

fix command package races
2016-07-29 16:12:21 -04:00
Clint a9aaf44a87 fix make issues (supersedes #7868) (#7876)
* Fixing the make error or invalid data type for errorf and printf

* fix make errors
2016-07-29 21:05:57 +01:00
James Bardin 9dec28bccf Merge pull request #7803 from hashicorp/jbardin/tf_vars-push
Add tf_vars to the variables sent in push
2016-07-28 16:31:04 -04:00
James Bardin 341abd7956 limit input retries
Prevent going into a busy loop if the input fd closes early.
2016-07-28 08:49:09 -04:00
James Nugent 7af10adcbe core: Do not assume HCL parser has touched vars
This PR fixes #7824, which crashed when applying a plan file. The bug is
that while a map which has come from the HCL parser reifies as a
[]map[string]interface{}, the variable saved in the plan file was not.
We now cover both cases.

Fixes #7824.
2016-07-27 17:14:47 -05:00
James Nugent 681d94ae20 core: Allow lists and maps as variable overrides
Terraform 0.7 introduces lists and maps as first-class values for
variables, in addition to string values which were previously available.
However, there was previously no way to override the default value of a
list or map, and the functionality for overriding specific map keys was
broken.

Using the environment variable method for setting variable values, there
was previously no way to give a variable a value of a list or map. These
now support HCL for individual values - specifying:

    TF_VAR_test='["Hello", "World"]'

will set the variable `test` to a two-element list containing "Hello"
and "World". Specifying

    TF_VAR_test_map='{"Hello = "World", "Foo" = "bar"}'

will set the variable `test_map` to a two-element map with keys "Hello"
and "Foo", and values "World" and "bar" respectively.

The same logic is applied to `-var` flags, and the file parsed by
`-var-files` ("autoVariables").

Note that care must be taken to not run into shell expansion for `-var-`
flags and environment variables.

We also merge map keys where appropriate. The override syntax has
changed (to be noted in CHANGELOG as a breaking change), so several
tests needed their syntax updating from the old `amis.us-east-1 =
"newValue"` style to `amis = "{ "us-east-1" = "newValue"}"` style as
defined in TF-002.

In order to continue supporting the `-var "foo=bar"` type of variable
flag (which is not valid HCL), a special case error is checked after HCL
parsing fails, and the old code path runs instead.
2016-07-26 15:27:29 -05:00
James Bardin f66d1a10a4 Add VersionString
We conditionally format version with VersionPrerelease in a number of
places. Add a package-level function where we can unify the version
format. Replace most of version formatting in terraform, but leave th
few instances set from the top-level package to make sure we don't break
anything before release.
2016-07-21 16:43:49 -04:00
James Bardin 885935962c Add a terraform version header to all atlas calls
Using the DefaultHeader added to the atlas.Client
2016-07-21 11:04:27 -04:00
James Bardin 87a5ce8045 Add tests for maps with dots
This adds some unit tests for config maps with dots in the key values.
We check for maps with keys which have overlapping names. There are
however still issues with nested maps which create overlapping flattened
names, as well as nested lists with dots in the key.
2016-07-20 14:08:14 -04:00
James Nugent 5d18f41f04 core: Convert context vars to map[string]interface{}
This is the first step in allowing overrides of map and list variables.
We convert Context.variables to map[string]interface{} from
map[string]string and fix up all the call sites.
2016-07-18 13:02:54 -05:00
Paul Hinze 7c40c174ef
clean up after v0.7.0-rc3 2016-07-15 18:33:02 -06:00
Paul Hinze 3f4857a07a
v0.7.0-rc3 2016-07-15 22:29:21 +00:00
Paul Hinze b45f53eef4
dag: fix ReverseDepthFirstWalk when nodes remove themselves
The report in #7378 led us into a deep rabbit hole that turned out to
expose a bug in the graph walk implementation being used by the
`NoopTransformer`. The problem ended up being when two nodes in a single
dependency chain both reported `Noop() -> true` and needed to be
removed. This was breaking the walk and preventing the second node from
ever being visited.

Fixes #7378
2016-07-15 13:43:28 -06:00
Paul Hinze 9fe916248c Merge pull request #7654 from hashicorp/zeroae-b-triton-dot-in-tags
Support "." in map keys
2016-07-15 09:48:19 -06:00
James Nugent 340655d56c core: Allow "." character in map keys
Fixes #2143 and fixes #7130.
2016-07-14 12:38:43 -06:00
James Nugent 56aadab115 core: Add context test for module var from splat
This adds additional coverage of the situation reported in #7195 to
prevent against regression. The actual fix was in 2356afd, in response
to #7143.
2016-07-13 11:23:56 -06:00
James Nugent 788bff46e2 Merge pull request #7563 from hashicorp/b-ignore-changes-dependency
terraform: another set of ignore_changes fixes
2016-07-13 11:06:49 -06:00
James Nugent d955c5191c core: Fix interpolation tests with nested lists
Some of the tests for splat syntax were from the pre-list-and-map world,
and effectively flattened the values if interpolating a resource value
which was itself a list.

We now set the expected values correctly so that an interpolation like
`aws_instance.test.*.security_group_ids` now returns a list of lists.

We also fix the implementation to correctly deal with maps.
2016-07-11 17:02:12 -06:00
Paul Hinze 14cea95e86
terraform: another set of ignore_changes fixes
This set of changes addresses two bug scenarios:

(1) When an ignored change canceled a resource replacement, any
downstream resources referencing computer attributes on that resource
would get "diffs didn't match" errors. This happened because the
`EvalDiff` implementation was calling `state.MergeDiff(diff)` on the
unfiltered diff. Generally this is what you want, so that downstream
references catch the "incoming" values. When there's a potential for the
diff to change, thought, this results in problems w/ references.

Here we solve this by doing away with the separate `EvalNode` for
`ignore_changes` processing and integrating it into `EvalDiff`. This
allows us to only call `MergeDiff` with the final, filtered diff.

(2) When a resource had an ignored change but was still being replaced
anyways, the diff was being improperly filtered. This would cause
problems during apply when not all attributes were available to perform
the replacement.

We solve that by deferring actual attribute removal until after we've
decided that we do not have to replace the resource.
2016-07-08 16:48:23 -05:00
James Nugent b6fff854a6 core: Set all unknown keys to UnknownVariableValue
As part of evaluating a variable block, there is a pass made on unknown
keys setting them to the config.DefaultVariableValue sentinal value.
Previously this only took into account one level of nesting and assumed
all values were strings.

This commit now traverses the unknown keys via lists and maps and sets
unknown map keys surgically.

Fixes #7241.
2016-07-08 16:44:40 +01:00
James Nugent 088feb933f terraform: Add test case reproducing #7241
The reproduction of issue #7421 involves a list of maps being passed to
a module, where one or more of the maps has a value which is computed
(for example, from another resource). There is a failure at the point of
use (via lookup interpolation) of the computed value of the form:

```
lookup: lookup failed to find 'elb' in:
${lookup(var.services[count.index], "elb")}
```

Where 'elb' is the key of the map.
2016-07-08 16:43:42 +01:00
James Nugent 1401a52a5c Merge pull request #7493 from hashicorp/b-pass-map-to-module
terraform: allow literal maps to be passed to modules
2016-07-08 11:50:29 +01:00
James Bardin 21e2173e0a Fix nested module "unknown variable" during dest (#7496)
* Fix nested module "unknown variable" during dstry

During a destroy with nested modules, accessing a variable between them
causes an "unknown variable accessed" during destroy.
2016-07-06 11:22:41 -04:00
Paul Hinze 559f14c3fa
terraform: allow literal maps to be passed to modules
Passing a literal map to a module looks like this in HCL:

    module "foo" {
      source = "./foo"
      somemap {
        somekey = "somevalue"
      }
    }

The HCL parser always wraps an extra list around the map, so we need to
remove that extra list wrapper when the parameter is indeed of type "map".

Fixes #7140
2016-07-06 09:52:32 -05:00
Paul Hinze 1a4bd24e1a
terraform: add test helper for inline config loading
In scenarios with a lot of small configs, it's tedious to fan out actual
dir trees in a test-fixtures dir. It also spreads out the context of the
test - requiring the reader fetch a bunch of scattered 3 line files in
order to understand what is being tested.

Our config loading code still only reads from disk, but in
the `helper/resource` acc test framework we work around this by writing
inline config to temp files and loading it from there. This helper is
based on that strategy.

Eventually it'd be great to be able to build up a `module.Tree` from
config directly, but this gets us the functionality today.

Example Usage:

    testModuleInline(t, map[string]string{
      "top.tf": `
        module "middle" {
          source = "./middle"
        }
      `,
      "middle/mid.tf": `
        module "bottom" {
          source = "./bottom"
          amap {
            foo = "bar"
          }
        }
      `,
      "middle/bottom/bot.tf": `
        variable "amap" {
          type = "map"
        }
      `,
    }),
2016-07-06 09:12:19 -05:00
Paul Hinze 4a1b36ac0d
core: rerun resource validation before plan and apply
In #7170 we found two scenarios where the type checking done during the
`context.Validate()` graph walk was circumvented, and the subsequent
assumption of type safety in the provider's `Diff()` implementation
caused panics.

Both scenarios have to do with interpolations that reference Computed
values. The sentinel we use to indicate that a value is Computed does
not carry any type information with it yet.

That means that an incorrect reference to a list or a map in a string
attribute can "sneak through" validation only to crop up...

 1. ...during Plan for Data Source References
 2. ...during Apply for Resource references

In order to address this, we:

 * add high-level tests for each of these two scenarios in `provider/test`
 * add context-level tests for the same two scenarios in `terraform`
   (these tests proved _really_ tricky to write!)
 * place an `EvalValidateResource` just before `EvalDiff` and `EvalApply` to
   catch these errors
 * add some plumbing to `Plan()` and `Apply()` to return validation
   errors, which were previously only generated during `Validate()`
 * wrap unit-tests around `EvalValidateResource`
 * add an `IgnoreWarnings` option to `EvalValidateResource` to prevent
   active warnings from halting execution on the second-pass validation

Eventually, we might be able to attach type information to Computed
values, which would allow for these errors to be caught earlier. For
now, this solution keeps us safe from panics and raises the proper
errors to the user.

Fixes #7170
2016-07-01 13:12:57 -05:00
Paul Hinze 40fbb8d2e8 Merge pull request #7370 from tpounds/show-tf-ver-on-state-mismatch
Show Terraform version on state version mismatch.
2016-06-29 10:48:13 -05:00
James Bardin 68010599b1 Merge pull request #7403 from hashicorp/jbardin/GH-7394
core: Don't set Modules to nil during state upgrade
2016-06-29 10:05:57 -04:00
James Bardin 1b75c51ed7 Don't nil module maps during state upgrade
The Outputs and Resources maps in the state modules are expected to be
non-nil, and initialized that way when a new module is added to the
state.  The V1->V2 upgrade was setting the maps to nil if the len == 0.
2016-06-29 09:17:25 -04:00
James Bardin 94f1899f4e increment the state serial whenever we upgrade
Always increment the state serial whenever we upgrade the state version.
This prevents possible version conflicts between local and remote state
when one has been upgraded, but the serial numbers match.
2016-06-28 16:32:36 -04:00
Trevor Pounds c4423bba17 Fix state version error message check. 2016-06-27 13:42:44 -07:00
Trevor Pounds 5932214f0d Show Terraform version on state version mismatch. 2016-06-27 11:52:43 -07:00
James Bardin 0e507e7e5e Remove computed maps from the diff Same check
Just like computed sets, computed maps may have both different values
and different cardinality after they're computed. Remove the computed
maps and the values from the compared diffs.
2016-06-27 10:04:45 -04:00
James Nugent 1f9a2b241e Merge pull request #7207 from hashicorp/b-diff-maps
core/diff: Fix attribute mismatch with tags.%
2016-06-24 15:03:36 +03:00
James Nugent cd354ed3c7 core: Use Terraform terms over HCL ones 2016-06-24 12:42:39 +01:00
James Bardin 416e875bff Output expected HCL types when evaluating config
Don't refer to Go types when an unexpected type is encountered in the
config.
2016-06-24 12:42:01 +01:00
James Nugent 2356afde84 core: Fix interpolation of unknown multi-variables
This commit test "TestContext2Input_moduleComputedOutputElement"
by ensuring that we treat a count of zero and non-reified resources
independently rather than returning an empty list for both, which
results in an interpolation failure when using the element function or
indexing.
2016-06-23 21:15:33 +01:00
James Nugent 983e4f13c6 core: Add context test for empty lists as module outputs
This test illustrates a failure which occurs during the Input walk, if
an interpolation is used with the input of a splat operation resulting
in a multi-variable.

The bug was found during use of the RC2, but does not correspond to an
open issue at present.
2016-06-23 21:15:33 +01:00
James Nugent 17f4777039 core: Fix Stringer on OutputState for types
The implementation of Stringer on OutputState previously assumed outputs
may only be strings - we now no longer cast to string, instead using the
built in formatting directives.
2016-06-23 21:15:33 +01:00
James Nugent d60365af02 core: Correctly ensure that State() is a copy
The previous mechanism for testing state threw away the mutation made on
the state by calling State() twice - this commit corrects the test to
match the comment.

In addition, we replace the custom copying logic with the copystructure
library to simplify the code.
2016-06-22 17:21:27 +03:00