Commit Graph

748 Commits

Author SHA1 Message Date
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