Commit Graph

1596 Commits

Author SHA1 Message Date
Clint 7a6aa1292f fix typo
fix typo
2016-12-02 16:23:07 -06:00
James Bardin f833958505 Merge pull request #10502 from hashicorp/jbardin/validate-crash
Make sure that a Context.diff is never nil
2016-12-02 15:15:49 -05:00
Mitchell Hashimoto 8ffe25ef9b release: clean up after v0.8.0-rc2 2016-12-02 20:09:28 +00:00
Mitchell Hashimoto a6ac5bed69
v0.8.0-rc2 2016-12-02 20:05:22 +00:00
James Bardin 6a8df0cbe2 Make sure that a Context.diff is never nil
The context and diff passed along during a walk, and the diff is assumed
to be valid.
2016-12-02 11:52:18 -05:00
Mitchell Hashimoto cfb440ea60
terraform: don't prune state on init()
Init should only _add_ values, not remove them.

During graph execution, there are steps that expect that a state isn't
being actively pruned out from under it. Namely: writing deposed states.

Writing deposed states has no way to handle if a state changes
underneath it because the only way to uniquely identify a deposed state
is its index in the deposed array. When destroying deposed resources, we
set the value to `<nil>`. If the array is pruned before the next deposed
destroy, then the indexes have changed, and this can cause a crash.

This PR does the following (with more details below):

  * `init()` no longer prunes.

  * `ReadState()` always prunes before returning. I can't think of a
    scenario where this is unsafe since generally we can always START
    from a pruned state, its just causing problems to prune
    mid-execution.

  * Exported State APIs updated to be robust against nil ModuleStates.

Instead, I think we should adopt the following semantics for init/prune
in our structures that support it (Diff, for example). By having
consistent semantics around these functions, we can avoid this in the
future and have set expectations working with them.

  * `init()` (in anything) will only ever be additive, and won't change
    ordering or existing values. It won't remove values.

  * `prune()` is destructive, expectedly.

  * Functions on a structure must not assume a pruned structure 100% of
    the time. They must be robust to handle nils. This is especially
    important because in many cases values such as `Modules` in state
    are exported so end users can simply modify them outside of the
    exported APIs.

This PR may expose us to unknown crashes but I've tried to cover our
cases in exposed APIs by checking for nil.
2016-12-02 11:48:34 -05:00
Mitchell Hashimoto 08a56304bb Merge pull request #10455 from hashicorp/b-non-cbd-promote
terraform: when promoting non-CBD to CBD, mark the config as such
2016-12-02 09:51:27 -05:00
Mitchell Hashimoto 95239a7fe6
terraform: when promoting non-CBD to CBD, mark the config as such
This brings the change for the  new graph. See #10455
2016-12-02 09:46:42 -05:00
Mitchell Hashimoto f3a62c694d
terraform: when promoting non-CBD to CBD, mark the config as such
Fixes #10439

When a CBD resource depends on a non-CBD resource, the non-CBD resource
is auto-promoted to CBD. This was done in
cf3a259. This PR makes it so that we
also set the config CBD to true. This causes the proper runtime
execution behavior to occur where we depose state and so on.

So in addition to simple graph edge tricks we also treat the non-CBD
resources as CBD resources.
2016-12-02 09:46:04 -05:00
Mitchell Hashimoto a2f3259e51 Merge pull request #10404 from hashicorp/b-plan-deposed
terraform: diff shows pure deposed destroy
2016-11-30 16:57:44 -08:00
Mitchell Hashimoto 2f8bf5b7ec
terraform: add variables to Interpolator value
Fixes #10412

The context wasn't properly adding variable values to the Interpolator
instance which made it so that the `console` command couldn't access
variables set via tfvars and the CLI.

This also adds better test coverage in command itself for this.
2016-11-30 11:56:31 -08:00
Mitchell Hashimoto bd1ef07a3c Merge pull request #10416 from hashicorp/b-deposed-order
terraform: Destroy node should only include deposed for specific index
2016-11-29 09:40:44 -08:00
James Bardin 7677bd94ed Merge pull request #10325 from hashicorp/jbardin/GH-10187
Fix some cases for nested maps and lists
2016-11-29 12:24:53 -05:00
Mitchell Hashimoto 3b2282ca57
terraform: Destroy node should only include deposed for specific index
Fixes #10338

The destruction step for a resource was included the deposed resources
for _all_ resources with that name (ignoring the "index"). For example:
`aws_instance.foo.0` was including destroying deposed for
`aws_instance.foo.1`.

This changes the config to the deposed transformer to properly include
that index.

This change includes a larger change of changing `stateId` to include
the index. This affected more parts but was ultimately the issue in
question.
2016-11-29 09:16:18 -08:00
Mitchell Hashimoto 80457b689c
terraform: do the deposed check within EvalDiff
There is never any reason to separate the two.
2016-11-28 14:34:24 -08:00
Mitchell Hashimoto 41c56ad002
terraform: new apply graph understands destroying deposed only 2016-11-28 14:34:24 -08:00
Mitchell Hashimoto 6ee3a08799
terraform: deposed shows up in plan, tests 2016-11-28 14:32:42 -08:00
Mitchell Hashimoto 3bf93501a1
terraform: test applying tainted + deposed (passes)
This is added just trying to reproduce a crash I saw. It passes so
adding it to the master tests.
2016-11-28 14:29:38 -08:00
James Bardin 16597d4a55 Nested lists and maps fail in GetRaw
When referencing a list of maps variable from within a resource, only
the first list element is included the plan. This is because GetRaw
can't access the interpolated values. Add some tests to document this
behavior for both Get and GetRaw.
2016-11-28 09:04:12 -05:00
Mitchell Hashimoto 1ddc242271 release: clean up after v0.8.0-rc1 2016-11-23 18:42:12 +00:00
Mitchell Hashimoto aac47ecf84
v0.8.0-rc1 2016-11-23 18:35:39 +00:00
Mitchell Hashimoto 28d933f6dd
nitpicks for #10310 2016-11-23 09:40:11 -08:00
Mitchell Hashimoto c15754c365 Merge pull request #10310 from spangenberg/custom-import-provider
Implements import with specified provider
2016-11-23 09:37:04 -08:00
Mitchell Hashimoto f50c7acf95
terraform: record dependency to self (other index)
Fixes #10313

The new graph wasn't properly recording resource dependencies to a
specific index of itself. For example: `foo.bar.2` depending on
`foo.bar.0` wasn't shown in the state when it should've been.

This adds a test to verify this and fixes it.
2016-11-23 09:25:20 -08:00
Daniel Spangenberg 804a5bd3c5 Implements import with specified provider
This allows the import with a specified provider.
So far it was not possible to get resources imported from a different provider
than the default.
2016-11-23 11:58:58 +01:00
James Bardin 47b66a28b9 Merge pull request #10279 from hashicorp/jbardin/GH-9996
Set proper Mode when moving a data source in state
2016-11-22 08:49:25 -05:00
Mitchell Hashimoto f35d02cbee
terraform: test for alias inheritance [GH-4789] 2016-11-21 21:51:07 -08:00
Mitchell Hashimoto 71a1e215d9
terraform: add more Same test cases to cover #9171 2016-11-21 17:31:47 -08:00
James Bardin 705527e6fe Set proper Mode when moving a data source in state
ResourceAddr.Mode wasn't properly set when moving a module, so data
sources would lose the "data." prefix when their module was moved within
the State.
2016-11-21 18:26:29 -05:00
Mitchell Hashimoto b6687aa287
terraform: write lock on post state updates
Found race here: https://travis-ci.org/hashicorp/terraform/builds/177814212

Since WriteState calls `prune` and `init`, we're actually modifying the
state structure so we need a full write lock to perform this operation.
2016-11-21 15:21:35 -08:00
James Bardin c908f3ceae convert TestStateAdd to subtests 2016-11-21 18:13:15 -05:00
James Bardin 91378d0499 Merge pull request #10233 from hashicorp/jbardin/GH-10229
An empty module in state can panic
2016-11-21 17:35:33 -05:00
James Bardin e3ef8e6f8a Merge pull request #10228 from hashicorp/jbardin/map-crash
ResourceConfig.get should never return (nil, true)
2016-11-21 12:01:30 -05:00
James Bardin 8f6583c264 Add test for ResourceConfig.Get
ResourceConfig.Get could previously return (nil, true) when looking up
an interpolated map in a list because of the indexing ambiguity. Make
sure we test that a non-existent value always returns false.
2016-11-21 10:09:21 -05:00
James Bardin e045a9cc79 Merge pull request #10133 from hashicorp/jbardin/debug
DebugVisitInfo
2016-11-21 09:13:51 -05:00
James Bardin 5108182690 Merge pull request #10199 from hashicorp/jbardin/GH-10155
Catch map type errors on variable assignment
2016-11-21 09:13:16 -05:00
Mitchell Hashimoto e7d59ab245
terraform: test for interpolation escapes 2016-11-20 21:14:16 -08:00
James Bardin a5cb530571 Move the state module cleanup from init to prune
It makes for sense for this to happen in State.prune(). Also move a
redundant pruning from ResourceState.init, and make sure
ResourceState.prune is called from the parent's prune method.
2016-11-20 11:33:41 -05:00
James Bardin def55e52ca An empty module in state can panic
An empty module, or a module with an empty path can panic during graph
traversal. Make sure we clear these out when reading and writing the
state.
2016-11-18 17:59:07 -05:00
James Bardin 68ba2d6ff0 ResourceConfig.get should never return (nil, true)
Fixes a case where ResourceConfig.get inadvertently returns a nil value.

Add an integration test where assigning a map to a list via
interpolation would panic.
2016-11-18 16:24:40 -05:00
James Bardin e331f05870 Return an error for setting a non-map to a map
Setting variables happens before context validation, so it's possible
that the user could be trying to set an incorrect variable type to a
map. Return a useful error rather than panicking.
2016-11-17 11:10:43 -05:00
James Bardin 8f6811da0c Add failing test for GH-10155
Overriding a map variable with the incorrect type panics
2016-11-16 18:20:59 -05:00
Mitchell Hashimoto 06b95b3c00 release: clean up after v0.8.0-beta2 2016-11-16 17:14:31 +00:00
Mitchell Hashimoto 7e4385ea2f v0.8.0-beta2 2016-11-16 17:13:31 +00:00
James Bardin 3df3b99276 Make sure each GraphBuilder has a Name
Ensure that each instance of BasucGraphBuilder gets a name corresponding
to the Builder which created it. This allows us to differentiate the
graphs in the logs.
2016-11-15 16:40:10 -05:00
Mitchell Hashimoto b72ef90c2f Revert "[WIP] core: Log diff mismatch using spew instead of %#v" 2016-11-15 11:53:28 -08:00
Mitchell Hashimoto b20f43834b Merge pull request #9118 from hashicorp/spew-diff-mismatch
[WIP] core: Log diff mismatch using spew instead of %#v
2016-11-15 11:53:19 -08:00
Mitchell Hashimoto 55ef93f0f9
terraform: Diff.Same should understand that Destroy might go false 2016-11-15 11:26:42 -08:00
Mitchell Hashimoto c6fd938fb8
terraform: EvalInstanceInfo on data sources in new graph
This doesn't cause any practical issues as far as I'm aware (couldn't
get any test to fail), but caused shadow errors since it wasn't matching
the prior behavior.
2016-11-15 09:02:10 -08:00
Mitchell Hashimoto b6f5eb6371 Merge pull request #10134 from hashicorp/b-shadow-close
helper/shadow: Close for auto-closing all values
2016-11-15 08:54:42 -08:00