Commit Graph

294 Commits

Author SHA1 Message Date
Mitchell Hashimoto
35c87836b4 core: Add terraform_version to state
This adds a field terraform_version to the state that represents the
Terraform version that wrote that state. If Terraform encounters a state
written by a future version, it will error. You must use at least the
version that wrote that state.

Internally we have fields to override this behavior (StateFutureAllowed),
but I chose not to expose them as CLI flags, since the user can just
modify the state directly. This is tricky, but should be tricky to
represent the horrible disaster that can happen by enabling it.

We didn't have to bump the state format version since the absense of the
field means it was written by version "0.0.0" which will always be
older. In effect though this change will always apply to version 2 of
the state since it appears in 0.7 which bumped the version for other
purposes.
2016-05-10 14:40:11 -04:00
Mitchell Hashimoto
4eed21f04c terraform: issue 5254 test case (not yet working) 2016-02-24 10:55:55 -05:00
Paul Hinze
7a464b1156 tests: extract deadlock checking test helper 2015-08-10 15:50:36 -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
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
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
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
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
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
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
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
74386655a5 terraform: test for reducing count and using splats 2015-06-23 18:25:08 -07:00
Mitchell Hashimoto
b251afb5af terraform: orphan module should flatten 2015-05-14 20:54:33 -07:00
Mitchell Hashimoto
fe74d69852 terraform: validation should succeed if env var set [GH-1930] 2015-05-13 20:09:05 -07: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
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
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
6afc14982a terraform: destroy transform must happen globally 2015-05-02 18:21:00 -07: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
Mitchell Hashimoto
873f5a91bb terraform: EvalDeleteOutput and context test 2015-04-29 11:27:12 -07: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
5ae9ee4d27 terraform: allow TF_VAR_name to be set to set variables 2015-04-22 06:31:53 +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
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
Mitchell Hashimoto
b64fd8401c terraform: prune tainted destroys if no tainted in state [GH-1475] 2015-04-14 10:48:45 -07: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
bcff7e070c terraform: don't prune, but disable, inherited configs [GH-1447] 2015-04-09 08:48:08 -07:00