Terraform: S3 Backend Initialisation Error

Created on 22 Mar 2017  ยท  5Comments  ยท  Source: hashicorp/terraform

Admittedly this is probably very low priority issue, as it only happens if you rerun initialisation in a folder where the backend was already initialised. Not a blocker by any means, but it was definitely unexpected.

NOTE: Obviously the bucket name is not the one I use, and I changed a few paths and so on, but this should be reproducible.

Terraform Version

0.9.1

Affected Resource(s)

S3 backend locking during initialisation.

Terraform Configuration Files

config.tfvars:

region = "eu-west-1"
encrypt = "true"
lock_table = "terraform_locks"
bucket = "terraform-statefiles.sandbox"

main.tf:

terraform {
  required_version = ">= 0.9.0"
  backend "s3" {}
}

Debug Output

Gist

Expected Behavior

It should not have noted any changes to the backend, if I run the command twice in a row with the same configuration. Furthermore, when trying to copy over states with the same names, it should not run into locking issues.

Actual Behavior

On every init run, changes in the backend are detected, even there are no actual configuration changes. Furthermore, when trying to copy over pre-existing state that has the same exact key, it fails to acquire the lock. When replying "no" to copying over pre-existing state, it works just fine.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform init -backend-config='key=global.tfstate' -backend-config=config.tfvars

Most helpful comment

Deleting .terraform/terraform.tfstate before doing terraform init fixed the issue for me.

All 5 comments

Same problem for me with v0.9.1. I dynamically construct the S3 key and since interpolation is not available for backend config, I am passing the key in -backend-config.

However, as mentioned, this option forces a backend change and interactive prompts break our automation.

Hi,

Thanks for reporting the issue. A problem merging "terraform" configuration blocks was recently fixed by #12942 , and will be included in the next release.

I verified the above reproduction case works in master.

Looks like the issue still exists in v0.9.2 for me.

When I run terraform init against a previously applied/saved state:

terraform init -input=false -get=true -backend-config="key=project/env/terraform.tfstate"

I get:

Initializing the backend...
Backend configuration changed!

Terraform has detected that the configuration specified for the backend
has changed. Terraform will now reconfigure for this backend. If you didn't
intend to reconfigure your backend please undo any changes to the "backend"
section in your Terraform configuration.


Do you want to copy the state from "s3"?
  Would you like to copy the state from your prior backend "s3" to the
  newly configured "s3" backend? If you're reconfiguring the same backend,
  answering "yes" or "no" shouldn't make a difference. Please answer exactly
  "yes" or "no".

  Enter a value:

Deleting .terraform/terraform.tfstate before doing terraform init fixed the issue for me.

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings