Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3 backend prompts for copy from s3 to s3 #16418

Closed
suneeta-mall opened this issue Oct 23, 2017 · 7 comments
Closed

S3 backend prompts for copy from s3 to s3 #16418

suneeta-mall opened this issue Oct 23, 2017 · 7 comments

Comments

@suneeta-mall
Copy link

I am using s3 backend with versioning enabled. Init scripts correctly prompts me if I want to copy from s3 to local. After this, I am not sure why I am prompted with copy from s3 to s3. If I am using versioning, I would have thought it will pick the latest version but I am not sure what this copy from s3 to s3 is all about.

Please see details.

Terraform Version

Terraform v0.10.6

Terraform Configuration Files

# Copy-paste your Terraform configurations here.
#
# For large Terraform configs, please use a service like Dropbox and
# share a link to the ZIP file. For security, you can also encrypt the
# files using our GPG public key.
resource "aws_s3_bucket" "state_store" {
  bucket        = "${var.name}-state"
  acl           = "private"
  force_destroy = true
  region        = "${var.region}"

  versioning {
    enabled = true
  }

  tags {
    Name        = "${var.name}-state-store"
    Infra       = "${var.name}"
    Environment = "${var.env}"
    Terraformed = "true"
  }
}

Expected Behavior

What should have happened?
TF should have configured backend from s3 using latest version

Downloading modules...
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: yes

Actual Behavior

What actually happened?

Downloading modules...
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.



Acquiring state lock. This may take a few moments...
Do you want to copy state from "s3" to "s3"?
  Pre-existing state was found in "s3" while migrating to "s3". An existing
  non-empty state exists in "s3". The two states have been saved to temporary
  files that will be removed after responding to this query.
  
  One ("s3"): /var/folders/1h/m_jw277137b5q5916mzp0shh62j_7h/T/terraform905276908/1-s3.tfstate
  Two ("s3"): /var/folders/1h/m_jw277137b5q5916mzp0shh62j_7h/T/terraform905276908/2-s3.tfstate
  
  Do you want to copy the state from "s3" to "s3"? Enter "yes" to copy
  and "no" to start with the existing state in "s3".

  Enter a value: no

Releasing state lock. This may take a few moments...

Steps to Reproduce

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

  1. terraform init
  2. terraform apply
terraform init \
   -backend-config "bucket=$TF_VAR_env.$TF_VAR_base_name-state" \
   -backend-config "dynamodb_table=$TF_VAR_env.$TF_VAR_base_name.statelock"  \
   -backend-config "region=$TF_VAR_region" \
   -backend-config "profile=$TF_VAR_profile" \
   -backend-config "role_arn=$TF_VAR_admin_aws_role"
@cwire4
Copy link

cwire4 commented Oct 24, 2017

Had the same issue with 0.10.6. I replied yes to the s3 to s3 copy and it somehow copied a completely different state file from elsewhere even though the only reference in the backend was to the bucket where the correct state file was located.

@suneeta-mall
Copy link
Author

@cwire4 yes . I have been bitten by that .. had to intervene manually

@cwire4
Copy link

cwire4 commented Oct 25, 2017

Just curious, how did you intervene? I only found out after the fact when trying a plan after setting up the backend. We had versioning on so swapping versions of the tfstate file, editing the digest for the lock table in DynamoDB, and reinitializing fixed it for me.

@suneeta-mall
Copy link
Author

@cwire4 Yes.. thats it. Had to revert to older version on state file in s3 and update the digest for the now 'latest' state file into dynamo.

@bazimov
Copy link

bazimov commented Sep 6, 2018

@suneeta-mall check your local TF_DATA_DIR. Looks like when terraform copies state from S3 to local if other (different state file) state exists that error comes up.
I have fixed by giving separate directories for each terraform state I have (since we have multiple states).
Make sure you clean local .terraform directory and clean up any local states so they don't collude. Hope that helps.

This error is due to mismatch of state in s3 vs local copy (if local copy exists).

@mildwonkey
Copy link
Contributor

I am going to close this issue due to inactivity.

If there is still a question, I recommend the the community forum, where there are far more people available to help. If there is a bug or you would like to make a feature request, please open a new issue and fill out the template.
Thanks!

@ghost
Copy link

ghost commented Oct 13, 2020

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.

@ghost ghost locked as resolved and limited conversation to collaborators Oct 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants