Skip to content

Commit 6c466f4

Browse files
committed
add private subnet access
1 parent d5a33ff commit 6c466f4

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ No modules.
169169
| [google_cloud_run_domain_mapping.main_app](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloud_run_domain_mapping) | resource |
170170
| [google_cloud_run_service.main_app](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloud_run_service) | resource |
171171
| [google_cloud_run_service_iam_member.main_app_public](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloud_run_service_iam_member) | resource |
172+
| [google_cloud_run_service_iam_member.main_app_subnet](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloud_run_service_iam_member) | resource |
172173
| [google_compute_firewall.allow_health_checks](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_firewall) | resource |
173174
| [google_compute_firewall.allow_internal](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_firewall) | resource |
174175
| [google_compute_global_address.private_ip_address](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_global_address) | resource |

cloud-run.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,21 @@ resource "google_cloud_run_service_iam_member" "main_app_public" {
249249
member = "allUsers"
250250
}
251251

252+
# IAM policy to allow subnet access
253+
resource "google_cloud_run_service_iam_member" "main_app_subnet" {
254+
location = google_cloud_run_service.main_app.location
255+
project = google_cloud_run_service.main_app.project
256+
service = google_cloud_run_service.main_app.name
257+
role = "roles/run.invoker"
258+
member = "allUsers"
259+
260+
condition {
261+
title = "Subnet access"
262+
description = "Allow access from the private subnet"
263+
expression = "inIpRange(origin.ip, \"${var.private_subnet_cidr}\")"
264+
}
265+
}
266+
252267
# Domain mapping for the hrafnar application (if Cloudflare DNS is enabled)
253268
# Domain mapping for the application
254269
resource "google_cloud_run_domain_mapping" "main_app" {

0 commit comments

Comments
 (0)