Skip to content

Commit 22f0e5e

Browse files
committed
replace VPC connector with superior direct VPC egress
1 parent e7e2cac commit 22f0e5e

5 files changed

Lines changed: 7 additions & 38 deletions

File tree

cloud-run.tf

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ resource "google_cloud_run_service" "main_app" {
1111
"autoscaling.knative.dev/minScale" = tostring(var.app_min_instances)
1212
"autoscaling.knative.dev/maxScale" = tostring(var.app_max_instances)
1313
"run.googleapis.com/execution-environment" = "gen2"
14-
# VPC connector annotation (if enabled)
15-
"run.googleapis.com/vpc-access-connector" = var.enable_vpc_connector ? google_vpc_access_connector.main[0].name : null
16-
"run.googleapis.com/vpc-access-egress" = var.enable_vpc_connector ? "private-ranges-only" : null
1714
# CPU allocation
18-
"run.googleapis.com/cpu-throttling" = "false"
15+
"run.googleapis.com/cpu-throttling" = "false",
16+
# Direct VPC Egress
17+
"run.googleapis.com/network-interfaces" = jsonencode([{
18+
"network" = google_compute_network.main.id
19+
"subnetwork" = google_compute_subnetwork.private.id
20+
"tags" = ["cloud-run"]
21+
}])
1922
}, {
2023
# Config hash annotations to force new revisions when config changes
2124
for name, config in var.app_config_files : "config.hash.${name}" => sha256(config.content)

locals.tf

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ locals {
3333
private_subnet_name = "${local.resource_prefix}-subnet-${random_id.network_suffix.hex}"
3434
nat_gateway_name = "${local.resource_prefix}-nat-${random_id.network_suffix.hex}"
3535
router_name = "${local.resource_prefix}-router-${random_id.network_suffix.hex}"
36-
# VPC connector name must be <= 25 chars and match ^[a-z][-a-z0-9]{0,23}[a-z0-9]$
37-
# Add random suffix to avoid naming collisions
38-
vpc_connector_name = length("${local.resource_prefix}-conn-${random_id.network_suffix.hex}") <= 25 ? "${local.resource_prefix}-conn-${random_id.network_suffix.hex}" : "${substr(local.resource_prefix, 0, 11)}-conn-${random_id.network_suffix.hex}"
3936

4037
# Cloud Run service names
4138
main_app_service_name = "${local.resource_prefix}-app"

networking.tf

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,6 @@ resource "google_compute_router_nat" "main" {
4343
}
4444
}
4545

46-
# VPC Connector for Cloud Run to VPC communication
47-
resource "google_vpc_access_connector" "main" {
48-
count = var.enable_vpc_connector ? 1 : 0
49-
name = local.vpc_connector_name
50-
region = var.region
51-
project = var.project_id
52-
53-
subnet {
54-
name = google_compute_subnetwork.private.name
55-
project_id = var.project_id
56-
}
57-
58-
# Minimum instances for the connector
59-
min_instances = 2
60-
max_instances = 3
61-
62-
# Machine type for the connector
63-
machine_type = "e2-micro"
64-
}
65-
6646
# Firewall rule to allow health checks for Cloud Run
6747
resource "google_compute_firewall" "allow_health_checks" {
6848
name = "${local.resource_prefix}-allow-health-checks"

outputs.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ output "private_subnet_name" {
5353
value = google_compute_subnetwork.private.name
5454
}
5555

56-
output "vpc_connector_id" {
57-
description = "ID of the VPC connector (if enabled)"
58-
value = var.enable_vpc_connector ? google_vpc_access_connector.main[0].id : null
59-
}
60-
6156
# Service Account Outputs
6257
output "hrafnar_app_service_account_email" {
6358
description = "Email of the hrafnar application service account"

variables.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,6 @@ variable "log_level" {
426426

427427
# Security Configuration
428428

429-
variable "enable_vpc_connector" {
430-
description = "Enable VPC Connector for Cloud Run to VPC communication"
431-
type = bool
432-
default = true
433-
}
434-
435429
# Resource Tags
436430
variable "labels" {
437431
description = "Labels to apply to all resources"

0 commit comments

Comments
 (0)