How to fix Error: Error creating Redshift Cluster: ClusterAlreadyExists in Terraform
The ClusterAlreadyExists error occurs when Terraform attempts to create a Redshift cluster with an identifier that already exists in your AWS account. Since cluster identifiers must be unique within an account and region, this error indicates the cluster was previously created or still exists from a failed operation.
Quick fix
Fixes ClusterAlreadyExists
aws redshift describe-clusters --cluster-identifier my-cluster-name --region us-east-1- Verify the cluster exists in AWS
- Import the existing cluster into Terraform state
- Check Terraform state for conflicts
- Use a unique cluster identifier
aws redshift describe-clusters --cluster-identifier my-cluster-name --region us-east-1Error: Error creating Redshift Cluster: ClusterAlreadyExists
What this error means
The ClusterAlreadyExists error means the cluster identifier you specified is already in use in your AWS account. Redshift cluster identifiers must be unique within each AWS account and region. When Terraform attempts to create a new cluster with an identifier that's already assigned, AWS rejects the operation to prevent resource conflicts. The identifier persists even if the cluster is being deleted or is in an error state.
Typical symptoms
- Terraform apply fails when creating aws_redshift_cluster resource
- Error message shows "ClusterAlreadyExists" or "cluster already exists"
- The specific cluster identifier cannot be reused
- AWS Redshift console shows the cluster exists or is in deletion state
- Previous failed Terraform runs may have left the cluster in an intermediate state
- Cluster was created outside of Terraform (via Console or CLI)
- Terraform state is out of sync with actual AWS resources
Common causes
- The cluster identifier was used in a previous successful Terraform run but state was lost or reset
- The cluster was created manually in AWS Console or via AWS CLI outside Terraform management
- A previous Terraform apply partially completed, leaving the cluster in a pending or intermediate state
- Another team member created a cluster with the same identifier in the same AWS account
- The cluster still exists despite being marked for deletion due to AWS cleanup delays
- Terraform state file does not reflect the actual clusters present in AWS
- A failed apply did not clean up the partially created cluster before exiting
How to fix "Error: Error creating Redshift Cluster: ClusterAlreadyExists"
Confirm the cluster is actually present in your AWS account and region:
aws redshift describe-clusters --cluster-identifier my-cluster-name --region us-east-1If the command returns cluster details, the cluster exists. If it returns a ClusterNotFound error, the cluster may be in a transient deletion state.
If you own the cluster and want Terraform to manage it, import it into your state:
terraform import aws_redshift_cluster.my_cluster my-cluster-nameReplace "my_cluster" with your resource name and "my-cluster-name" with the actual cluster identifier. This brings the existing cluster under Terraform management without modifying it.
List Redshift resources in your state to see what is already tracked:
terraform state list | grep redshift_cluster
terraform state show aws_redshift_cluster.my_clusterIf the resource exists in state, remove it and re-import:
terraform state rm aws_redshift_cluster.my_cluster
terraform import aws_redshift_cluster.my_cluster my-cluster-nameModify your Terraform configuration to use a different cluster identifier that is not already in use:
resource "aws_redshift_cluster" "my_cluster" {
cluster_identifier = "my-cluster-${formatdate("YYYY-MM-DD-hhmm", timestamp())}"
database_name = "mydb"
master_username = "admin"
node_type = "dc2.large"
number_of_nodes = 2
}Cluster identifiers must be 1-63 alphanumeric characters (lowercase) and unique within your account.
If the cluster is in a deletion state, wait for AWS to fully remove it before retrying:
aws redshift describe-clusters --cluster-identifier my-cluster-name --region us-east-1Repeat this command until it returns a ClusterNotFound error. Cluster deletion can take 5-15 minutes. Once deleted, you can reuse the identifier.
If you want to recreate the cluster from scratch, delete it first:
aws redshift delete-cluster --cluster-identifier my-cluster-name --skip-final-cluster-snapshot --region us-east-1Use --final-cluster-snapshot-identifier to save a snapshot before deletion. After deletion completes, you can run terraform apply to create a new cluster with the same identifier.
Advanced notes
## Redshift Cluster Identifier Rules
- Must be 1-63 alphanumeric characters
- First character must be a letter
- Lowercase letters only
- Cannot end with a hyphen
- Cannot contain two consecutive hyphens
- Must be unique within your AWS account and region
## State Drift and Recovery
If Terraform state becomes out of sync due to manual cluster modifications, use terraform refresh to update state without making changes:
terraform refreshThis polls AWS for the current state of all tracked resources and updates your local state file.
## Deletion Timing
Cluster deletion is asynchronous in AWS. The cluster may show as "deleting" for several minutes. During this time, the identifier is still reserved and cannot be reused. Plan accordingly when deleting and recreating clusters.
## Multi-Cluster Deployments
When managing multiple Redshift clusters in the same Terraform configuration, use unique identifiers for each one:
resource "aws_redshift_cluster" "analytics" {
cluster_identifier = "analytics-cluster"
}
resource "aws_redshift_cluster" "reporting" {
cluster_identifier = "reporting-cluster"
}Never attempt to create two resources with the same cluster_identifier in the same or different regions.
Frequently asked questions
- What does "ClusterAlreadyExists" mean?
- The ClusterAlreadyExists error means the cluster identifier you specified is already in use in your AWS account. Redshift cluster identifiers must be unique within each AWS account and region. When Terraform attempts to create a new cluster with an identifier that's already assigned, AWS rejects the operation to prevent resource conflicts.
- How do I fix "ClusterAlreadyExists"?
- The ClusterAlreadyExists error occurs when Terraform attempts to create a Redshift cluster with an identifier that already exists in your AWS account. Since cluster identifiers must be unique within an account and region, this error indicates the cluster was previously created or still exists from a failed operation.
- What causes "ClusterAlreadyExists"?
- The cluster identifier was used in a previous successful Terraform run but state was lost or reset The cluster was created manually in AWS Console or via AWS CLI outside Terraform management A previous Terraform apply partially completed, leaving the cluster in a pending or intermediate state
- Is the "ClusterAlreadyExists" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.