Moving to 0.9 s3 remote state

624 views
Skip to first unread message

Marco Morales

unread,
Apr 3, 2017, 8:19:50 PM4/3/17
to Terraform
Hello,

I'm trying to migrate to using the new 0.9 s3 backend, I'm using terraform 0.9.2. I was already using the old s3 remote state before. I'm also trying to use the new state locking with DynamoDB.

This is what my terraform backend config looks like:

terraform {
  backend "s3" {
    bucket = "foobar-terraform-state-oregon"
    key = "oregon-terraform.tfstate"
    region = "us-west-2"
    lock_table = "foobar"
  }
}

I created the dynamodb table "foobar" with a primary key of "LockID". When I run terraform init I get the following output:

 
Initializing the backend...
Legacy remote state was detected while also changing your current backend!reset]

Terraform has detected that you have legacy remote state, a configured
current backend, and you're attempting to reconfigure your backend. To handle
all of these changes, Terraform will first reconfigure your backend. After
this, Terraform will handle optionally copying your legacy remote state
into the newly configured backend.


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

Error locking source state: Error acquiring the state lock: 2 error(s) occurred:

* ResourceNotFoundException: Requested resource not found
status code: 400, request id: CADDUB3DG14JRUTE4DK1FATMGVVV4KQNSO5AEMVJF66Q9ASUAAJG
* ResourceNotFoundException: Requested resource not found
status code: 400, request id: B5K7M98IQFA9K6F6UALF14MCA3VV4KQNSO5AEMVJF66Q9ASUAAJG

Terraform acquires a state lock to protect the state from being written
by multiple users at the same time. Please resolve the issue above and try
again. For most commands, you can disable locking with the "-lock=false"
flag, but this is not recommended.

Has anyone run into similar situations?

James Bardin

unread,
Apr 4, 2017, 4:26:23 PM4/4/17
to Terraform
Hi Marco,

The "ResourceNotFoundException" error is coming from the DynamoDB call, which generally means the table doesn't exist. Are you certain that you created the "foobar" table in "us-west-2", and not another region?

Marco Morales

unread,
Apr 4, 2017, 7:45:52 PM4/4/17
to Terraform
Hey James,

I'm sure this table exist since I can see it when I run the command `aws dynamodb list-tables`, and when I configure the aws cli tool the region is us-west-2. I can also confirm that this is the same region that I have configured in the aws provider in terraform.

James Bardin

unread,
Apr 5, 2017, 4:28:21 PM4/5/17
to Terraform


On Tuesday, April 4, 2017 at 7:45:52 PM UTC-4, Marco Morales wrote:
Hey James,

I'm sure this table exist since I can see it when I run the command `aws dynamodb list-tables`, and when I configure the aws cli tool the region is us-west-2. I can also confirm that this is the same region that I have configured in the aws provider in terraform.


That may be a clue -- the backend config is separate from the aws provider config (though they will be sharing more code for more consistent behavior). Do you have the region set in the backend config, or do you have AWS_DEFAULT_REGION set in the environment?


Marco Morales

unread,
Apr 6, 2017, 6:56:26 PM4/6/17
to Terraform
I've setup the backend config and the provider config to the same region. So just to be more specific, on two .tf files, I've specified the terraform block with backend block and the region us-west-2. On the aws provider block, I have the us-west-2 region. I don't use the environment variables for any of the terraform settings.

Yoaquim Cintrón

unread,
May 16, 2017, 7:13:55 PM5/16/17
to Terraform
Experiencing the exact same problem, and I've corroborated my table is in the same region as the profile I'm using.

Did you manage to fix this?

Any ideas?

James Bardin

unread,
May 17, 2017, 9:15:11 AM5/17/17
to terrafo...@googlegroups.com
On Tue, May 16, 2017 at 7:13 PM, Yoaquim Cintrón <yoaquim...@gmail.com> wrote:
Experiencing the exact same problem, and I've corroborated my table is in the same region as the profile I'm using.

Did you manage to fix this?

Any ideas?


Are you using the current release?
What Version of terraform were you using previously?
Are you changing any of the key, bucket or region values from the existing state?
Can you post the backend config saved in `.terraform/terraform.tfstate`, or if it exists?


Vamshi krishna

unread,
Jun 7, 2017, 11:40:33 AM6/7/17
to Terraform
Hey Marco,

I have faced the same situtation. Its because  the item in your dynamoDB table should be `LockId` not `StateFileId`.  terraform specifically mentioned it. Recreate your dynamoDb table that should fix this error. 
Reply all
Reply to author
Forward
0 new messages