TerraformPilot

Troubleshooting

Fix Terraform Kinesis Stream - ResourceInUseException

Fix AWS Kinesis stream name conflict errors in Terraform. Handle duplicate streams, import existing resources, shard count changes, and stream modes.

LLuca Berton1 min read

Quick Answer

#

A Kinesis stream with the same name already exists in the region, or the stream is currently being modified. Import the existing stream, use a unique name, or wait for in-progress operations to complete.

The Error

#
Error: creating Kinesis Stream (my-data-stream):
  ResourceInUseException: Stream my-data-stream already exists.
Error: updating Kinesis Stream (my-data-stream):
  ResourceInUseException: Stream my-data-stream under account xxx
  is currently being modified.

What Causes This Error

#
  1. Stream already exists — created manually, by another workspace, or failed previous apply
  2. Stream being modified — shard count change or encryption update in progress
  3. Stream in DELETING state — recently deleted but not yet fully removed

How to Fix It

#

Solution 1: Import the Existing Stream

#
aws kinesis describe-stream-summary --stream-name my-data-stream
 
terraform import aws_kinesis_stream.data my-data-stream

Solution 2: Use Unique Naming

#
resource "aws_kinesis_stream" "data" {
  name             = "${var.project}-${var.environment}-events"
  shard_count      = 2
  retention_period = 24
 
  stream_mode_details {
    stream_mode = "PROVISIONED"
  }
 
  tags = {
    Environment = var.environment
    ManagedBy   = "terraform"
  }
}

Solution 3: Use On-Demand Mode

#
resource "aws_kinesis_stream" "data" {
  name = "${var.project}-${var.environment}-events"
 
  stream_mode_details {
    stream_mode = "ON_DEMAND"  # No shard count needed
  }
 
  retention_period = 72
}

Solution 4: Wait for Modifications to Complete

#
# Check stream status
aws kinesis describe-stream-summary --stream-name my-data-stream \
  --query 'StreamDescriptionSummary.StreamStatus'
 
# Wait until ACTIVE, then retry
aws kinesis wait stream-exists --stream-name my-data-stream
terraform apply

Troubleshooting Checklist

#
  1. ✅ Does the stream exist? (aws kinesis describe-stream-summary)
  2. ✅ What's the stream status? (CREATING, ACTIVE, UPDATING, DELETING)
  3. ✅ Should you import or delete it?
  4. ✅ Is a modification currently in progress?

Prevention Tips

#
  • Use environment-prefixed stream names to avoid collisions
  • Use ON_DEMAND mode for variable workloads — avoids shard scaling conflicts
  • Import existing streams before recreating
  • Add timeouts for shard scaling operations
#

Conclusion

#

Kinesis ResourceInUseException means the stream name is taken or the stream is being modified. Import existing streams, use unique naming, and check stream status before retrying operations.

#Terraform#AWS#Troubleshooting#Error Fix

Share this article