terraform-example/components/cloud-function/main.tf (31 lines of code) (raw):

terraform { required_version = ">= 1" backend "gcs" {} } provider "google" {} resource "google_storage_bucket" "bucket" { name = "${var.name}-cloud-function-source" location = "US" } resource "google_storage_bucket_object" "archive" { name = "index.zip" bucket = google_storage_bucket.bucket.name source = "./index.zip" } resource "google_cloudfunctions_function" "function" { name = var.name description = "Hello world function" runtime = "nodejs16" available_memory_mb = 128 source_archive_bucket = google_storage_bucket.bucket.name source_archive_object = google_storage_bucket_object.archive.name trigger_http = true entry_point = "helloGET" } # IAM entry for all users to invoke the function resource "google_cloudfunctions_function_iam_member" "invoker" { project = google_cloudfunctions_function.function.project region = google_cloudfunctions_function.function.region cloud_function = google_cloudfunctions_function.function.name role = "roles/cloudfunctions.invoker" member = "allUsers" }