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.
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.
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.
## 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.
Error: Error rendering template: template not found
How to fix "template not found" error in Terraform
Error: Error generating private key
How to fix 'Error generating private key' in Terraform
Error creating Kubernetes Service: field is immutable
How to fix "field is immutable" errors in Terraform
Error: Error creating local file: open: permission denied
How to fix "Error creating local file: permission denied" in Terraform
Error: line endings have changed from CRLF to LF
Line endings have changed from CRLF to LF in Terraform