0
votes

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?

1
are you trying to run from same directory as you run first? btw terraform keep the state/Adiii
yes, from the same dir. I did not remove the state file, so it should be there.Reynard
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.mohit

1 Answers

3
votes

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.