Fix Terraform Error - GCP Cloud SQL Instance Already Exists
Fix Google Cloud SQL instance name conflicts in Terraform. Handle deletion cooldowns, name reuse restrictions, imports, and instance restoration.
Troubleshooting
Fix Google Cloud IAM binding conflicts in Terraform. Covers authoritative vs non-authoritative bindings, member format, conditions, and import patterns.
The IAM binding already exists — either created manually or by another Terraform resource. Use google_project_iam_member (non-authoritative) instead of google_project_iam_binding (authoritative) to avoid conflicts, or import the existing binding.
Error: Error applying IAM policy for project "my-project":
Error setting IAM policy: googleapi: Error 409:
There were concurrent policy changes. Please retry the whole read-modify-write.Error: Member already has the requested role on resourceGCP Terraform provider has three IAM resource types with different behavior:
| Resource | Behavior | Risk |
|---|---|---|
google_project_iam_policy | Sets entire policy — removes all other bindings | ⚠️ Dangerous |
google_project_iam_binding | Authoritative for one role — removes other members of that role | ⚠️ Careful |
google_project_iam_member | Non-authoritative — adds one member to one role | ✅ Safe |
Multiple Terraform runs or manual Console changes happening at the same time.
Two Terraform resources adding the same member to the same role.
# SAFE — adds a single binding without affecting others
resource "google_project_iam_member" "editor" {
project = var.project_id
role = "roles/editor"
member = "serviceAccount:${google_service_account.terraform.email}"
}
resource "google_project_iam_member" "viewer" {
project = var.project_id
role = "roles/viewer"
member = "user:developer@example.com"
}# Import a member binding
# Format: "project_id role member"
terraform import google_project_iam_member.editor \
"my-project roles/editor serviceAccount:terraform@my-project.iam.gserviceaccount.com"# Add retry logic with lifecycle
resource "google_project_iam_member" "ci_deployer" {
project = var.project_id
role = "roles/run.admin"
member = "serviceAccount:${var.ci_sa_email}"
# Terraform automatically retries concurrent policy conflicts
}# Member format must be one of:
# user:email@example.com
# serviceAccount:sa@project.iam.gserviceaccount.com
# group:group@example.com
# domain:example.com
# BAD
member = "terraform@my-project.iam.gserviceaccount.com"
# GOOD
member = "serviceAccount:terraform@my-project.iam.gserviceaccount.com"iam_member: Adding individual bindings — safe, no side effectsiam_binding: You want to control ALL members of a specific role — removes members not in your configiam_policy: You want to control the ENTIRE IAM policy — removes everything not in your config (dangerous)iam_member (safe) or iam_binding (authoritative)?user:, serviceAccount:, group:)google_project_iam_member — safest option, no side effectsgoogle_project_iam_policy unless you manage ALL IAM for the projectiam_binding and iam_member for the same roleGCP IAM conflicts usually come from using authoritative resources (iam_binding or iam_policy) that overwrite existing bindings. Use google_project_iam_member for safe, non-authoritative additions, verify member format includes the type prefix, and import existing bindings rather than recreating them.
Fix Google Cloud SQL instance name conflicts in Terraform. Handle deletion cooldowns, name reuse restrictions, imports, and instance restoration.
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.