Fix Terraform Error - GCP IAM Member Already Exists
Fix Google Cloud IAM binding conflicts in Terraform. Covers authoritative vs non-authoritative bindings, member format, conditions, and import patterns.
Troubleshooting
Fix Google Cloud SQL instance name conflicts in Terraform. Handle deletion cooldowns, name reuse restrictions, imports, and instance restoration.
A Cloud SQL instance with the same name exists, or the name was recently deleted and is in a 7-day cooldown. GCP Cloud SQL instance names cannot be reused for up to a week after deletion. Use a different name with a timestamp or random suffix.
Error: Error creating DatabaseInstance: googleapi: Error 409:
The Cloud SQL instance already exists. When you delete an instance,
you can't reuse the name of the deleted instance until one week
from the deletion date.A Cloud SQL instance with the same name is active in the project.
GCP reserves deleted Cloud SQL instance names for 7 days. You cannot reuse the name during this period — there is no workaround.
Cloud SQL names are unique per project, but the error might come from a deleted instance in the same project.
resource "random_id" "db" {
byte_length = 4
}
resource "google_sql_database_instance" "main" {
name = "${var.project}-${var.environment}-db-${random_id.db.hex}"
database_version = "POSTGRES_15"
region = var.region
settings {
tier = "db-custom-2-8192"
ip_configuration {
ipv4_enabled = false
private_network = google_compute_network.main.id
}
backup_configuration {
enabled = true
point_in_time_recovery_enabled = true
}
}
deletion_protection = true
}# Check if instance exists
gcloud sql instances describe my-db --project my-project
# Import into Terraform
# Format: projects/PROJECT/instances/INSTANCE_NAME
terraform import google_sql_database_instance.main \
projects/my-project/instances/my-db# Check when the instance was deleted
gcloud sql instances list --project my-project --show-deleted
# If within 7 days, you MUST use a different name
# Append date or random suffixresource "google_sql_database_instance" "main" {
name = "${var.project}-${var.environment}-db-v2"
deletion_protection = true # Prevents accidental deletion
settings {
tier = "db-custom-2-8192"
}
}| Rule | Details |
|---|---|
| Globally unique per project | Can't have two instances with same name in one project |
| 7-day cooldown after deletion | Name reserved for 1 week after delete |
| No workaround for cooldown | Must wait or use a different name |
| Max length | 98 characters |
| Characters | Lowercase letters, numbers, hyphens |
gcloud sql instances describe)deletion_protection — prevents accidental deletionprevent_destroy lifecycle rule for production databasesCloud SQL instance names have a 7-day cooldown after deletion — no exceptions. Always use random suffixes in names, enable deletion_protection, and import existing instances instead of recreating them. This is the #1 gotcha that trips up GCP Terraform users.
Fix Google Cloud IAM binding conflicts in Terraform. Covers authoritative vs non-authoritative bindings, member format, conditions, and import patterns.
Fix Google Cloud network quota exceeded errors in Terraform. Request quota increases, clean up unused VPCs, and optimize shared VPC configurations.
Fix Google Cloud quota exceeded errors in Terraform. Learn to request quota increases, optimize resource usage, and handle regional quota limits.
Fix Azure Cosmos DB global name conflicts in Terraform. Handle unique naming, DNS resolution, and account restoration after soft deletion.