Commit Graph

1091 Commits

Author SHA1 Message Date
Mitchell Hashimoto
edd05f2aa2 terraform: fix some test failures 2015-07-19 14:14:05 -07:00
Mitchell Hashimoto
61d275f475 terraform: get nested oprhans in the transform 2015-07-19 13:53:31 -07:00
Mitchell Hashimoto
96a04c16f6 terraform: state ModuleOrphans should return grandchild orphans 2015-07-19 13:41:57 -07:00
Mitchell Hashimoto
2ee46eda94 test case 2015-07-17 10:58:47 -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
Paul Hinze
ff45f6451d core: split context tests
The context_test file has gotten pretty unruly. Let's split it up into
a few files so we can be nicer to our editors and our own sanity.

Definitely lots more we can do to clean up, but with changes like this
I'd rather do small, focused, clear steps instead of one big "cleaned up
lots of stuff" PR.
2015-07-10 14:08:49 -06:00
Sander van Harmelen
4a8ef78d33 Fixes #2676 by prefixing all Windows commands
By prefixing them with `cmd /c` it will work with both `winner` and
`ssh` connection types.

This PR also reverts some bad stringer changes made in PR #2673
2015-07-10 12:56:27 +02:00
Sander van Harmelen
97fd4f5b7d Tweaking the tests 2015-07-09 21:29:27 +02:00
Paul Hinze
5c38456b05 core: don't prompt for variables with defaults
In `helper/schema` we already makes a distinction between `Default`
which is always applied and `InputDefault` which is displayed to the
user for an empty field.

But for variables we just have `Default` which is treated like
`InputDefault`. This changes it to _not_ prompt the user for a value
when the variable declaration includes a default.

Treating this as a UX bugfix and the "don't prompt for variables w/
defaults set" behavior as the originally expected behavior we were
failing to honor.

Added an already-passing test to verify and cover the `helper/schema`
behavior.

Perhaps down the road we can add a `input_default` attribute to
variables to allow similar behavior to `helper/schema` in variables, but
for now just sticking with the fix.

Fixes #2592
2015-07-02 10:40:30 -05:00
Paul Hinze
3d81d83d01 release: clean up after 0.6.0 2015-06-30 17:39:32 -05:00
Paul Hinze
e40127fda6 v0.6.0 2015-06-30 19:57:29 +00:00
Paul Hinze
6bbf61ae6e Merge pull request #2555 from hashicorp/b-target-after-flatten
core: move targets transform after flatten
2015-06-29 13:34:52 -05:00
Paul Hinze
cf432b3ceb core: move targets transform after flatten
Allows target dependencies to be properly calculated across module
boundaries, fixing scenarios where a target depends on something inside
a module, but the contents of the module are not included in the
targeted resources.

fixes #1858
2015-06-29 13:19:37 -05:00
Paul Hinze
184edbefcd core: remove now-unused flatten impls of close nodes
/cc @mitchellh
2015-06-29 12:46:24 -05:00
Paul Hinze
557b299c4b core: move close transforms after flatten and destroy transforms
fixes destroy-related failures introduced by the close transforms
2015-06-29 12:46:18 -05:00
Mitchell Hashimoto
d6f7261190 terraform: provider mock should close itself to find bugs 2015-06-29 10:33:37 -07:00
Paul Hinze
00a177cd99 provider/aws: add test for provider aliases
Not sure if this test has value /cc @mitchellh (who requested one be
added) to see what I might be missing here.

refs #2495
2015-06-29 11:35:02 -05:00
Paul Hinze
2d6a8c1f39 core: fix provider/close provider race when targeting
When targeting prunes out all the resource nodes between a provider and
its close node, there was no dependency to ensure the close happened
after the configure. Needed to add an explicit dependency from the close
to the provider.

This tweak highlighted the fact that CloseProviderTransformer needed to
happen after DisableProviderTransformer, since
DisableProviderTransformer inspects up-edges to decide what to disable,
and CloseProviderTransformer adds an up-edge.

fixes #2495
2015-06-29 11:22:51 -05:00
Paul Hinze
2626c179a5 core: improve debug logging when targeting 2015-06-26 14:04:58 -05:00
Mitchell Hashimoto
51a7e05f8a terraform: all providers for ProvidedBy() should be added 2015-06-26 12:00:02 -07:00
Mitchell Hashimoto
7daf13487f Merge pull request #2506 from hashicorp/b-orphan-hook
terraform: orphans should call post-apply hook [GH-1938]
2015-06-26 08:19:16 -07:00
Paul Hinze
a81cad3672 Merge pull request #2504 from hashicorp/f-string-list
core: Change string list representation so we can distinguish empty, single element lists
2015-06-26 08:41:38 -05:00
Mitchell Hashimoto
8ebdc1e786 terraform: orphans should call post-apply hook [GH-1938] 2015-06-25 20:11:29 -07:00
Mitchell Hashimoto
a3a2698e56 Merge pull request #2479 from hashicorp/b-validate-fail-early
terraform: fail early if module validation fails
2015-06-25 17:50:35 -07:00
Paul Hinze
e88aeede9b core: allow distinguishing between empty lists and strings
Had to handle a lot of implicit leaning on a few properties of the old
representation:

 * Old representation allowed plain strings to be treated as lists
   without problem (i.e. shoved into strings.Split), now strings need to
   be checked whether they are a list before they are treated as one
   (i.e. shoved into StringList(s).Slice()).
 * Tested behavior of 0 and 1 length lists in formatlist() was a side
   effect of the representation. Needs to be special cased now to
   maintain the behavior.
 * Found a pretty old context test failure that was wrong in several
   different ways. It's covered by TestContext2Apply_multiVar so I
   removed it.
2015-06-25 18:53:35 -05: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
c79a661ce1 Merge branch 'b-provider-alias-module' 2015-06-25 08:54:56 -07:00
Mitchell Hashimoto
632cc92897 Merge pull request #2476 from hashicorp/b-orphan-provider-inherit
terraform: module orphans providers should inherit config
2015-06-25 08:50:49 -07:00
Mitchell Hashimoto
ced4701a8c terraform: remove test that was weirdly passing without error 2015-06-24 22:51:29 -07:00
Mitchell Hashimoto
785defc870 terraform: fail early if module validation fails 2015-06-24 22:43:55 -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
29eadb8194 terraform: missing provider should add missing aliases [GH-2023] 2015-06-24 20:58:52 -07:00
Mitchell Hashimoto
afe5ec6e29 terraform: module orphans providers should inherit config 2015-06-24 17:48:31 -07:00
Paul Hinze
38efe4cb80 dot: only draw provider close on terraform greph -verbose 2015-06-24 17:36:45 -05:00
Mitchell Hashimoto
148a84cfc3 Merge pull request #2453 from hashicorp/b-orphan-deps
terraform: orphan dependencies should be inverted
2015-06-24 10:31:43 -07:00
Mitchell Hashimoto
c144491f6f Merge pull request #2457 from hashicorp/b-provider-computed
Computed provider variables properly validate
2015-06-24 10:14:35 -07:00
Mitchell Hashimoto
d0519f226d terraform: provider input should be scoped by path
The provider input before wasn't scoped by path, which caused
non-descendant parts of the graph to grab the configuration of another
sub-tree. The result is that you'd often get copied provider
configurations across the module barriers.

See GH-2024
2015-06-24 09:34:21 -07:00
Mitchell Hashimoto
1e739d1237 terraform: validate step should still set parent config for inheritence 2015-06-23 22:18:57 -07:00
Mitchell Hashimoto
772fab3609 terraform: don't config provider on validate 2015-06-23 22:14:54 -07:00
Mitchell Hashimoto
8daa459e57 terraform: tests to check behavior of computed provider configs 2015-06-23 22:02:56 -07:00
Mitchell Hashimoto
7031cb145c terraform: orphan dependencies should be inverted 2015-06-23 20:41:02 -07:00
Mitchell Hashimoto
74386655a5 terraform: test for reducing count and using splats 2015-06-23 18:25:08 -07:00
Sander van Harmelen
783fd57ec2 Merge pull request #2435 from svanharmelen/f-add-loadjson
core: add a function to load JSON directly
2015-06-23 22:38:13 +02:00
Sander van Harmelen
01a9ceeed4 Merge pull request #2406 from svanharmelen/b-close-providers-provisioners
core: close provider/provisioner connections when not used anymore
2015-06-23 22:37:10 +02:00
Sander van Harmelen
110cf8b3d4 A close provider should not be an origin node
Removed the `DotOrigin()` func after review of the PR. With this change
the PR is up-to-spec to be merged (as just discussed with Paul in IRC).
2015-06-23 22:31:44 +02:00
Sander van Harmelen
c62370f9e9 Add a function to load JSON directly
Without this 12 line function it’s impossible to use any of the
Terraform code without the need for having the files on disk. As more
and more people are using (parts of) Terraform in other software, this
seems to be a very welcome addition. It has no negative impact on
Terraform itself whatsoever (the function is never called), but it
opens up a lot of other use cases.

Next to the single new function, I renamed the existing function (and
related tests) to better reflect what the function does. So now there
is a `LoadDir` function which calls `LoadFile` for each file, which
kind of made sense to me, especially when now adding a `LoadJSON`
function as well.

But of course if the rename is a problem, I can revert that part as
it’s not related to the added `LoadJSON` function.

Thanks!
2015-06-23 16:15:26 +02:00
Radek Simko
0fc8882e29 Expose Terraform version internally & externally 2015-06-21 12:24:42 +01:00
Sander van Harmelen
0b1dbf31a3 core: close provider/provisioner connections
Currently Terraform is leaking goroutines and with that memory. I know
strictly speaking this maybe isn’t a real concern for Terraform as it’s
mostly used as a short running command line executable.

But there are a few of us out there that are using Terraform in some
long running processes and then this starts to become a problem.

Next to that it’s of course good programming practise to clean up
resources when they're not needed anymore. So even for the standard
command line use case, this seems an improvement in resource management.

Personally I see no downsides as the primary connection to the plugin
is kept alive (the plugin is not killed) and only unused connections
that will never be used again are closed to free up any related
goroutines and memory.
2015-06-19 21:52:50 +02:00
Clint Shryock
78e7519efa Updates from go generate 2015-06-03 08:37:57 -05:00
Sam Boyer
b82bd0c280 Condense switch fallthroughs into expr lists 2015-05-26 21:52:36 -04:00
Mitchell Hashimoto
b251afb5af terraform: orphan module should flatten 2015-05-14 20:54:33 -07:00
Mitchell Hashimoto
0728e25f43 terraform: env vars are lower priority 2015-05-14 09:58:30 -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
6982ebc142 Merge pull request #1955 from ctiwald/ct/fix-vet-complaints
Fix three trivial errors 'go vet' discovered.
2015-05-13 18:24:42 -07:00
Christopher Tiwald
2252b83d9a Fix three trivial errors 'go vet' discovered. 2015-05-13 21:23:07 -04:00
Paul Hinze
842d66183b core: respect roots in CBD transform
Because CBD now runs after a RootTransformer, it's now operating on a
graph that _may_ have had a graphNodeRoot added to it (a noop node whose
only purpose is to be a root).

CBD includes a step that tells the destroy node to depend on any parents
of the create node. When one of those parents was "root", this was
causing the destroy node to depend on "root", making it cease to be an
actual root node.

Because graphNodeRoot is a singleton, the follow-up RootTransformer was
not sufficient to slap another root on top - it wasn't being seen as a
fresh node, so edges were just accumulating, and we ended up in a state
with "no roots".

refs #1903 (not sure if this will fix all the "no root found" cases, or
just the one I bumped into)
2015-05-13 17:53:42 -05: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
Paul Hinze
63241c991b core: flatten disabled providers 2015-05-13 11:50:11 -05:00
Paul Hinze
a5e4e3de59 core: flatten orphan modules 2015-05-13 11:33:29 -05:00
Paul Hinze
9c7fb87ca8 core: flatten orphan outputs
Hit the "unflattenable node" error again with these.

This fixes it.
2015-05-12 15:10:21 -05:00
Paul Hinze
0273732dec core: make orphans flattenable
Got this while playing around in a module:

> * unflattenable node: aws_security_group.internal (orphan)
> *terraform.graphNodeOrphanResource

Basically just copied implementation from
d503cc2d82
2015-05-11 22:24:11 -05:00
Mitchell Hashimoto
f86dc22caf terraform: return unknown if resource not found 2015-05-11 14:57:20 -07:00
Mitchell Hashimoto
fc084cc03e Merge pull request #1857 from hashicorp/b-multi-mod
terraform: flattening multi-level modules works
2015-05-07 13:34:35 -07:00
Mitchell Hashimoto
6d56a2ac86 terraform: comment 2015-05-07 13:10:25 -07:00
Mitchell Hashimoto
7c3e355bb0 terraform: flattening multi-level modules works 2015-05-07 13:08:59 -07:00
Mitchell Hashimoto
6752ccfe10 terraform: only include variables in graph if count of a resource
depends
2015-05-07 10:50:56 -07:00
Mitchell Hashimoto
6b2e0b938d terraform: only omit vars on full destroys 2015-05-06 20:55:14 -07:00
Mitchell Hashimoto
19b33326be terraform: don't include variables in destroy node requirements 2015-05-06 20:13:19 -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
d503cc2d82 terraform: flattenable graphNodeMissingProvisioner 2015-05-05 12:45:28 -07:00
Mitchell Hashimoto
6d4969f64c terraform: run prune destroy on validate 2015-05-05 12:11:49 -07:00
Paul Hinze
c3ce23c7b4 core: failing test for a bad module cycle
passing output of one module into input of the following module results
in a cycle
2015-05-04 18:58:29 -05:00
Mitchell Hashimoto
13f3daa3b3 terraform: update comment on interpolater stuff 2015-05-04 10:51:34 -07:00
Mitchell Hashimoto
2f3f680505 terraform: update comment 2015-05-04 10:49:34 -07:00
Mitchell Hashimoto
cc0c208364 terraform: skip outputs for destroy graphs 2015-05-02 18:28:26 -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
bbb065d1ad terraform: add edge for missing providers 2015-05-01 18:39:24 -07:00
Mitchell Hashimoto
23b6acc29d terraform: add module destroy node to graph 2015-05-01 18:26:35 -07:00
Mitchell Hashimoto
1f10dfef2d terraform: remove test 2015-05-01 18:17:49 -07:00
Mitchell Hashimoto
8f58367680 terraform: missing providers need to do dependencies 2015-05-01 18:08:06 -07:00
Mitchell Hashimoto
7fd432b076 terraform: providers in flattened graphs should depend on the parent 2015-05-01 16:41:49 -07:00
Mitchell Hashimoto
c207beda36 terraform: set variables in the proper location 2015-05-01 16:29:19 -07:00
Mitchell Hashimoto
94e1bab65d terraform: fill in more flat interfaces 2015-05-01 15:28:41 -07:00
Mitchell Hashimoto
416e7a2077 terraform: missing provider should be flattenable 2015-05-01 15:23:37 -07:00
Mitchell Hashimoto
86d07d3b5b terraform: redo how flattening works 2015-05-01 15:18:40 -07:00
Mitchell Hashimoto
f2e7f505d4 terraform: subpath context setting 2015-05-01 14:19:32 -07:00
Mitchell Hashimoto
9a54dddc85 terraform: eval for variables 2015-05-01 14:10:41 -07:00
Mitchell Hashimoto
e544e1d401 terraform: hook up the proxies 2015-05-01 11:45:42 -07:00
Mitchell Hashimoto
7d28e980a5 terraform: proxy uses custom edge 2015-05-01 11:41:01 -07:00
Mitchell Hashimoto
f24a1533f2 terraform: GraphNodeProxy 2015-05-01 11:38:36 -07:00
Mitchell Hashimoto
a0d9bc0f19 terraform: outputs connect properly 2015-05-01 11:26:58 -07:00
Mitchell Hashimoto
7e838dfae2 terraform: Graph should overrride Remove to clear lookaside 2015-05-01 11:20:57 -07:00
Mitchell Hashimoto
dd14ce9a0b terraform: test that variable deps reach out to parent graph 2015-05-01 11:09:23 -07:00
Mitchell Hashimoto
e542d6efdf terraform: test to verify config variables are variables 2015-05-01 10:56:46 -07:00
Mitchell Hashimoto
3bfef7c374 terraform: wrap variable values and prefix dependencies
(untested yet)
2015-05-01 10:56:05 -07:00
Mitchell Hashimoto
12c30feb0f terraform: start FlattenGraph impl. 2015-04-30 20:46:54 -07:00
Mitchell Hashimoto
5e767f63b9 terraform: move module to its own file 2015-04-30 19:23:52 -07:00
Mitchell Hashimoto
15ca84a682 terraform: module dependencies in graph use full name (FOR THE FUTURE) 2015-04-30 17:19:01 -07:00
Mitchell Hashimoto
90cfade626 terraform: naive flatten 2015-04-30 17:02:39 -07:00
Mitchell Hashimoto
1152ff562b terraform: add variables as graph nodes (no eval yet) 2015-04-30 16:27:20 -07:00
Paul Hinze
430e00c55c Merge pull request #1763 from hashicorp/b-fix-1699
core: fix targeting with non-word chars
2015-04-30 16:34:19 -05:00
Paul Hinze
d30d88e327 Merge pull request #1655 from hashicorp/f-build-graph-during-plan
core: validate on verbose graph to detect some cycles earlier
2015-04-30 16:08:33 -05:00
Paul Hinze
443c7e053f Merge pull request #1544 from hashicorp/b-destroy-target-provisioner
core: fix resource targeting w/ provisioners
2015-04-30 16:03:17 -05:00
Paul Hinze
9295e1eca6 core: fix targeting with non-word chars
Flips the regex strategy to capture everything that's _not_ the next
separator instead of whitelisting `\w`

fixes #1699
2015-04-30 15:49:37 -05:00
Mitchell Hashimoto
873f5a91bb terraform: EvalDeleteOutput and context test 2015-04-29 11:27:12 -07:00
Mitchell Hashimoto
2ca181d42d terraform: add output orphan transformer 2015-04-29 11:18:58 -07:00
Paul Hinze
ce49dd6080 core: graph command gets -verbose and -draw-cycles
When you specify `-verbose` you'll get the whole graph of operations,
which gives a better idea of the operations terraform performs and in
what order.

The DOT graph is now generated with a small internal library instead of
simple string building. This allows us to ensure the graph generation is
as consistent as possible, among other benefits.

We set `newrank = true` in the graph, which I've found does just as good
a job organizing things visually as manually attempting to rank the nodes
based on depth.

This also fixes `-module-depth`, which was broken post-AST refector.
Modules are now expanded into subgraphs with labels and borders. We
have yet to regain the plan graphing functionality, so I removed that
from the docs for now.

Finally, if `-draw-cycles` is added, extra colored edges will be drawn
to indicate the path of any cycles detected in the graph.

A notable implementation change included here is that
{Reverse,}DepthFirstWalk has been made deterministic. (Before it was
dependent on `map` ordering.) This turned out to be unnecessary to gain
determinism in the final DOT-level implementation, but it seemed
a desirable enough of a property that I left it in.
2015-04-27 09:23:47 -05:00
Paul Hinze
5e67657325 core: fix targeting in destroy w/ provisioners
The `TargetTransform` was dropping provisioner nodes, which caused graph
validation to fail with messages about uninitialized provisioners when a
`terraform destroy` was attempted.

This was because `destroy` flops the dependency calculation to try and
address any nodes in the graph that "depend on" the target node. But we
still need to keep the provisioner node in the graph.

Here we switch the strategy for filtering nodes to only drop
addressable, non-targeted nodes. This should prevent us from having to
whitelist nodes to keep in the future.

closes #1541
2015-04-27 08:36:54 -05:00
Paul Hinze
d4b9362518 core: validate on verbose graph to detect some cycles earlier
Most CBD-related cycles include destroy nodes, and destroy nodes were
all being pruned from the graph before staring the Validate walk.

In practice this meant that we had scenarios that would error out with
graph cycles on Apply that _seemed_ fine during Plan.

This introduces a Verbose option to the GraphBuilder that tells it to
generate a "worst-case" graph. Validate sets this to true so that cycle
errors will always trigger at this step if they're going to happen.

(This Verbose option will be exposed as a CLI flag to `terraform graph`
in a second incoming PR.)

refs #1651
2015-04-23 11:07:13 -05:00
Mitchell Hashimoto
af4396aa0d Merge pull request #1621 from hashicorp/f-envs
Set variables from env vars
2015-04-22 15:50:56 +02:00
Mitchell Hashimoto
d2011438f7 Merge pull request #1587 from hashicorp/b-count-deps
terraform: inner-count dependencies work [GH-1540]
2015-04-22 08:10:24 +02:00
Mitchell Hashimoto
5ae9ee4d27 terraform: allow TF_VAR_name to be set to set variables 2015-04-22 06:31:53 +02:00
Mitchell Hashimoto
fa934d96d0 helper/schema: FieldReaderConfig detects computed maps 2015-04-21 22:07:52 +02:00
Mitchell Hashimoto
d3689cea29 terraform: test input with multiple providers 2015-04-20 14:59:03 -07:00
Mitchell Hashimoto
de004d7183 terraform: context test for when provider is missing from state 2015-04-20 14:54:25 -07:00
Matt Good
21b0a03d70 Support for multiple providers of the same type
Adds an "alias" field to the provider which allows creating multiple instances
of a provider under different names. This provides support for configurations
such as multiple AWS providers for different regions. In each resource, the
provider can be set with the "provider" field.

(thanks to Cisco Cloud for their support)
2015-04-20 14:14:34 -07:00
Mitchell Hashimoto
7a1592ff1e terraform: don't panic on input for bad default type [GH-1344] 2015-04-18 16:31:21 -07:00
Mitchell Hashimoto
2fffec9545 terraform: inner-count dependencies work [GH-1540] 2015-04-18 15:56:43 -07:00
Paul Hinze
afe4abb637 core: add prevent_destroy lifecycle flag
When the `prevent_destroy` flag is set on a resource, any plan that
would destroy that resource instead returns an error. This has the
effect of preventing the resource from being unexpectedly destroyed by
Terraform until the flag is removed from the config.
2015-04-17 10:40:04 -05: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
Paul Hinze
6365b3af89 Merge pull request #1515 from hashicorp/b-diff-mismatch-on-instance-replacement
core: avoid diff mismatch on NewRemoved fields during -/+
2015-04-14 17:44:28 -05:00
Paul Hinze
64f0897c82 core: avoid diff mismatch on NewRemoved fields during -/+
fixes #1508

In a DESTROY/CREATE scenario, the plan diff will be run against the
state of the old instance, while the apply diff will be run against an
empty state (because the state is cleared when the destroy node does its
thing.)

For complex attributes, this can result in keys that seem to disappear
between the two diffs, when in reality everything is working just fine.

Same() needs to take into account this scenario by analyzing NewRemoved
and treating as "Same" a diff that does indeed have that key removed.
2015-04-14 17:23:30 -05:00
Mitchell Hashimoto
2934824069 terraform: remove debug 2015-04-14 13:20:23 -07:00
Mitchell Hashimoto
486cde44ec terraform: when pruning destroy, only match exact nodes, or exact counts 2015-04-14 13:17:08 -07:00
Paul Hinze
d49933b0f8 Merge pull request #1514 from hashicorp/f-dead-evaltree-cbd-code
core: remove dead code from pre-deposed refactor
2015-04-14 13:42:50 -05:00
Mitchell Hashimoto
b64fd8401c terraform: prune tainted destroys if no tainted in state [GH-1475] 2015-04-14 10:48:45 -07:00
Paul Hinze
d5f6942755 core: remove dead code from pre-deposed refactor
CBD used to "borrow" the last slot of of the Tainted list in the State,
but as of #1078 it uses its own list. This seems like just a block of
old code that didn't get cleaned up from the refactor. Deposed resources
get their own destroy nodes, so they don't have to mess with the main
destroy node.
2015-04-13 18:33:29 -05:00
Paul Hinze
d168cc1bd1 terraform: add reason to diff mismatch error
Helps with debugging those pesky "diffs did not match" errors.
2015-04-13 09:31:09 -05:00
Paul Hinze
6761424309 Merge pull request #1487 from hashicorp/b-provider-vars-inherit
terraform: fix provider config inheritance during input
2015-04-10 16:35:17 -05:00
Paul Hinze
d1b40de242 terraform: fix provider config inheritance during input
The provider config was not being properly merged across module
boundaries during the Input walk over the graph, so when a provider was
configured at the top level, resources in modules could improperly
trigger a request for input for a provider attribute that's already
defined.
2015-04-10 16:28:47 -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
b201983304 terraform: copy RawConfigs 2015-04-09 09:21:38 -07:00
Mitchell Hashimoto
eda2e0fdfc terraform: fix disable provider tests 2015-04-09 08:51:38 -07:00
Mitchell Hashimoto
bcff7e070c terraform: don't prune, but disable, inherited configs [GH-1447] 2015-04-09 08:48:08 -07:00
Mitchell Hashimoto
8a90bd08a3 terraform: test negative case for disable provider transformer 2015-04-08 21:39:56 -07:00
Mitchell Hashimoto
edc97d3afd terraform: expanded resource nodes implement graphNodeConfig 2015-04-08 21:25:17 -07:00
Mitchell Hashimoto
218f147c0c terraform: test fixture modified to not prune provider 2015-04-08 21:25:03 -07:00
Mitchell Hashimoto
36520121b1 terraform: disable providers that are only used by modules 2015-04-08 21:14:19 -07:00
Paul Hinze
816c4b475f core: [tests] fix order dependent test 2015-04-01 11:11:46 -05:00
Paul Hinze
c6300d511c core: formalize resource addressing
Only used in targets for now. The plan is to use this for interpolation
as well.

This allows us to target:

 * individual resources expanded by `count` using bracket / index notation.
 * deposed / tainted resources with an `InstanceType` field after name

Docs to follow.
2015-03-31 15:04:10 -05:00
Paul Hinze
40ebfb5ccc core: fill out context tests for targeted ops 2015-03-31 14:49:38 -05:00
Paul Hinze
97acccd3ed core: targeted operations
Add `-target=resource` flag to core operations, allowing users to
target specific resources in their infrastructure. When `-target` is
used, the operation will only apply to that resource and its
dependencies.

The calculated dependencies are different depending on whether we're
running a normal operation or a `terraform destroy`.

Generally, "dependencies" refers to ancestors: resources falling
_before_ the target in the graph, because their changes are required to
accurately act on the target.

For destroys, "dependencies" are descendents: those resources which fall
_after_ the target. These resources depend on our target, which is going
to be destroyed, so they should also be destroyed.
2015-03-31 14:49:38 -05:00
Paul Hinze
f2968b045c Merge pull request #1316 from hashicorp/b-empty-instancestate-state-migrate-crash
providers/aws: handle empty instancestate in state migration
2015-03-29 08:53:04 -05:00
Seth Vargo
1adb3fbfa0 command: when setting up state, only write back if local is newer 2015-03-26 17:16:54 -07:00
Paul Hinze
f51fb5e127 providers/aws: handle empty instancestate in state migration
fixes #1309
2015-03-26 13:07:04 -05:00
Mitchell Hashimoto
a0839da71a terraform: merge provider configs before validate [GH-1282] 2015-03-25 16:28:52 -07:00
Mitchell Hashimoto
9c6e2cdc21 terraform: make sure our serial is always higher 2015-03-25 15:40:53 -07:00
Mitchell Hashimoto
f68f285f72 terraform: test case for higher S1 serial 2015-03-25 15:39:33 -07:00
Mitchell Hashimoto
0d4c7887c5 terraform: don't increment state if one is nil 2015-03-25 15:38:24 -07:00
Mitchell Hashimoto
5e27bfc040 command/push: read name from the config 2015-03-24 13:30:23 -07:00
Mitchell Hashimoto
22087181af command/push: archive, upload 2015-03-24 13:30:22 -07:00
Mitchell Hashimoto
2dce764d75 terraform: add input mode to only ask for unset variables
This adds a new input mode for Context.Input() that will only ask for
variable values that are not set.
2015-03-24 13:30:21 -07:00
Paul Hinze
3ba8ed536b helper/schema: record schema version on apply
We were previously only recording the schema version on refresh. This
caused the state to be incorrectly written after a `terraform apply`
causing subsequent commands to run the state through an unnecessary
migration.
2015-03-18 19:08:48 -05:00
Paul Hinze
3d4b55e557 helper/schema: schema versioning & migration
Providers get a per-resource SchemaVersion integer that they can bump
when a resource's schema changes format. Each InstanceState with an
older recorded SchemaVersion than the cureent one is yielded to a
`MigrateSchema` function to be transformed such that it can be addressed
by the current version of the resource's Schema.
2015-03-06 16:26:11 -06:00
Paul Hinze
f1c9e32fa0 core: tweaks from code review 2015-03-05 10:11:14 -06:00
Paul Hinze
6e13aacefa core: [refactor] DRY up EvalWriteState nodes
Also some final comment cleanup
2015-03-04 18:22:18 -06:00
Paul Hinze
6c93fbb85d core: [refactor] store Deposed resource instances as a list
Deposed instances need to be stored as a list for certain pathological
cases where destroys fail for some reason (e.g. upstream API failure,
Terraform interrupted mid-run). Terraform needs to be able to remember
all Deposed nodes so that it can clean them up properly in subsequent
runs.

Deposed instances will now never touch the Tainted list - they're fully
managed from within their own list.

Added a "multiDepose" test case that walks through a scenario to
exercise this.
2015-03-04 12:25:59 -06:00
Paul Hinze
426f253085 core: [refactor] split WriteState EvalNodes
This is the non-DRY pass.
2015-03-04 12:25:47 -06:00
Paul Hinze
d81ec2d37e core: [refactor] pull out common ReadState behavior 2015-03-04 12:25:47 -06:00
Paul Hinze
596e891b80 core: [refactor] pull Deposed out of Tainted list 2015-03-04 12:25:47 -06:00
Mitchell Hashimoto
80c129a961 terraform: style, multiline a long line 2015-03-02 08:41:09 -08:00
Mitchell Hashimoto
4894080d87 Merge pull request #1086 from hashicorp/b-pph
terraform: catch scenario where both "foo" and "foo.0" are in state
2015-03-02 08:34:05 -08:00
Mitchell Hashimoto
11d073f7d4 terraform: test the increase from one case 2015-03-01 21:39:48 -08:00
Mitchell Hashimoto
2389251c38 terraform: catch scenario where both "foo" and "foo.0" are in state 2015-03-01 21:28:41 -08:00
Mitchell Hashimoto
865de51816 dag: do a DFS for each vertex 2015-02-27 19:37:59 -08:00
Mitchell Hashimoto
9eb7ebbddd terraform: do the transitive reduction as part of the graph builder 2015-02-27 19:23:20 -08:00
Mitchell Hashimoto
903e49162d terraform: add TransitiveReductionTransformer 2015-02-27 19:18:04 -08:00
Mitchell Hashimoto
ac6efa5e57 Merge pull request #1065 from hashicorp/f-taint
Add "taint" command
2015-02-26 23:55:20 -08:00
Paul Hinze
c03e44106f core: band-aid fix for tainted double destroy
After a lot of fun debugging with @mitchellh we finally have a diagnosis
for #1056.

I'm going to attempt to reproduce the diagnosis in prose to test out my
understanding.

----

The `DestroyTransformer` runs twice:

 * `DestroyPrimary` mode creates destroy nodes for normal resources
 * `DestroyTainted` mode creates destroy nodes for tainted resources

These destroy nodes are specializations of `GraphConfigNode`, which has
a `DynamicExpand` step.

In `DynamicExpand` we have a race condition between the normal destroy
node and the tainted destroy node for a given resource when
`CreateBeforeDestroy` is off.

The `DestroyTainted` `GraphConfigNode` must run the `TaintedTransform`
to draw out tainted nodes, since it is reponsible for destroying them
for replacement.

The `DestroyPrimary` `GraphConfigNode` _also_ runs `TaintedTransform` -
this is to catch `Deposed` nodes from CBD, which are piggy backing on
the end of the `Tainted` list.

Here's the bug: when CBD is off and you start an apply with a tainted
resource in your state, both `DestroyPrimary` and `DestroyTainted` catch
it and create their own `graphNodeTaintedResource` in their respective
subgraphs.

If parallelism is disabled, this doesn't happen because the
`DestroyPrimary` subgraph resolves completely before the
`DestroyTainted` node does its `DynamicExpand`, so the `Tainted` list
has been cleared by the time `DestroyTainted` is expanding. With
parallelism, each of these two subgraphs plays out in its own goroutine
simultaneously, and each picks up the tainted resource(s) that the apply
starts with.  So you get two `graphNodeTaintedResource` nodes, and two
destroys.

This band-aid fixes that by skipping the TaintedTransform alltogether in
the `DestroyPrimary` node if CBD is off.

A better fix will follow, which involves reworking the `Deposed` concept
so it no longer piggybacks on `Tainted`.

fixes #1056
2015-02-26 22:32:50 -06:00
Mitchell Hashimoto
4ec31ecb95 command/taint: new command 2015-02-26 10:29:23 -08:00
Mitchell Hashimoto
b3cd1bd5bc terraform: add ResourceState.Taint 2015-02-26 09:58:56 -08:00
Mitchell Hashimoto
341be226f4 terraform: test for various taint cases 2015-02-26 09:50:18 -08:00
Mitchell Hashimoto
6affc57b2d terraform: destroy node should not create 2015-02-24 22:45:47 -08:00
Mitchell Hashimoto
1fcbfcd19d Merge pull request #1037 from hashicorp/f-continuous-state
Continuous state persistance
2015-02-24 17:34:19 -08:00
Mitchell Hashimoto
ac167c3082 terraform: test post state update is called 2015-02-23 22:10:31 -08:00
Mitchell Hashimoto
57f7507ebd terraform: more state tests, fix a bug 2015-02-23 21:43:54 -08:00
Mitchell Hashimoto
f3af221866 terraform: make DeepCopy public 2015-02-23 21:32:27 -08:00
Mitchell Hashimoto
c2bf600603 state: only change serial if changed 2015-02-23 21:26:33 -08:00
Mitchell Hashimoto
821536b1e9 terraform: call the EvalUpdateStateHook strategically 2015-02-23 19:14:16 -08:00
Mitchell Hashimoto
429711b938 terraform: PostStateUpdate hook and EvalUpdateStateHook 2015-02-23 19:09:48 -08:00
Mitchell Hashimoto
3f9dafc5f6 Merge pull request #1033 from hashicorp/f-self
core: Self Variables
2015-02-23 15:19:48 -08:00
Mitchell Hashimoto
330364f668 terraform: State.IsEmpty 2015-02-23 15:13:54 -08:00
Mitchell Hashimoto
6cd5c894e8 terraform: State.IsRemote 2015-02-23 15:13:54 -08:00
Mitchell Hashimoto
dd7bc5db0c terraform: more self tests 2015-02-23 15:02:26 -08:00
Mitchell Hashimoto
0e59acc2c9 terraform: enable self vars 2015-02-23 14:56:02 -08:00
Mitchell Hashimoto
022967acdb terraform: module inputs/vars can be non-strings [GH-819] 2015-02-23 13:50:53 -08:00
Mitchell Hashimoto
8a9c8a882e Merge pull request #1019 from hashicorp/f-state-equality
terraform: State.Equal to check for state equality
2015-02-23 13:47:47 -08:00
Mitchell Hashimoto
709c40026c terraform: remove debug println 2015-02-23 13:45:45 -08:00
Mitchell Hashimoto
39d2bf4629 terraform: cache provider configuration with the provider name
/cc @sethvargo

This was causing a race with whichever provider was configured first
would "win" the configuration slot. We need to make sure to append the
unique provider name to the end of the key.

Note: this doesn't have tests. We don't test this yet. :(
2015-02-20 15:48:06 -08:00
Mitchell Hashimoto
40ee70d5c9 terraform: Input should only be called on providers once
/cc @sethvargo

Prior to this commit, we'd only persist the result of calling Input if
any input was given (len(result) > 0). The result was that every module
would also repeat asking for input even if there was no input to be
asked for.

This commit makes it so that if no input was received, we still set a
sentinel so that modules don't re-ask.
2015-02-20 15:35:57 -08:00
Mitchell Hashimoto
b041f48e56 terraform: State.Equal 2015-02-20 13:39:49 -08:00
Mitchell Hashimoto
85e2bef179 terraform: provisioners should be cached with the provisioner name 2015-02-20 10:50:36 -08:00
Mitchell Hashimoto
ab414de0ab terraform: test case for destroying with a count [GH-527] 2015-02-20 10:02:52 -08:00
Mitchell Hashimoto
c2593f6ada terraform: re-enable dot-graphs 2015-02-19 23:00:29 -08:00
Mitchell Hashimoto
4b6f258f1f terraform: only depose state if we're doing the destroy side 2015-02-19 12:08:34 -08:00
Mitchell Hashimoto
fa222a44c3 terraform: limit parallelism 2015-02-19 12:08:34 -08:00
Mitchell Hashimoto
0175d1babc terraform: updated comment 2015-02-19 12:08:33 -08:00
Mitchell Hashimoto
10e96ad72d terraform: provisioner config is properly interpolated 2015-02-19 12:08:33 -08:00
Mitchell Hashimoto
ae68cf1705 terraform: slightly better validation error messages 2015-02-19 12:08:33 -08:00
Mitchell Hashimoto
459ad04d71 terraform: provider cache should append the provider name to it 2015-02-19 12:08:33 -08:00
Mitchell Hashimoto
ad595cf254 terraform: test case for cycle of CBD depending on non-CBD 2015-02-19 12:08:33 -08:00
Mitchell Hashimoto
e68ea0d38f terraform: only keep the destroy if we decreased counts 2015-02-19 12:08:33 -08:00
Mitchell Hashimoto
1ed37f0b7f terraform: change DiffId to DiffInclude to allow smarter logic
This lets us check for orphans properly.
2015-02-19 12:08:33 -08:00
Mitchell Hashimoto
4789f16796 terraform: tainted destroy nodes 2015-02-19 12:08:33 -08:00
Mitchell Hashimoto
991611857a terraform: remove requirement that DestroyNode return the SAME node 2015-02-19 12:08:33 -08:00
Mitchell Hashimoto
9c14315336 terraform: don't prune if there are known tainted resources 2015-02-19 12:08:33 -08:00
Mitchell Hashimoto
8d2ed22e97 terraform: prune destroy nodes for resources not in diff 2015-02-19 12:08:32 -08:00
Mitchell Hashimoto
8db6f722d2 terraform: CBD edge transpositions must happen atomically 2015-02-19 12:08:32 -08:00
Mitchell Hashimoto
c47440ddd6 terraform: remove evaltype, unused 2015-02-19 12:08:32 -08:00
Mitchell Hashimoto
b52881d232 terraform: clean up EvalNodes 2015-02-19 12:08:32 -08:00
Mitchell Hashimoto
af1778cd5e terraform: goodbye graph.go 2015-02-19 12:08:32 -08:00
Mitchell Hashimoto
b1e5b32322 terraform: Graph returns *Graph for now 2015-02-19 12:08:32 -08:00
Mitchell Hashimoto
7552abed8b terraform: fix Refresh func signature 2015-02-19 12:08:32 -08:00
Mitchell Hashimoto
7ccba588ac terraform: gofmt -w -r 'Context2 -> Context' terraform/ 2015-02-19 12:08:32 -08:00
Mitchell Hashimoto
e37c187228 terraform: goodbye context.go (old) 2015-02-19 12:08:32 -08:00
Mitchell Hashimoto
14b5942453 terraform: all input tests pass 2015-02-19 12:08:08 -08:00
Mitchell Hashimoto
7c78a3749e terraform: provider input 2015-02-19 12:08:08 -08:00
Mitchell Hashimoto
f3714f1efc terraform: start Input 2015-02-19 12:08:08 -08:00
Mitchell Hashimoto
7b305d1f41 terraform: forgot the docs :( 2015-02-19 12:08:08 -08:00
Mitchell Hashimoto
960ba73f1d terraform: last apply test 2015-02-19 12:08:08 -08:00
Mitchell Hashimoto
1c713878b0 terraform: fix outputs on destroy 2015-02-19 12:08:07 -08:00
Mitchell Hashimoto
bd0c3b12cb terraform: more tests passing 2015-02-19 12:08:07 -08:00
Mitchell Hashimoto
c8091aa338 terraform: fix more create-before-destroy state juggling 2015-02-19 12:08:07 -08:00
Mitchell Hashimoto
33cad6d207 terraform: fix create before destroy edge case with partial state 2015-02-19 12:08:07 -08:00
Mitchell Hashimoto
f7f1f17b49 terraform: create before destroy 2015-02-19 12:08:07 -08:00
Mitchell Hashimoto
119d5a09cf terraform: fix some diff comparison 2015-02-19 12:08:07 -08:00
Mitchell Hashimoto
b8ebcc85d7 terraform: partial state works properly 2015-02-19 12:08:07 -08:00
Mitchell Hashimoto
5f8d1b86d5 terraform: more passing tests 2015-02-19 12:08:07 -08:00
Mitchell Hashimoto
6bb3cb8f2f terraform: a lot more passing tests 2015-02-19 12:08:06 -08:00
Mitchell Hashimoto
742b45886a terraform: destroy nodes work properly 2015-02-19 12:08:06 -08:00
Mitchell Hashimoto
c3df003624 terraform: more passing tests 2015-02-19 12:08:06 -08:00
Mitchell Hashimoto
e2abf17c9c terraform: provisioners should only be run on first create 2015-02-19 12:08:06 -08:00
Mitchell Hashimoto
c70cc682ea terraform: resource provisioner self references are not put in the graph 2015-02-19 12:08:06 -08:00
Mitchell Hashimoto
edfb11ff1d terraform: more passing tests 2015-02-19 12:08:06 -08:00
Mitchell Hashimoto
79746cb35d terraform: state must not be nil for apply 2015-02-19 12:08:06 -08:00
Mitchell Hashimoto
b8e5690565 terraform: eval post hook, eerrors 2015-02-19 12:08:06 -08:00
Mitchell Hashimoto
819aed67d4 terraform: provisioners 2015-02-19 12:08:06 -08:00
Mitchell Hashimoto
f8871917f5 terraform: update tests 2015-02-19 12:08:06 -08:00
Mitchell Hashimoto
10e82375f2 terraform: early exit and cancellation 2015-02-19 12:08:05 -08:00
Mitchell Hashimoto
d0c77d268a terraform: more tests passing 2015-02-19 12:08:05 -08:00
Mitchell Hashimoto
843cfbe8ad terraform: tainted apply 2015-02-19 12:08:05 -08:00
Mitchell Hashimoto
a3e4b3e966 terraform: more apply tests 2015-02-19 12:08:05 -08:00
Mitchell Hashimoto
691db58478 terraform: apply for orphans 2015-02-19 12:08:05 -08:00
Mitchell Hashimoto
abc68a89a8 terraform: use the proper diff for apply time 2015-02-19 12:08:05 -08:00
Mitchell Hashimoto
aea6b0a7e1 terraform: compare bad diffs for apply 2015-02-19 12:08:05 -08:00