Commit Graph

314 Commits

Author SHA1 Message Date
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
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
Mitchell Hashimoto
a0839da71a terraform: merge provider configs before validate [GH-1282] 2015-03-25 16:28:52 -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
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
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
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
341be226f4 terraform: test for various taint cases 2015-02-26 09:50:18 -08:00
Mitchell Hashimoto
ac167c3082 terraform: test post state update is called 2015-02-23 22:10:31 -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
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
ab414de0ab terraform: test case for destroying with a count [GH-527] 2015-02-20 10:02:52 -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
10e96ad72d terraform: provisioner config is properly interpolated 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
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
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
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
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
Mitchell Hashimoto
d72ceb597d terraform: more tests 2015-02-19 12:08:05 -08:00
Mitchell Hashimoto
9b7d1509fc terraform: outputs in apply 2015-02-19 12:08:05 -08:00
Mitchell Hashimoto
a614f6105a terraform: apply starting 2015-02-19 12:08:04 -08:00
Mitchell Hashimoto
93f3050dbd terraform: make things more linear 2015-02-19 12:08:04 -08:00
Mitchell Hashimoto
67e7aeeea0 terraform: PLAN IS DONE
http://i.imgur.com/fiw5hXx.gif
2015-02-19 12:08:04 -08:00
Mitchell Hashimoto
f85baf6e26 terraform: more tests 2015-02-19 12:08:04 -08:00
Mitchell Hashimoto
ef32656a65 terraform: set the diff up properly with tainted resources 2015-02-19 12:08:04 -08:00
Mitchell Hashimoto
e82affdf5c terraform: more plan tests 2015-02-19 12:08:04 -08:00
Mitchell Hashimoto
ec6ce69e90 terraform: destroy module plan 2015-02-19 12:08:04 -08:00
Mitchell Hashimoto
e185769271 terraform: plan destroy 2015-02-19 12:08:04 -08:00
Mitchell Hashimoto
00f4245572 terraform: count increase from one tests 2015-02-19 12:08:04 -08:00
Mitchell Hashimoto
4ccb12508a terraform: decreasing counts works 2015-02-19 12:08:03 -08:00
Mitchell Hashimoto
4caab6870b terraform: more passing plan tests 2015-02-19 12:08:03 -08:00
Mitchell Hashimoto
354a35afb0 terraform: properly interpolate variable counts 2015-02-19 12:08:03 -08:00
Mitchell Hashimoto
4c3ea016b9 terraform: non-multi count resource is still index 0 2015-02-19 12:08:03 -08:00
Mitchell Hashimoto
14aee00bf0 terraform: setup proper count.index value for interpolation 2015-02-19 12:08:03 -08:00
Mitchell Hashimoto
8365d39d26 terraform: fix more plan tests 2015-02-19 12:08:03 -08:00
Mitchell Hashimoto
a2d278b284 terraform: more passing tests 2015-02-19 12:08:02 -08:00
Mitchell Hashimoto
10a216d85e terraform: nil diffs should not be written to the diff 2015-02-19 12:08:02 -08:00
Mitchell Hashimoto
32e714c41d terraform: computed outputs 2015-02-19 12:08:02 -08:00
Mitchell Hashimoto
de6827b3ed terraform: calculate outputs and store it into the state 2015-02-19 12:08:02 -08:00
Mitchell Hashimoto
fb3a67a6d7 terraform: more passing plan tests 2015-02-19 12:08:02 -08:00
Mitchell Hashimoto
4089d33dea terraform: provider merging should be parent OVER child 2015-02-19 12:08:02 -08:00
Mitchell Hashimoto
99eab4fd13 terraform: more passing plan tests 2015-02-19 12:08:01 -08:00
Mitchell Hashimoto
e45308fa6d terraform: module orphans are properly expanded and planned for destroy 2015-02-19 12:08:01 -08:00
Mitchell Hashimoto
f7bed9a2f9 terraform: more tests 2015-02-19 12:08:01 -08:00
Mitchell Hashimoto
10dee0dce8 terraform: more passing tests 2015-02-19 12:08:01 -08:00
Mitchell Hashimoto
23d097ee53 terraform: module inputs are passed through to subgraphs 2015-02-19 12:08:01 -08:00
Mitchell Hashimoto
5595229430 terraform: uncomments more passing tests 2015-02-19 12:08:00 -08:00