Skip to content

Commit

Permalink
Add NEG support for cloud_run
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewscwei committed Feb 21, 2023
1 parent 676a768 commit 3246d43
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 51 deletions.
29 changes: 29 additions & 0 deletions cloud_run/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ resource "google_cloud_run_service" "default" {
containers {
image = var.container.image

startup_probe {
failure_threshold = 5
initial_delay_seconds = 10
timeout_seconds = 3
period_seconds = 3

http_get {
path = "/"
http_headers {
name = "Access-Control-Allow-Origin"
value = "*"
}
}
}

dynamic "env" {
for_each = var.container.env

Expand Down Expand Up @@ -72,6 +87,20 @@ resource "google_cloud_run_domain_mapping" "default" {
}
}

resource "google_compute_region_network_endpoint_group" "default" {
count = var.neg == null ? 0 : 1

name = "${google_cloud_run_service.default.name}-neg"
network_endpoint_type = "SERVERLESS"
project = var.project_id
region = google_cloud_run_service.default.location

cloud_run {
service = google_cloud_run_service.default.name
tag = var.neg.tag
}
}

resource "google_cloud_run_service_iam_policy" "default" {
count = length(var.invokers) > 0 ? 1 : 0

Expand Down
5 changes: 5 additions & 0 deletions cloud_run/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ output "name" {
value = google_cloud_run_service.default.name
}

output "neg" {
description = "NEG ID, if available."
value = var.neg == null ? null : google_compute_region_network_endpoint_group.default.id
}

output "public_url" {
description = "Public IP of the Cloud Run service."
value = google_cloud_run_service.default.status[0].url
Expand Down
9 changes: 9 additions & 0 deletions cloud_run/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ variable "name" {
type = string
}

variable "neg" {
default = null
description = "If specified, creates a Network Endpoint Group (NEG) for the Cloud Run service with the contained attributes."
nullable = true
type = object({
tag = optional(string)
})
}

variable "project_id" {
description = "ID of project to create resources in."
type = string
Expand Down
11 changes: 0 additions & 11 deletions cloud_run_neg/main.tf

This file was deleted.

4 changes: 0 additions & 4 deletions cloud_run_neg/outputs.tf

This file was deleted.

26 changes: 0 additions & 26 deletions cloud_run_neg/variables.tf

This file was deleted.

10 changes: 0 additions & 10 deletions cloud_run_neg/versions.tf

This file was deleted.

0 comments on commit 3246d43

Please sign in to comment.