0

I successfully applied my basic configuration for AWS using Terraform (added a DynamoDB table):

terraform init
terraform apply -auto-approve

After I updated files by adding new resources and ran apply again, I got an error that Dynamo table already exists:

* aws_dynamodb_table.my-table: error creating DynamoDB Table: ResourceInUseException: Table already exists: my-table

How can I avoid replacing existing resources?

3
  • 1
    are you trying to run from same directory as you run first? btw terraform keep the state/ Commented Sep 21, 2019 at 16:33
  • yes, from the same dir. I did not remove the state file, so it should be there. Commented Sep 21, 2019 at 16:39
  • Can you print the output of the plan ? Ideally it should not create this resource if its there in its state file or maybe if you have created it from GUI. Commented Sep 21, 2019 at 18:52

1 Answer 1

3

It turns out, that I needed to update to a newer version of Terraform. In my case, from 0.11.4 to 0.12.9

Before the change: state was updated, but not "used", so it tried to re-create ALL the resources.

After the change: apply phase skips the resources saved into state, as expected.

Hope it helps someone.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm positive that Terraform 0.11.x used the state file correctly and didn't just ignore it. There had to be some other issue you were encountering, but glad to know upgrading fixed it for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.