Skip to content

Commit 9c4b93f

Browse files
Add private service access for Redis instance
Fixes the "Google private service access is not enabled" error by: - Adding google_compute_global_address for VPC peering - Creating google_service_networking_connection - Updating Redis instance to depend on the connection 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 3a1b07f commit 9c4b93f

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

terraform/main.tf

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@ resource "google_compute_subnetwork" "subnet" {
4848
network = google_compute_network.vpc.id
4949
}
5050

51+
# Allocate IP address range for private service access
52+
resource "google_compute_global_address" "private_ip_address" {
53+
name = "${var.project_name}-private-ip"
54+
purpose = "VPC_PEERING"
55+
address_type = "INTERNAL"
56+
prefix_length = 16
57+
network = google_compute_network.vpc.id
58+
}
59+
60+
# Create private VPC connection for private service access
61+
resource "google_service_networking_connection" "private_vpc_connection" {
62+
network = google_compute_network.vpc.id
63+
service = "servicenetworking.googleapis.com"
64+
reserved_peering_ranges = [google_compute_global_address.private_ip_address.name]
65+
depends_on = [google_project_service.required_apis]
66+
}
67+
5168
# VPC connector for Cloud Run to access Redis
5269
resource "google_vpc_access_connector" "connector" {
5370
name = "pe-api-v2-alpha-vpc"
@@ -68,7 +85,10 @@ resource "google_redis_instance" "redis" {
6885
authorized_network = google_compute_network.vpc.id
6986
connect_mode = "PRIVATE_SERVICE_ACCESS"
7087

71-
depends_on = [google_project_service.required_apis]
88+
depends_on = [
89+
google_project_service.required_apis,
90+
google_service_networking_connection.private_vpc_connection
91+
]
7292
}
7393

7494
# Artifact Registry repository for Docker images

0 commit comments

Comments
 (0)