diff --git a/main.tf b/main.tf index acd99e9e6adb5e2d1ce17553c847df35be5c50ce..956a574894c1db8b6a7fd544402306c6ae08406b 100644 --- a/main.tf +++ b/main.tf @@ -61,6 +61,15 @@ resource "google_cloud_run_v2_service" "faas" { } } + dynamic "volume_mounts" { + for_each = var.mount_cloudsql_instance != null ? [1] : [] + iterator = instance + content { + name = "cloudsql" + mount_path = "/cloudsql" + } + } + resources { limits = { cpu = var.function.cpu_limit @@ -81,6 +90,17 @@ resource "google_cloud_run_v2_service" "faas" { } + dynamic "volumes" { + for_each = var.mount_cloudsql_instance != null ? [1] : [] + iterator = instance + content { + name = "cloudsql" + cloud_sql_instance { + instances = [var.mount_cloudsql_instance] + } + } + } + scaling { min_instance_count = 0 diff --git a/variables.tf b/variables.tf index 52688cc9c0c48d393f2c66b252795c92262dda29..b816ac0229ed0004a313ab9642b52db719c5293e 100644 --- a/variables.tf +++ b/variables.tf @@ -242,6 +242,16 @@ Defaults to 200. EOI } +variable "mount_cloudsql_instance" { + description = <<EOI +Mount a single CloudSQL instance into the FaaS service container. This value +should be the Cloud SQL instance connection name, for example +"example-devel-e662dd2b:europe-west2:sql-6e1dd60b". +EOI + type = string + default = null +} + # Cloud Run pre-deploy job variables variable "enable_pre_deploy_job" { description = <<EOI