Commit Graph

23 Commits

Author SHA1 Message Date
James Bardin
a1727ec4c2 Add warning to mismatched plan state
Forward-port the plan state check from the 0.9 series.
0.10 has improved the serial handling for the state, so this adds
relevant comments and some more test coverage for the case of an
incrementing serial during apply.
2017-07-17 10:41:29 -04:00
Martin Atkins
1b673746fd core: don't allow core or providers to change between plan and apply
The information stored in a plan is tightly coupled to the Terraform core
and provider plugins that were used to create it, since we have no
mechanism to "upgrade" a plan to reflect schema changes and so mismatching
versions are likely to lead to the "diffs didn't match during apply"
error.

To allow us to catch this early and return an error message that _doesn't_
say it's a bug in Terraform, we'll remember the Terraform version and
plugin binaries that created a particular plan and then require that
those match when loading the plan in order to apply it.

The planFormatVersion is increased here so that plan files produced by
earlier Terraform versions _without_ this information won't be accepted
by this new version, and also that older versions won't try to process
plans created by newer versions.
2017-06-09 14:03:59 -07:00
Mitchell Hashimoto
523801dcc2
terraform: support backends in the state 2017-01-26 14:33:49 -08:00
James Nugent
5d18f41f04 core: Convert context vars to map[string]interface{}
This is the first step in allowing overrides of map and list variables.
We convert Context.variables to map[string]interface{} from
map[string]string and fix up all the call sites.
2016-07-18 13:02:54 -05:00
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
Paul Hinze
f882dd1427 core: Encode Targets in saved Planfile
When a user specifies `-target`s on a `terraform plan` and stores
the resulting diff in a plan file using `-out` - it usually works just
fine since the diff is scoped based on the targets.

When there are tainted resources in the state, however, graph nodes to
destroy them were popping back into the plan when it was being loaded
from a file. This was because Targets weren't being stored in the
Planfile, so Terraform didn't know to filter them out. (In the
non-Planfile scenario, we still had the Targets loaded directly from the
flags.)

By encoding Targets in with the Planfile we can ensure that the same
filters are always applied.

Backwards compatibility should be fine here, since we're just adding a
field. The gob encoder/decoder will just do the right thing (ignore/skip
the field) with planfiles stored w/ versions that don't know about
Targets.

Fixes #5183
2016-03-08 14:29:37 -06: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
718fb42f4b terraform: Plan should use module.Tree 2014-09-24 14:56:48 -07:00
Mitchell Hashimoto
bc67e7c443 terraform: diff is split down into modules 2014-09-23 11:43:21 -07:00
Mitchell Hashimoto
a32833af2c terraform: Graph, Context, Plan all speak modules 2014-09-22 15:37:29 -07:00
Mitchell Hashimoto
258a7311ce terraform: register a type 2014-08-11 09:58:53 -07:00
Mitchell Hashimoto
3acb7dc154 terraform: register another gob type we use 2014-07-24 07:30:23 -07:00
Mitchell Hashimoto
1911ee215b terraform: plan read/write sets magic bytes so we can test format 2014-07-11 21:43:24 -07:00
Mitchell Hashimoto
9e41c6335b terraform: remove unused options for making a plan 2014-07-03 11:33:05 -07:00
Mitchell Hashimoto
51396f02c6 terraform: Plan.Context 2014-07-03 11:32:44 -07:00
Mitchell Hashimoto
8fba438cf0 terraform: bring order to the world
/cc @pearkes
2014-07-02 17:04:48 -07:00
Jack Pearkes
8c330d9e4d terraform: register gob type for array 2014-07-02 16:17:26 -07:00
Mitchell Hashimoto
c493d60358 terraform: register gob type that might be in config 2014-07-02 11:28:23 -07:00
Mitchell Hashimoto
5c836ab861 terraform: PlanOpts for expanding plan configuration 2014-06-28 13:10:11 -07:00
Mitchell Hashimoto
fe79e5df03 command/apply: can take a plan as an argument 2014-06-27 14:43:33 -07:00
Mitchell Hashimoto
d64ba66edb command: adhere to new API 2014-06-25 18:22:42 -07:00
Mitchell Hashimoto
f7a6cbf247 terraform: rename Diff to Plan on Terraform API 2014-06-20 10:44:49 -07:00
Mitchell Hashimoto
d2001275dc terraform: initial Plan structure
This is REALLY heavy and would be really hard to maintain any sort
of compatibility with, but it is what we're going to do during dev
initially (if we don't ship with it) in order to just get stuff working.
2014-06-20 10:33:26 -07:00