terraform/backend
Martin Atkins 9cda37205d backend/local: create local state file if backend write fails
In the old remote state system we had the idea of a local backup, which
is actually still present for the legacy backends but no longer applies
for the new-style backends like the s3 backend.

It's problematic when an apply runs for long enough that someone's
time-limited AWS STS credentials expire and then Terraform fails and can't
persist state to S3.

To reduce the risk of lost state, here we add some extra fallback code
for the local apply operation in particular. If either state writing
or state persisting fail then we attempt to write the state to a special
backup file errored.tfstate, and produce an error message that guides the
user on how to retry uploading this state.

In the unlikely event that we can't write to local disk either (e.g.
permissions problems) we take a last-ditch attempt to dump the JSON onto
stdout and advise the user to manually copy it into a file for import.
If even that doesn't work for some reason, we assume a critical Terraform
bug (JSON-serialization problem with states?) and bail out with an
apologetic error message.

This is implemented for the apply command in particular because this is
the one command where new objects are created in real APIs that we don't
want to lose track of. For other operations it's less bad to just generate
a simple error message and have the user retry.

This fixes #14298.
2017-05-23 11:18:01 -07:00
..
atlas backend/atlas: accept ATLAS_ADDRESS env var for address 2017-03-16 23:04:07 -07:00
init convert S3 remote state to a backend 2017-03-22 10:59:37 -04:00
legacy Make backcend/legacy match new Backend iface 2017-02-28 16:35:45 -05:00
local backend/local: create local state file if backend write fails 2017-05-23 11:18:01 -07:00
remote-state only list environments when the keyName matches 2017-04-12 13:57:22 -04:00
backend.go provide contexts to clistate.Lock calls 2017-04-01 17:09:20 -04:00
cli.go command: use backend.CLIIinit 2017-02-28 10:58:29 -08:00
nil.go Update Backend interface to latest iteration 2017-02-28 16:07:07 -05:00
nil_test.go
operation_type.go
operationtype_string.go Restore stringer-generated files back to new version 2017-04-21 14:49:18 -07:00
testing.go test for proper state persistence 2017-03-23 10:06:07 -04:00