Fix Terraform Error - GCP Service API Not Enabled
Fix googleapi 403 'has not been used in project' or 'is disabled' errors in Terraform. Enable GCP APIs with google_project_service and fix billing/quota issues.
DevOps
Fix 'resource already exists' errors when creating GCP firewall rules in Terraform. Import existing rules, handle naming conflicts, and manage default...
A firewall rule with that name already exists in the GCP project. Firewall rule names are unique per project. Import it with terraform import, use a unique name, or delete the existing rule.
Error: Error creating Firewall: googleapi: Error 409:
The resource 'projects/my-project/global/firewalls/allow-http'
already exists, alreadyExistsdefault-allow-ssh, default-allow-icmp, etc.)# Import format: projects/PROJECT/global/firewalls/RULE_NAME
terraform import google_compute_firewall.allow_http \
projects/my-project/global/firewalls/allow-httpresource "google_compute_firewall" "allow_http" {
name = "${var.project}-${var.environment}-allow-http"
network = google_compute_network.main.name
allow {
protocol = "tcp"
ports = ["80", "443"]
}
source_ranges = ["0.0.0.0/0"]
target_tags = ["http-server"]
}# List existing rules
gcloud compute firewall-rules list --project my-project
# Delete default rules if you want Terraform to manage everything
gcloud compute firewall-rules delete default-allow-ssh \
--project my-project --quietOr import them:
terraform import google_compute_firewall.default_ssh \
projects/my-project/global/firewalls/default-allow-sshWhen you create a default network, GCP auto-creates:
| Rule Name | Allows | Source |
|---|---|---|
default-allow-ssh | TCP 22 | 0.0.0.0/0 |
default-allow-rdp | TCP 3389 | 0.0.0.0/0 |
default-allow-icmp | ICMP | 0.0.0.0/0 |
default-allow-internal | All | 10.128.0.0/9 |
Best practice: Use auto_create_subnetworks = false to avoid default rules, then create your own.
gcloud compute firewall-rules list)auto_create_subnetworks = false for custom VPCs?GCP firewall rule names are unique per project. Import existing rules, use environment-prefixed names, and create custom VPCs with auto_create_subnetworks = false to avoid conflicts with default rules.
Fix googleapi 403 'has not been used in project' or 'is disabled' errors in Terraform. Enable GCP APIs with google_project_service and fix billing/quota issues.
Fix Docker provider connection refused errors in Terraform. Covers Docker daemon socket permissions, TLS configuration, and remote host setup.
Fix terraform CloudWatch Log Group ResourceAlreadyExistsException. Import orphaned log groups, prevent Lambda auto-creation
Fix terraform import errors when a resource already exists in state. Covers state rm, state show, reimport workflow, import blocks