Commit Graph

24 Commits

Author SHA1 Message Date
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
Sander van Harmelen
d97b24e3c1
Add tests and fix last issues 2016-05-26 19:56:03 -05:00
Sander van Harmelen
8560f50cbc
Change taint behaviour to act as a normal resource
This means it’s shown correctly in a plan and takes into account any
actions that are dependant on the tainted resource and, vice verse, any
actions that the tainted resource depends on.

So this changes the behaviour from saying this resource is tainted so
just forget about it and make sure it gets deleted in the background,
to saying I want that resource to be recreated (taking into account the
existing resource and it’s place in the graph).
2016-05-26 19:55:26 -05:00
Martin Atkins
61ab8bf39a core: ResourceAddress supports data resources
The ResourceAddress struct grows a new "Mode" field to match with
Resource, and its parser learns to recognize the "data." prefix so it
can set that field.

Allows -target to be applied to data sources, although that is arguably
not a very useful thing to do. Other future uses of resource addressing,
like the state plumbing commands, may be better uses of this.
2016-05-14 08:26:36 -07:00
Paul Hinze
8223e606df
terraform: add debug logging to Noop impls
This sort of output is needed to debug these codepaths anyways, so I
figured might as well leave it in.
2016-05-10 15:58:46 -05:00
Paul Hinze
fe210e6da4
core: Fix interp error msgs on module vars during destroy
Wow this one was tricky!

This bug presents itself only when using planfiles, because when doing a
straight `terraform apply` the interpolations are left in place from the
Plan graph walk and paper over the issue. (This detail is what made it
so hard to reproduce initially.)

Basically, graph nodes for module variables are visited during the apply
walk and attempt to interpolate. During a destroy walk, no attributes
are interpolated from resource nodes, so these interpolations fail.

This scenario is supposed to be handled by the `PruneNoopTransformer` -
in fact it's described as the example use case in the comment above it!

So the bug had to do with the actual behavor of the Noop transformer.
The resource nodes were not properly reporting themselves as Noops
during a destroy, so they were being left in the graph.

This in turn triggered the module variable nodes to see that they had
another node depending on them, so they also reported that they could
not be pruned.

Therefore we had two nodes in the graph that were effectively noops but
were being visited anyways. The module variable nodes were already graph
leaves, which is why this error presented itself as just stray messages
instead of actual failure to destroy.

Fixes #5440
Fixes #5708
Fixes #4988
Fixes #3268
2016-05-09 12:18:57 -05:00
Mitchell Hashimoto
12b6776675 terraform: don't prune resource if count contains interpolations 2016-02-24 12:04:42 -05:00
Paul Hinze
3f72837f4b core: Make copies when creating destroy nodes
Fixes an interpolation race that was occurring when a tainted destroy
node and a primary destroy node both tried to interpolate a computed
count in their config. Since they were sharing a pointer to the _same_
config, depending on how the race played out one of them could catch the
config uninterpolated and would then throw a syntax error.

The `Copy()` tree implemented for this fix can probably be used
elsewhere - basically we should copy the config whenever we drop nodes
into the graph - but for now I'm just applying it to the place that
fixes this bug.

Fixes #4982 - Includes a test covering that race condition.
2016-02-09 09:25:16 -06:00
Paul Hinze
a0d3245ee3 core: Orphan addressing / targeting
Instead of trying to skip non-targeted orphans as they are added to
the graph in OrphanTransformer, remove knowledge of targeting from
OrphanTransformer and instead make the orphan resource nodes properly
addressable.

That allows us to use existing logic in TargetTransformer to filter out
the nodes appropriately. This does require adding TargetTransformer to the
list of transforms that run during DynamicExpand so that targeting can
be applied to nodes with expanded counts.

Fixes #4515
Fixes #2538
Fixes #4462
2016-01-19 17:48:44 -06:00
James Nugent
38bb9f2416 Allow targeting of orphan nodes
Fixes #3852. We now run the OrphanTransformer even when targeting, and
pass it the list of targets following resource expansion.
2015-11-13 14:33:58 -06:00
Panagiotis Moustafellos
e4845f75cc removed extra parentheses 2015-10-08 15:48:04 +03:00
Mitchell Hashimoto
696d5ef94f terraform: clarify comment 2015-07-20 08:57:35 -07:00
Mitchell Hashimoto
4d361c839e terraform: prune resources and variables 2015-07-20 08:57:34 -07:00
Paul Hinze
f97c635ef6 core: fix "provider ... couldn't be found" bug
The `CloseProviderTransformer` relies on the `ProvidedBy()` interface to
look up the proper dependency for the the graph nodes it adds. This
interface needs to yield the name of a provider, _AND_ for flattened
nodes it needs to yield the full path to a provider.

Destroy nodes did not implement this second part, which resulted in
"provider X couldn't be found" when both of these were true:

 * A module included a resource that dependend on a provider
 * The root did _NOT_ include a provider config

Implementing a proper ProvidedBy() on the flattened version of
destroy nodes solves the issue.

fixes #2581
2015-07-16 11:56:58 -05:00
Sam Boyer
b82bd0c280 Condense switch fallthroughs into expr lists 2015-05-26 21:52:36 -04:00
Paul Hinze
b0eafeb212 core: fix deadlock w/ CBD + modules
fixes #1947

Root cause was a bad edge being made by the CBD transform going from the
flattened destroy node to the unflattened create node, which was no
longer in the graph. The destroy node therefore had a dependency that
could never be satisfied, which locked up the walk.
2015-05-13 13:05:43 -05:00
Mitchell Hashimoto
6752ccfe10 terraform: only include variables in graph if count of a resource
depends
2015-05-07 10:50:56 -07:00
Paul Hinze
5d50264c31 core: module targeting
Adds the ability to target resources within modules, like:

module.mymod.aws_instance.foo

And the ability to target all resources inside a module, like:

module.mymod

Closes #1434
2015-05-05 21:58:48 -05:00
Paul Hinze
0fff7d1673 core: validate graph w/ diff during plan phase
This reimplements my prior attempt at nipping issues where a plan did
not yield the same cycle an apply did. My prior attempt was to have
ctx.Validate generate a "Verbose" worst-case graph. It turns out that
skipping PruneDestroyTransformer to generate this graph misses important
heuristics that prevent cycles by dropping destroy nodes that are
determined to be unused.

This resulted in Validate improperly failing in scenarios where these
heuristics would have broken the cycle.

We detected the problem during the work on #1781 and worked around the
issue by reverting to the non-Verbose graph in Validate.

This commit accomplishes the original goal in a better way - by
generating the full graph and checking it once Plan has calculated the
diff. This guarantees that any graph issue that would be caught by Apply
will be caught by Plan.
2015-05-05 17:24:44 -05:00
Mitchell Hashimoto
8c34e9a36a terraform: provisionedby prefixed 2015-05-05 13:04:27 -07:00
Mitchell Hashimoto
6afc14982a terraform: destroy transform must happen globally 2015-05-02 18:21:00 -07:00
Mitchell Hashimoto
542ddb881a terraform: disable destroy mode for flattened nodes 2015-05-01 18:44:07 -07:00
Mitchell Hashimoto
94e1bab65d terraform: fill in more flat interfaces 2015-05-01 15:28:41 -07:00
Mitchell Hashimoto
86d07d3b5b terraform: redo how flattening works 2015-05-01 15:18:40 -07:00