How to fix Error creating ElastiCache Cluster: ReplicationGroupNotFoundFault in Terraform

TerraformINTERMEDIATEHIGHUpdated Dec 31, 2025ยท 99 views

The ReplicationGroupNotFoundFault error occurs when Terraform references an ElastiCache replication group that doesn't exist or hasn't been created yet. This typically happens due to dependency ordering issues, manual deletions, or incorrect resource references. Verify the replication group exists, fix dependencies, and upgrade your AWS provider to v5.10.0 or later.

Quick fix

Fixes ReplicationGroupNotFoundFault

aws elasticache describe-replication-groups \
  --replication-group-id your-replication-group-id \
  --region us-east-1
  1. Verify the replication group exists in AWS
  2. Check your Terraform resource references
  3. Add explicit depends_on to ensure proper ordering
  4. Remove and re-import the resource from state
terraform โ€” error
aws elasticache describe-replication-groups \
--replication-group-id your-replication-group-id \
--region us-east-1
Error creating ElastiCache Cluster: ReplicationGroupNotFoundFault

What this error means

When Terraform attempts to create or modify ElastiCache resources, it may fail with ReplicationGroupNotFoundFault if it references a replication group that cannot be found in your AWS account. This happens when: 1. The replication group ID or reference is incorrect 2. The replication group hasn't been created yet due to dependency ordering 3. The replication group was manually deleted outside of Terraform 4. Terraform is querying for the resource before it's fully available in AWS Older versions of Terraform AWS Provider (pre-5.10.0) don't properly handle manually deleted resources during refresh, causing persistent failures. This requires either upgrading the provider or removing the resource from Terraform state.

Typical symptoms

  • Terraform plan or apply fails with 'ReplicationGroupNotFoundFault' error
  • Error message includes the replication group ID that cannot be found
  • The replication group exists in AWS Console but Terraform can't find it
  • After manually deleting a replication group in AWS, terraform refresh fails
  • Terraform tries to create resources before the replication group is ready
  • Dependency graph issues cause resources to be created in wrong order

Common causes

  1. Replication group ID in Terraform configuration is misspelled or incorrect
  2. aws_elasticache_cluster resource references a non-existent replication group without proper depends_on
  3. Replication group was manually deleted outside of Terraform without updating Terraform state
  4. Using aws_elasticache_cluster instead of aws_elasticache_replication_group for Redis in cluster mode
  5. AWS hasn't fully propagated the replication group creation before Terraform queries for it
  6. Terraform AWS Provider version is older than 5.10.0 and doesn't handle state refresh correctly
  7. Replication group is in a transitional state (deleting, modifying) when Terraform tries to reference it

How to fix "Error creating ElastiCache Cluster: ReplicationGroupNotFoundFault"

1Verify the replication group exists in AWS

Check if the replication group actually exists in your AWS account and region:

bash
aws elasticache describe-replication-groups \
  --replication-group-id your-replication-group-id \
  --region us-east-1

If the command returns "ReplicationGroupNotFoundFault", the replication group truly doesn't exist. If it exists, the issue is with Terraform's reference or state.

2Check your Terraform resource references

Verify that your Terraform configuration correctly references the replication group:

hcl
resource "aws_elasticache_replication_group" "primary" {
  replication_group_description = "My Redis cluster"
  engine                        = "redis"
  engine_version                = "7.0"
  node_type                     = "cache.t3.micro"
  num_cache_clusters            = 2
  automatic_failover_enabled    = true
}

# Correct: Reference the replication group ID directly
resource "aws_elasticache_cluster" "replica" {
  cluster_id           = "my-replica-cluster"
  replication_group_id = aws_elasticache_replication_group.primary.id
}

Ensure the replication_group_id matches exactly or uses the correct terraform reference.

3Add explicit depends_on to ensure proper ordering

Add explicit dependency declaration to ensure the replication group is created before dependent resources:

hcl
resource "aws_elasticache_replication_group" "primary" {
  replication_group_description = "My Redis cluster"
  engine                        = "redis"
  # ... other config ...
}

resource "aws_elasticache_cluster" "replica" {
  cluster_id           = "my-replica-cluster"
  replication_group_id = aws_elasticache_replication_group.primary.id

  # Explicit depends_on (usually not needed with references, but helps with timing issues)
  depends_on = [aws_elasticache_replication_group.primary]
}

While Terraform usually infers dependencies from references, explicit depends_on can help with timing issues.

4Remove and re-import the resource from state

If the replication group was manually deleted outside Terraform, remove it from Terraform state and recreate it:

bash
# Remove from state
terraform state rm aws_elasticache_replication_group.primary

# Re-apply to recreate
terraform apply

Alternatively, if the resource exists in AWS but state is out of sync, import it:

bash
terraform import aws_elasticache_replication_group.primary my-replication-group-id
5Upgrade Terraform AWS Provider to v5.10.0 or later

Upgrade your AWS Provider to v5.10.0 or later, which includes better handling of manually deleted resources:

hcl
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.10"
    }
  }
}

After updating, run:

bash
terraform init
terraform apply

The newer provider will properly refresh state when resources are deleted outside Terraform.

6Ensure you're using the correct resource type

For Redis replication, use aws_elasticache_replication_group instead of aws_elasticache_cluster:

hcl
# Correct for Redis with replication
resource "aws_elasticache_replication_group" "example" {
  replication_group_description = "Redis cluster"
  engine                        = "redis"
  engine_version                = "7.0"
  node_type                     = "cache.t3.micro"
  num_cache_clusters            = 2
  automatic_failover_enabled    = true
}

# aws_elasticache_cluster is for standalone clusters or Memcached

Using the correct resource type prevents referential errors and ensures proper configuration.

Advanced notes

When working with ElastiCache in Terraform, be aware that replication groups have multiple states: creating, available, deleting, and snapshotting. Terraform may query for the resource during state transitions, causing temporary "not found" errors.

If you're using parameter groups with your replication group, ensure the parameter group family matches your Redis engine version (redis7, redis6.x, redis5.0, etc.). Mismatched families can cause creation failures.

For production deployments, always set automatic_failover_enabled = true and use at least 2 cache clusters (num_cache_clusters >= 2) for multi-AZ deployment and automatic failover support.

When dealing with managed backups or snapshots, be aware that the replication group cannot be deleted while a snapshot is in progress. Check CloudTrail logs if you see unexpected timing issues.

Frequently asked questions

What does "ReplicationGroupNotFoundFault" mean?
When Terraform attempts to create or modify ElastiCache resources, it may fail with ReplicationGroupNotFoundFault if it references a replication group that cannot be found in your AWS account. This happens when: 1. The replication group ID or reference is incorrect 2.
How do I fix "ReplicationGroupNotFoundFault"?
The ReplicationGroupNotFoundFault error occurs when Terraform references an ElastiCache replication group that doesn't exist or hasn't been created yet. This typically happens due to dependency ordering issues, manual deletions, or incorrect resource references. Verify the replication group exists, fix dependencies, and upgrade your AWS provider to v5.10.0 or later.
What causes "ReplicationGroupNotFoundFault"?
Replication group ID in Terraform configuration is misspelled or incorrect aws_elasticache_cluster resource references a non-existent replication group without proper depends_on Replication group was manually deleted outside of Terraform without updating Terraform state
Is the "ReplicationGroupNotFoundFault" 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