Commit Graph

1771 Commits

Author SHA1 Message Date
Mitchell Hashimoto 4e4d51e6ba
terraform: remove old orphan transform 2017-01-26 19:36:02 -08:00
Mitchell Hashimoto 9426b71a5f
terraform: remove noop transformer 2017-01-26 19:32:49 -08:00
Mitchell Hashimoto e8eb0bd92f
terraform: delete proxy transformer 2017-01-26 19:31:32 -08:00
Mitchell Hashimoto ca0550e7eb
terraform: delete old module destroy transform 2017-01-26 19:30:27 -08:00
Mitchell Hashimoto 13e27c8b8f
terraform: delete old unused transforms 2017-01-26 19:29:15 -08:00
Mitchell Hashimoto 301cf60821
terraform: delete some flatten stuff 2017-01-26 18:10:07 -08:00
Mitchell Hashimoto 114315d502
terraform: delete legacy outputs 2017-01-26 18:09:07 -08:00
Mitchell Hashimoto be56ebf770
terraform: remove so much destroy transform 2017-01-26 18:00:47 -08:00
Mitchell Hashimoto b1b0e30f5a
terraform: remove old CBD transformer 2017-01-26 17:58:24 -08:00
Mitchell Hashimoto 09242fab09
terraform: remove legacy graph builder 2017-01-26 15:18:42 -08:00
Mitchell Hashimoto 83cc54bfbe
updated generate output 2017-01-26 15:11:47 -08:00
Mitchell Hashimoto a8f64cbcee
terraform: make sure Stop blocks until full completion 2017-01-26 15:10:30 -08:00
Mitchell Hashimoto 142df657c3
provisioners/remote-exec: listen to Stop 2017-01-26 15:10:30 -08:00
Mitchell Hashimoto f8c7b639c9
terraform: switch to Context for stop, Stoppable provisioners
This switches to the Go "context" package for cancellation and threads
the context through all the way to evaluation to allow behavior based on
stopping deep within graph execution.

This also adds the Stop API to provisioners so they can quickly exit
when stop is called.
2017-01-26 15:03:27 -08:00
Mitchell Hashimoto 523801dcc2
terraform: support backends in the state 2017-01-26 14:33:49 -08:00
Mitchell Hashimoto b35b263015 Merge pull request #11329 from hashicorp/f-destroy-prov
Destroy Provisioners
2017-01-26 14:32:21 -08:00
Mitchell Hashimoto 0b0114c9bf Merge pull request #11426 from hashicorp/f-new-graph
core: Refresh, Validate, Input on new graph builders
2017-01-26 14:31:03 -08:00
Radek Simko 0bafea87bb release: clean up after v0.8.5 2017-01-26 16:18:34 +00:00
Radek Simko b4d477660b
v0.8.5 2017-01-26 16:01:59 +00:00
Mitchell Hashimoto ae6bf241ec
terraform: validate self references 2017-01-25 21:00:45 -08:00
Mitchell Hashimoto 4a9cafcd67
terraform: expand count on resources during validation 2017-01-25 12:39:08 -08:00
Mitchell Hashimoto 86cbcff962
terraform: fixup a merge issue
We forgot to wrap some changes from the old branch into the new style
2017-01-25 12:32:09 -08:00
Mitchell Hashimoto 1427075005
terraform: wip moving validation to new graph 2017-01-25 12:28:07 -08:00
Mitchell Hashimoto 66f6f70cdb
terraform: input graph 2017-01-25 12:28:07 -08:00
Mitchell Hashimoto b2fb3b1d0f
terraform: import graph should setup parent refs to providers
Fixes #11212

The import graph builder was missing the transform to setup links to
parent providers, so provider inheritance didn't work properly. This
adds that.

This also removes the `PruneProviderTransform` since that has no value
in this graph since we'll never add an unused provider.
2017-01-24 15:36:45 -08:00
Mitchell Hashimoto 290ad37489
terraform: test case for #11282 2017-01-24 12:56:13 -08:00
Mitchell Hashimoto 7c014b84b6
terraform: handle count fields for data sources 2017-01-22 16:05:10 -08:00
Mitchell Hashimoto 38286fe491
terraform: Refresh supports new data sources 2017-01-22 13:00:01 -08:00
Mitchell Hashimoto 9c16489887
terraform: ConfigTransformer has Unique and mode filters 2017-01-22 12:58:18 -08:00
Mitchell Hashimoto d0b7a4a072
terraform: StateFilter handles cases where ResourceState has no type
This was possible with test fixtures but it is also conceiably possible
with older states or corrupted states. We can also extract the type from
the key so we do that now so that StateFilter is more robust.
2017-01-21 10:24:03 -08:00
Mitchell Hashimoto 2055885a0f
website: add destroy provisioners to getting started 2017-01-21 08:31:18 -08:00
Mitchell Hashimoto a50003d9f6
terraform: fix compilation by complying with interface 2017-01-20 20:45:06 -08:00
Mitchell Hashimoto d3df7874d5
terraform: introduce EvalApplyPre so that PreApply is called even for
destroy provisioners.
2017-01-20 20:36:53 -08:00
Mitchell Hashimoto f40fdde708
terraform: PostProvision hook gets the error from the provision step 2017-01-20 20:21:12 -08:00
Mitchell Hashimoto b56ee1a169
terraform: test on_failure with non-destroy provisioners 2017-01-20 20:05:28 -08:00
Mitchell Hashimoto 4a8c2d0958
terraform: on_failure for provisioners 2017-01-20 19:55:32 -08:00
Mitchell Hashimoto 85cb3a16b0
terraform: on destroy prov failure, don't taint and preserve state 2017-01-20 18:26:41 -08:00
Mitchell Hashimoto e9f6c9c429
terraform: run destroy provisioners on destroy 2017-01-20 18:07:51 -08:00
James Bardin 89259a1b00 Fix the removal of empty containers from a flatmap
Removal of empty nested containers from a flatmap would sometimes fail a
sanity check when removed in the wrong order. This would only fail
sometimes due to map iteration. There was also an off-by-one error in
the prefix check which could match the incorrect keys.
2017-01-20 16:23:10 -05:00
James Bardin 2820845f8c Remove 0 counts from flatmap during MergeDiff
When a InstanceState is merged with an InstanceDiff, any maps arrays or
sets that no longer exist are shown as empty with a count of 0. If these
are left in the flatmap structure, they will cause errors during
expansion because their existing in the map affects the counts for
parent structures.
2017-01-17 15:49:50 -05:00
clint f895f93769 release: clean up after v0.8.4 2017-01-11 17:21:31 +00:00
clint a791ff09b2
v0.8.4 2017-01-11 17:03:56 +00:00
stack72 288996f69c release: clean up after v0.8.3 2017-01-10 09:10:37 +00:00
stack72 b845cb7093
v0.8.3 2017-01-10 09:03:50 +00:00
Andrew Garrett 497010ce42 Fix string representation of sets during interpolation
The change in #10787 used flatmap.Expand to fix interpolation of nested
maps, but it broke interpolation of sets such that their elements were
not represented. For example, the expected string representation of a
splatted aws_network_interface.whatever.*.private_ips should be:

```
[{Variable (TypeList): [{Variable (TypeString): 10.41.17.25}]} {Variable (TypeList): [{Variable (TypeString): 10.41.22.236}]}]
```

But instead it became:

```
[{Variable (TypeList): [{Variable (TypeString): }]} {Variable (TypeList): [{Variable (TypeString): }]}]
```

This is because the expandArray function of expand.go treated arrays to
exclusively be lists, e.g. not sets. The old code used to match for
numeric keys, so it would work for sets, whereas expandArray just
assumed keys started at 0 and ascended incrementally. Remember that
sets' keys are numeric, but since they are hashes, they can be any
integer. The result of assuming that the keys start at 0 led to the
recursive call to flatmap.Expand not matching any keys of the set, and
returning nil, which is why the above example has nothing where the IP
addresses used to be.

So we bring back that matching behavior, but we move it to expandArray
instead. We've modified it to not reconstruct the data structures like
it used to when it was in the Interpolator, and to use the standard int
sorter rather than implementing a custom sorter since a custom one is no
longer necessary thanks to the use of flatmap.Expand.

Fixes #10908, and restores the viability of the workaround I posted in #8696.

Big thanks to @jszwedko for helping me with this fix. I was able to
diagnose the problem along, but couldn't fix it without his help.
2016-12-23 23:37:03 +00:00
Mitchell Hashimoto fc6e2a1b79 release: clean up after v0.8.2 2016-12-21 20:15:38 +00:00
Mitchell Hashimoto dd2c6da4f6
v0.8.2 2016-12-21 20:03:36 +00:00
James Bardin 084670c241 Use flatmap.Expand to extract interpolated values
Now that flatmap.Expand will properly expand nested maps, we can use
that to extract any lists and maps when interpolating.
2016-12-16 10:36:27 -05:00
James Bardin ec2550dea5 Sort interpolated lists by index
Interpolated lists should be sorted by index number, rather than
lexicographic key order.
2016-12-15 16:45:59 -05:00
James Bardin 61982be9c6 failing test with wrong interpolated list order
The plan diffs for aws_instance.a and aws_instance.b should be
identical.
2016-12-15 13:23:50 -05:00
James Bardin d026745823 Allow test fixtures with non-string attributes
The testDiffFn was only only allowing string values for attributes
2016-12-15 12:03:17 -05:00
Mitchell Hashimoto 9853935876 release: clean up after v0.8.1 2016-12-15 06:14:59 +00:00
Mitchell Hashimoto a54c3478b4
v0.8.1 2016-12-15 06:10:22 +00:00
Mitchell Hashimoto 817a593280
terraform: destroy edges should take into account module variables
Fixes #10729

Destruction ordering wasn't taking into account ordering implied through
variables across module boundaries.

This is because to build the destruction ordering we create a
non-destruction graph to determine the _creation_ ordering (to properly
flip edges). This creation graph we create wasn't including module
variables. This PR adds that transform to the graph.
2016-12-14 21:48:09 -08:00
Mitchell Hashimoto 89f7e3b79f
terraform: add module vars after providers to see references
Fixes #10711

The `ModuleVariablesTransformer` only adds module variables in use. This
was missing module variables used by providers since we ran the provider
too late. This moves the transformer and adds a test for this.
2016-12-13 21:22:21 -08:00
Mitchell Hashimoto a04ce1d09a release: clean up after v0.8.0 2016-12-13 18:20:33 +00:00
Mitchell Hashimoto 142dd256ad
v0.8.0 2016-12-13 18:16:00 +00:00
Mitchell Hashimoto 5f1e6ad020
terraform: TargetsTransformer should preserve module variables
Fixes #10680

This moves TargetsTransformer to run after the transforms that add
module variables is run. This makes targeting work across modules (test
added).

This is a bug that only exists in the new graph, but was caught by a
shadow error in #10680. Tests were added to protect against regressions.
2016-12-12 20:59:14 -08:00
James Bardin ed3517858f Merge pull request #10670 from hashicorp/jbardin/GH-10603
Prevent data sources from being aplied early
2016-12-12 14:53:03 -05:00
Mitchell Hashimoto 80eab1d749 Merge pull request #10659 from hashicorp/b-multi-provider-dep
terraform: destroy resources in dependent providers first
2016-12-12 11:49:18 -08:00
Mitchell Hashimoto 8e19a8b79f Merge pull request #10657 from hashicorp/b-unknown-computed-list
terraform: allow indexing into a computed list for multi-count resources
2016-12-12 10:52:27 -08:00
James Bardin d2c6f1b57f Prevent data sources from being aplied early
If a data source has explicit dependencies in `depends_on`, we can
assume the user has added those because of a dependency not tracked
directly in the config. If there are any entries in `depends_on`, don't
apply the data source early during Refresh.
2016-12-12 10:35:10 -05:00
Mitchell Hashimoto b346ba32d1
terraform: dependent provider resources are destroyed first in modules
This extends the prior commit to also verify (and fix) that resources of
dependent providers are destroyed first even when they're within
modules.
2016-12-10 20:22:12 -05:00
Mitchell Hashimoto 14d079f914
terraform: destroy resources in dependent providers first
Fixes #4645

This is something that never worked (even in legacy graphs), but as we
push forward towards encouraging multi-provider usage especially with
things like the Vault data source, I want to make sure we have this
right for 0.8.

When you have a config like this:

```
resource "foo_type" "name" {}
provider "bar" { attr = "${foo_type.name.value}" }
resource "bar_type" "name" {}
```

Then the destruction ordering MUST be:

  1. `bar_type`
  2. `foo_type`

Since configuring the client for `bar_type` requires accessing data from
`foo_type`. Prior to this PR, these two would be done in parallel. This
properly pushes forward the dependency.

There are more cases I want to test but this is a basic case that is
fixed.
2016-12-10 20:11:24 -05:00
Mitchell Hashimoto cabcc4b5b8
terraform: allow indexing into a computed list for multi-count resources
Fixes #8695

When a list count was computed in a multi-resource access
(foo.bar.*.list), we were returning the value as empty string. I don't
actually know the histocal reasoning for this but this can't be correct:
we must return unknown.

When changing this to unknown, the new tests passed and none of the old
tests failed. This leads me further to believe that the return empty
string is probably a holdover from long ago to just avoid crashes or
UUIDs in the plan output and not actually the correct behavior.
2016-12-10 19:17:29 -05:00
Mitchell Hashimoto 808f09f01f
terraform: user friendly error when using old map overrides
Related to #8036

We have had this behavior for a _long_ time now (since 0.7.0) but it
seems people are still periodically getting bit by it. This adds an
explicit error message that explains that this kind of override isn't
allowed anymore.
2016-12-09 15:58:24 -05:00
Mitchell Hashimoto 92faace610 release: clean up after v0.8.0-rc3 2016-12-09 05:07:23 +00:00
Mitchell Hashimoto fce2be1773
v0.8.0-rc3 2016-12-09 05:01:06 +00:00
Mitchell Hashimoto d5135c0f61 Merge pull request #10522 from hashicorp/b-destroy-cbd
terraform: apply resource must depend on destroy deps
2016-12-05 21:37:09 -08:00
Mitchell Hashimoto a4ceb4a772 Merge pull request #10518 from hashicorp/b-graph
command/graph: work with new graphs
2016-12-05 21:36:33 -08:00
Martin Atkins e772b45970 "external" data source, for integrating with external programs (#8768)
* "external" provider for gluing in external logic

This provider will become a bit of glue to help people interface external
programs with Terraform without writing a full Terraform provider.

It will be nowhere near as capable as a first-class provider, but is
intended as a light-touch way to integrate some pre-existing or custom
system into Terraform.

* Unit test for the "resourceProvider" utility function

This small function determines the dependable name of a provider for
a given resource name and optional provider alias. It's simple but it's
a key part of how resource nodes get connected to provider nodes so
worth specifying the intended behavior in the form of a test.

* Allow a provider to export a resource with the provider's name

If a provider only implements one resource of each type (managed vs. data)
then it can be reasonable for the resource names to exactly match the
provider name, if the provider name is descriptive enough for the
purpose of the each resource to be obvious.

* provider/external: data source

A data source that executes a child process, expecting it to support a
particular gateway protocol, and exports its result. This can be used as
a straightforward way to retrieve data from sources that Terraform
doesn't natively support..

* website: documentation for the "external" provider
2016-12-05 17:24:57 +00:00
Mitchell Hashimoto 0e4a6e3e89
terraform: apply resource must depend on destroy deps
Fixes #10440

This updates the behavior of "apply" resources to depend on the
destroy versions of their dependencies.

We make an exception to this behavior when the "apply" resource is CBD.
This is odd and not 100% correct, but it mimics the behavior of the
legacy graphs and avoids us having to do major core work to support the
100% correct solution.

I'll explain this in examples...

Given the following configuration:

    resource "null_resource" "a" {
       count = "${var.count}"
    }

    resource "null_resource" "b" {
      triggers { key = "${join(",", null_resource.a.*.id)}" }
    }

Assume we've successfully created this configuration with count = 2.
When going from count = 2 to count = 1, `null_resource.b` should wait
for `null_resource.a.1` to destroy.

If it doesn't, then it is a race: depending when we interpolate the
`triggers.key` attribute of `null_resource.b`, we may get 1 value or 2.
If `null_resource.a.1` is destroyed, we'll get 1. Otherwise, we'll get
2. This was the root cause of #10440

In the legacy graphs, `null_resource.b` would depend on the destruction
of any `null_resource.a` (orphans, tainted, anything!). This would
ensure proper ordering. We mimic that behavior here.

The difference is CBD. If `null_resource.b` has CBD enabled, then the
ordering **in the legacy graph** becomes:

  1. null_resource.b (create)
  2. null_resource.b (destroy)
  3. null_resource.a (destroy)

In this case, the update would always have 2 values for `triggers.key`,
even though we were destroying a resource later! This scenario required
two `terraform apply` operations.

This is what the CBD check is for in this PR. We do this to mimic the
behavior of the legacy graph.

The correct solution to do one day is to allow splat references
(`null_resource.a.*.id`) to happen in parallel and only read up to to
the `count` amount in the state. This requires some fairly significant
work close to the 0.8 release date, so we can defer this to later and
adopt the 0.7.x behavior for now.
2016-12-03 23:54:29 -08:00
Mitchell Hashimoto 26ac58bc97
terraform: refactor NodeApplyableProvider to use NodeAbstractProvider
This is important so that the graph looks correct.
2016-12-03 15:27:38 -08:00
Mitchell Hashimoto fb8f2e2753
terraform: new Graph API that can return the graph for each op 2016-12-02 22:56:22 -05:00
Mitchell Hashimoto 9197422881
terraform: new graph nodes implement Dotter 2016-12-02 22:26:40 -05:00
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
Mitchell Hashimoto 6557a3de18
helper/shadow: Close for auto-closing all values
Fixes #10122

The simple fix was that we forgot to close `ReadDataApply` for the
provider. But I've always felt that this section of the code was brittle
and I wanted to put in a more robust solution. The `shadow.Close` method
uses reflection to automatically close all values.
2016-11-15 08:54:26 -08:00
James Bardin bb137f4bfb Remove the dot graphs from the debug log,
and record the walk visits in the debug information.
2016-11-15 11:11:53 -05:00
James Bardin 23de57ddf3 Merge pull request #10104 from hashicorp/jbardin/debug
DebugOperation
2016-11-15 10:16:08 -05:00
Mitchell Hashimoto aaf1ad0532 Merge pull request #10093 from hashicorp/f-console
Add `terraform console` for REPL
2016-11-14 11:53:49 -08:00
Mitchell Hashimoto 25d19ef3d0 Merge pull request #10080 from hashicorp/f-tf-version
terraform: support version requirement in configuration
2016-11-14 11:53:30 -08:00
Mitchell Hashimoto df34fa88ce Merge pull request #10076 from hashicorp/f-depend-module
terraform: depends_on can reference entire modules
2016-11-14 11:53:12 -08:00
Mitchell Hashimoto e3a01ccfd8 Merge pull request #10072 from hashicorp/f-output-depends-on
terraform: output nodes can have `depends_on`
2016-11-14 11:52:18 -08:00
Mitchell Hashimoto aa5d16be79
terraform: shadow errors with UUID() must be ignored
People with `uuid()` usage in their configurations would receive shadow
errors every time on plan because the UUID would change.

This is hacky fix but I also believe correct: if a shadow error contains
uuid() then we ignore the shadow error completely. This feels wrong but
I'll explain why it is likely right:

The "right" feeling solution is to create deterministic random output
across graph runs. This would require using math/rand and seeding it
with the same value each run. However, this alone probably won't work
due to Terraform's parallelism and potential to call uuid() in different
orders. In addition to this, you can't seed crypto/rand and its unlikely
that we'll NEVER use crypto/rand in the future even if we switched
uuid() to use math/rand.

Therefore, the solution is simple: if there is no shadow error, no
problem. If there is a shadow error and it contains uuid(), then ignore
it.
2016-11-14 10:20:26 -08:00
James Bardin de0cb17a39 Add Graph.DebugOperation
The method marks the start of a set of operations on the Graph, with
extra information optionally provided in the second paramter. This
returns a function with a single End method to mark the end of the set
in the logs.

Refactor the existing graph Begin/End Operation calls to use this single
method. Remove the *string types in the marshal structs, these are
strictly informational and don't need to differentiate empty vs unset
strings.

Add calls to DebugOperation for each step while building the graph.
2016-11-14 12:47:51 -05:00
Mitchell Hashimoto 9205d25d38 Merge pull request #10068 from hashicorp/b-destroy-edge
terraform: destroy edge must include resources through outputs
2016-11-14 09:34:36 -08:00
Mitchell Hashimoto 9e8f311df1
terraform: fix typo 2016-11-14 09:34:21 -08:00
James Bardin 7e66df3290 Rename annotation methods
Change AnnotateVertex and AnnotateEdge to VertexDebugInfo EdgeDebugInfo
to avoid confusion between debug output and future graph annotations.
2016-11-14 11:06:52 -05:00
James Bardin 916d3522b1 Write debug info using Graph.AnnotateVertex 2016-11-14 08:52:18 -05:00
James Bardin 6f9744292a Replace DebugGraphs with the Graph's methods
Now that the Graph can serialize itself, and log transformations,
there's no need for DebugGraph
2016-11-14 08:52:18 -05:00
James Bardin 6f347ebb3a Remove dot package
Unify all dot functionality in the dag package
2016-11-14 08:50:34 -05:00
James Bardin 8a5d71b0ac Implement dag.GraphNodeDotter (temporarily)
To maintain the same output, the Graph.Dot implementation needs to be
aware of GraphNodeDotter. Copy the interface into the dag package, and
make the Dot marshaler aware of which nodes implemented the interface.
This way we can remove most of the remaining dot code from terraform.
2016-11-14 08:50:34 -05:00
James Bardin 7b774f771b implement dag.Subgrapher interface
This allows the dag package to detect subgraphs, even when impelemnted
by types from other packages
2016-11-14 08:50:34 -05:00
James Bardin 28d406c040 Provider a marshaler for dag.Graph
The dot format generation was done with a mix of code from the terraform
package and the dot package. Unify the dot generation code, and it into
the dag package.

Use an intermediate structure to allow a dag.Graph to marshal itself
directly. This structure will be ablt to marshal directly to JSON, or be
translated to dot format. This was we can record more information about
the graph in the debug logs, and provide a way to translate those logged
structures to dot, which is convenient for viewing the graphs.
2016-11-14 08:50:33 -05:00
Mitchell Hashimoto a633cdf95d
terraform: improve error messages to assist REPL 2016-11-13 23:17:04 -08:00
Mitchell Hashimoto 1a8fbdc428
terraform: update interpolation to be more flexible w/o config 2016-11-13 23:17:03 -08:00
Mitchell Hashimoto 2c467e0f74
terraform: verify version requirements from configuration 2016-11-12 16:50:26 -08:00
Mitchell Hashimoto 538302f143
terraform: resources nested within a module must also be depended on
For example: A => B => C (modules). If A depends on module B, then it
also must depend on everything in module C.
2016-11-12 15:38:28 -08:00
Mitchell Hashimoto bcfec4e24e
terraform: test that dependencies in the state are enough to maintain
order
2016-11-12 15:22:48 -08:00
Mitchell Hashimoto 22dd4303bc
terraform: tests for ReferenceMap for module paths 2016-11-12 08:24:09 -08:00
Mitchell Hashimoto 0b87ef82c3
terraform: depends_on can reference entire modules 2016-11-12 08:07:45 -08:00