How to fix Error: Error creating DynamoDB Table: ResourceInUseException in Terraform

TerraformINTERMEDIATEHIGHUpdated Dec 30, 2025· 108 views

The DynamoDB ResourceInUseException error occurs when Terraform attempts to create a table that already exists or is in a transitional state. This happens when a table with the same name already exists in your AWS account, or the table is currently being modified. Most cases are resolved by importing the existing table into Terraform state or using a different table name.

Quick fix

Fixes ResourceInUseException

aws dynamodb list-tables --region us-east-1
  1. Verify the table exists in AWS
  2. Import the existing table into Terraform state
  3. Verify Terraform configuration matches the existing table
  4. Handle table in transitional state (GSI updates)
terraform — error
aws dynamodb list-tables --region us-east-1
Error: Error creating DynamoDB Table: ResourceInUseException

What this error means

AWS DynamoDB returns a ResourceInUseException when an operation conflicts with an existing resource. When creating a table, this means either: (1) a table with the same name already exists in your AWS account, (2) the table is currently in a transitional state (being created, deleted, or modified), or (3) there's a race condition where multiple Terraform operations are trying to modify the same resource simultaneously. Terraform cannot proceed with table creation until the conflict is resolved.

Typical symptoms

  • Terraform apply fails with 'Error creating DynamoDB Table: ResourceInUseException'
  • Error message indicates 'Table already exists' or similar conflict
  • The table exists in AWS Console but Terraform doesn't know about it
  • Running terraform apply multiple times in quick succession causes failures
  • Global Secondary Index (GSI) operations fail with ResourceInUseException
  • Terraform state and AWS resources are out of sync

Common causes

  1. A DynamoDB table with the same name already exists in your AWS account (likely created manually or by another process)
  2. The table is currently in a transitional state (being created, deleted, or undergoing GSI updates)
  3. Terraform state file is out of sync with actual AWS infrastructure
  4. Multiple Terraform apply operations running simultaneously or in quick succession
  5. The table was created but not properly registered in Terraform state due to a previous error or network failure
  6. Name conflict between manually created resources and Terraform-managed resources

How to fix "Error: Error creating DynamoDB Table: ResourceInUseException"

1Verify the table exists in AWS

First, confirm whether the DynamoDB table actually exists in your AWS account:

bash
aws dynamodb list-tables --region us-east-1

Or use the AWS Console: Go to DynamoDB > Tables and check if a table with your configured name exists. If it exists, move to step 2. If it doesn't exist, move to step 4.

2Import the existing table into Terraform state

If the table exists but isn't managed by Terraform, import it into your Terraform state:

bash
terraform import aws_dynamodb_table.my_table my-table-name

Replace my_table with your resource name in Terraform and my-table-name with the actual table name in AWS. This tells Terraform to manage the existing resource instead of creating a new one.

After importing, run:

bash
terraform plan

Verify the plan shows no changes. If it does, your Terraform configuration may not match the existing table—update your configuration accordingly.

3Verify Terraform configuration matches the existing table

After importing, ensure your Terraform configuration exactly matches the existing table's configuration:

hcl
resource "aws_dynamodb_table" "my_table" {
  name           = "my-table-name"
  billing_mode   = "PAY_PER_REQUEST"  # Or PROVISIONED
  hash_key       = "id"
  range_key      = "sort_key"         # If applicable

  attribute {
    name = "id"
    type = "S"
  }

  ttl {
    attribute_name = "TTL"  # If TTL is enabled
    enabled        = true
  }
}

Compare with your actual table configuration in the AWS Console. Update your Terraform code to match exactly, then run terraform plan again to ensure no changes are needed.

4Handle table in transitional state (GSI updates)

If the table is in a transitional state (e.g., updating a Global Secondary Index), wait for the operation to complete before running Terraform again:

bash
aws dynamodb describe-table --table-name my-table-name --region us-east-1

Check the "TableStatus" field. It should be "ACTIVE" before Terraform can modify it. Common transitional states include:
- CREATING: Table is being created
- UPDATING: GSI or capacity is being modified
- DELETING: Table is being deleted

Wait for the operation to complete (check every 30 seconds), then retry:

bash
terraform apply
5Use a different table name if needed

If you don't want to manage the existing table with Terraform, create a new table with a different name:

hcl
resource "aws_dynamodb_table" "my_table" {
  name           = "my-table-name-v2"  # Changed name
  billing_mode   = "PAY_PER_REQUEST"
  hash_key       = "id"

  attribute {
    name = "id"
    type = "S"
  }
}

Then run:

bash
terraform apply

If the old table is no longer needed, delete it manually through the AWS Console.

6Fix race conditions with dependencies

If you're experiencing race conditions (multiple resources trying to modify the same table), ensure proper resource ordering with depends_on:

hcl
resource "aws_dynamodb_table" "my_table" {
  name           = "my-table-name"
  billing_mode   = "PAY_PER_REQUEST"
  hash_key       = "id"

  attribute {
    name = "id"
    type = "S"
  }
}

resource "aws_dynamodb_global_secondary_index" "my_gsi" {
  table_name            = aws_dynamodb_table.my_table.name
  index_name            = "gsi-index"
  hash_key              = "gsi_key"
  projection_type       = "ALL"
  write_capacity_units  = 10
  read_capacity_units   = 10

  depends_on = [aws_dynamodb_table.my_table]
}

Alternatively, define GSI within the table resource to avoid race conditions:

hcl
resource "aws_dynamodb_table" "my_table" {
  name           = "my-table-name"
  billing_mode   = "PROVISIONED"
  hash_key       = "id"
  read_capacity  = 10
  write_capacity = 10

  attribute {
    name = "id"
    type = "S"
  }

  global_secondary_index {
    name            = "gsi-index"
    hash_key        = "gsi_key"
    projection_type = "ALL"
    read_capacity   = 10
    write_capacity  = 10
  }
}
7Sync Terraform state with AWS

If Terraform state is severely out of sync with AWS, refresh the state:

bash
terraform refresh

This updates the Terraform state file to reflect the current AWS infrastructure. Then review the changes:

bash
terraform plan

If the plan shows deletions or unexpected changes, carefully review before applying:

bash
terraform apply

Advanced notes

LocalStack Testing: When using LocalStack (local DynamoDB emulator) for testing, ResourceInUseException can occur immediately after starting LocalStack. Wait a few seconds after startup before creating tables, or add retry logic in your infrastructure code.

Terraform State Recovery: If a table was created but Terraform crashed before updating the state file, the table exists in AWS but not in your .tfstate file. The terraform import command is the safest way to recover. Never manually edit .tfstate files.

Billing Mode Mismatches: Ensure your Terraform configuration specifies the correct billing mode (PROVISIONED or PAY_PER_REQUEST). Changing billing modes requires table updates, which can conflict with concurrent operations.

Regional Considerations: DynamoDB tables are region-specific. Ensure your Terraform provider is configured for the correct region and that you're checking the table in the right region.

Global Tables: If using DynamoDB Global Tables, ResourceInUseException can occur during replication across regions. Wait for replication to complete before modifying the table.

Frequently asked questions

What does "ResourceInUseException" mean?
AWS DynamoDB returns a ResourceInUseException when an operation conflicts with an existing resource. When creating a table, this means either: (1) a table with the same name already exists in your AWS account, (2) the table is currently in a transitional state (being created, deleted, or modified), or (3) there's a race condition where multiple Terraform operations are trying to modify the same resource simultaneously. Terraform cannot proceed with table creation until the conflict is resolved.
How do I fix "ResourceInUseException"?
The DynamoDB ResourceInUseException error occurs when Terraform attempts to create a table that already exists or is in a transitional state. This happens when a table with the same name already exists in your AWS account, or the table is currently being modified. Most cases are resolved by importing the existing table into Terraform state or using a different table name.
What causes "ResourceInUseException"?
A DynamoDB table with the same name already exists in your AWS account (likely created manually or by another process) The table is currently in a transitional state (being created, deleted, or undergoing GSI updates) Terraform state file is out of sync with actual AWS infrastructure
Is the "ResourceInUseException" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading