Commit Graph

33 Commits

Author SHA1 Message Date
James Bardin 7aa2ce8341 add -reconfigure option for init
The reconfigure flag will force init to ignore any saved backend state.
This is useful when a user does not want any backend migration to
happen, or if the saved configuration can't be loaded at all for some
reason.
2017-04-20 18:15:46 -04:00
James Bardin d059939f88 Merge pull request #13262 from hashicorp/jbardin/lock-timeouts
lock timeouts
2017-04-04 14:30:20 -04:00
James Bardin 5eca913b14 add cli flags for -lock-timeout
Add the -lock-timeout flag to the appropriate commands.
Add the -lock flag to `init` and `import` which were missing it.
Set both stateLock and stateLockTimeout in Meta.flagsSet, and remove the
extra references for clarity.
2017-04-01 17:09:21 -04:00
James Bardin 305ef43aa6 provide contexts to clistate.Lock calls
Add fields required to create an appropriate context for all calls to
clistate.Lock.

Add missing checks for Meta.stateLock, where we would attempt to lock,
even if locking should be skipped.
2017-04-01 17:09:20 -04:00
James Bardin 3f0dcd1308 Have the clistate Lock use LockWithContext
- Have the ui Lock helper use state.LockWithContext.
- Rename the message package to clistate, since that's how it's imported
  everywhere.
- Use a more idiomatic placement of the Context in the LockWithContext
  args.
2017-04-01 17:09:20 -04:00
James Bardin 8050eda52d don't delete local state on a local backend
Don't erase local state during backend migration if the new and old
paths are the same. Skipping the confirmation and copy are handled in
another patch, but the local state was always erased by default, even
when it was our new state.
2017-03-31 15:26:23 -04:00
James Bardin c891ab50b7 detect when backend.Hash needs update
It's possible to not change the backend config, but require updating the
stored backend state by moving init options from the config file to the
`-backend-config` flag. If the config is the same, but the hash doesn't
match, update the stored state.
2017-03-29 16:03:51 -04:00
James Bardin ff2d753062 add Rehash to terraform.BackendState
This method mirrors that of config.Backend, so we can compare the
configration of a backend read from a config vs that of a backend read
from a state. This will prevent init from reinitializing when using
`-backend-config` options that match the existing state.
2017-03-29 15:53:42 -04:00
James Bardin 8027fe9e08 Don't Validate if we have an execution plan
The plan file should contain all data required to execute the apply
operation. Validation requires interpolation, and the `file()`
interpolation function may fail if the module files are not present.
This is the case currently with how TFE executes plans.
2017-03-27 17:11:50 -04:00
James Bardin 54e536cfe0 add `-force-copy` option to init command
The `-force-copy` option will suppress confirmation for copying state
data.

Modify some tests to use the option, making sure to leave coverage of
the Input code path.
2017-03-22 08:47:26 -04:00
Mitchell Hashimoto 4f59576231
command: fix awkward wording in message 2017-03-17 10:52:22 -07:00
Mitchell Hashimoto 96e38041ab
command: use backendinit instead of initializing legacy directly
Fixes #12806

This should've been part of 2c19aa69d9

This is the same issue, just missed a spot. Tests are hard to cover for
this since we're removing the legacy backends one by one, eventually
it'll be gone. A good sign is that we don't import backendlegacy at all
anymore in command/
2017-03-17 10:41:13 -07:00
Mitchell Hashimoto df8529719c
command/init: backend-config accepts key=value pairs
This augments backend-config to also accept key=value pairs.
This should make Terraform easier to script rather than having to
generate a JSON file.

You must still specify the backend type as a minimal amount in
configurations, example:

```
terraform { backend "consul" {} }
```

This is required because Terraform needs to be able to detect the
_absense_ of that value for unsetting, if that is necessary at some
point.
2017-03-16 23:27:05 -07:00
Mitchell Hashimoto e1f4eca93c
command: apply needs to look at the right field for backend state
Plans were properly encoding backend configuration but the apply was
reading it from the wrong field. :( This meant that every apply from a
plan was applying it locally with backends.

This needs to get released ASAP.
2017-03-16 15:44:15 -07:00
Mitchell Hashimoto 81639480fb
command: recompute config hash with ConfigFile set
Fixes #12749

If we merge in an extra partial config we need to recompute the hash to
compare with the old value to detect that change.

This hash needs to NOT be stored and just used as a temporary. We want
to keep the original hash in the state so that we don't detect a change
from the config (since the config will always be partial).
2017-03-16 11:47:59 -07:00
Mitchell Hashimoto 8b208a597d
command/push: don't allow pushing with local backend 2017-03-16 10:47:48 -07:00
Mitchell Hashimoto 03493f7d46
command: validate backend config
The validation itself was added a couple weeks ago but I forgot to
actually call it. :sad:
2017-03-02 14:07:49 -08:00
Mitchell Hashimoto bdde7d845a Merge pull request #12347 from hashicorp/b-env-migrate
command: migrating envs when changing backends
2017-03-01 12:58:40 -08:00
Mitchell Hashimoto 549d525487 Merge pull request #12320 from hashicorp/b-legacy-state
command: fix loading legacy remote state + migration guide
2017-03-01 12:39:17 -08:00
Mitchell Hashimoto 1d8b76c89d
command: initial work on migrating envs, basic cases first 2017-03-01 10:59:17 -08:00
Mitchell Hashimoto 2c19aa69d9
command: legacy remote state should load from backendinit 2017-02-28 19:29:19 -08:00
James Bardin b53704ed87 Thread the environment through all commands
Add Env and SetEnv methods to command.Meta to retrieve the current
environment name inside any command.

Make sure all calls to Backend.State contain an environment name, and
make the package compile against the update backend package.
2017-02-28 16:35:46 -05:00
James Bardin 1ea9413c07 Remove state path handling from commands
The Local backend is now responsible for handling the paths to the local
state files, since they are dependent on the current environment.
2017-02-28 16:06:14 -05:00
Mitchell Hashimoto 3cedfa00f4
command: use backend.CLIIinit
I made this interface way back with the original backend work and I
guess I forgot to hook it up! This is becoming an issue as I'm working
on our 2nd enhanced backend that requires this information and I
realized it was hardcoded before.

This propertly uses the CLIInit interface allowing any backend to gain
access to this data.
2017-02-28 10:58:29 -08:00
Mitchell Hashimoto 478a7dbfe7
command: convert to using backend/init 2017-02-22 11:17:27 -08:00
James Bardin 5095d7c6a7 Add complete unlock test
Test actual unlock failure and success through the the unlock command.
2017-02-20 14:50:31 -05:00
James Bardin f5ed8cd288 Use NewLockInfo to get a pre-populated value
Using NewLockInfo ensure we start with all required fields filled.
2017-02-15 14:41:55 -05:00
James Bardin 4f0c465187 make command tests pass with new state.Locker 2017-02-15 14:41:55 -05:00
Mitchell Hashimoto 90f3d40c1f
command: use new state lock/unlock helpers for better UX 2017-02-14 11:33:55 -08:00
George Hartzell e39f4e1993 Typo: determien -> determine (#11888) 2017-02-12 19:46:32 +00:00
James Bardin 0c1b138719 Add state locking during backend init
During backend initialization, especially during a migration, there is a
chance that an existing state could be overwritten.

Attempt to get a locks when writing the new state. It would be nice to
always have a lock when reading the states, but the recursive structure
of the Meta.Backend config functions makes that quite complex.
2017-02-09 15:47:27 -05:00
James Bardin 5c2e945b3c Fix format string and typos 2017-02-09 10:27:42 -05:00
Mitchell Hashimoto 9654387771
command: meta.Backend is used for initializing the backend
This is a complex function that handles all the potential cases that can
happen with legacy remote state, new configurations, etc.
2017-01-26 14:33:49 -08:00