FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit fd271a13 authored by E. Evstafiev's avatar E. Evstafiev :bulb: Committed by E. Kirk
Browse files

feat: add faas Cloud Run and Pub/Sub modules

parent 47feac5f
No related branches found
No related tags found
No related merge requests found
variable "project_id" {
type = string
description = "The Google Cloud project ID where resources will be provisioned."
}
module "pubsub" {
source = "./modules/pubsub"
topic_name = var.topic_name
dead_letter_topic_name = var.dead_letter_topic_name
subscription_name = var.subscription_name
dead_letter_subscription_name = var.dead_letter_subscription_name
}
module "faas_service" {
source = "./modules/faas"
name = var.name
container_image = var.container_image
location = var.location
topic_id = module.pubsub.main_topic_id
project_id = var.project_id
}
resource "google_project_service_identity" "pubsub_sa" {
provider = google-beta
project = var.project_id
service = "pubsub.googleapis.com"
}
resource "google_cloud_run_service" "faas" {
name = var.name
location = var.location
template {
metadata {
annotations = {
"run.googleapis.com/service-account" = "serviceAccount:${google_project_service_identity.pubsub_sa.email}"
}
}
spec {
containers {
image = var.container_image
}
}
}
traffic {
percent = 100
latest_revision = true
}
}
resource "google_eventarc_trigger" "trigger" {
name = "${var.name}-trigger"
location = var.location
transport {
pubsub {
topic = var.topic_id
}
}
destination {
cloud_run_service {
service = google_cloud_run_service.faas.name
}
}
matching_criteria {
attribute = "type"
value = "google.cloud.pubsub.topic.v1.messagePublished"
}
service_account = "serviceAccount:${google_project_service_identity.pubsub_sa.email}"
}
output "service_url" {
value = google_cloud_run_service.faas.status[0].url
description = "The URL on which the Cloud Run service is accessible."
}
variable "name" {
type = string
description = "The name of the Cloud Run service."
}
variable "container_image" {
type = string
description = "The container image to use for the Cloud Run service."
}
variable "location" {
type = string
description = "The location where the service will be deployed."
default = "europe-west2"
}
variable "topic_id" {
type = string
description = "The ID of the Pub/Sub topic that triggers the function."
}
variable "project_id" {
type = string
description = "The ID of the project where the resources will be deployed."
}
resource "google_pubsub_topic" "main" {
name = var.topic_name
}
resource "google_pubsub_topic" "dead_letter" {
name = var.dead_letter_topic_name
}
resource "google_pubsub_subscription" "main" {
name = var.subscription_name
topic = google_pubsub_topic.main.id
dead_letter_policy {
dead_letter_topic = google_pubsub_topic.dead_letter.id
max_delivery_attempts = 5
}
}
resource "google_pubsub_subscription" "dead_letter" {
name = var.dead_letter_subscription_name
topic = google_pubsub_topic.dead_letter.id
}
output "main_topic_id" {
value = google_pubsub_topic.main.id
description = "The ID of the main Pub/Sub topic."
}
output "dead_letter_topic_id" {
value = google_pubsub_topic.dead_letter.id
description = "The ID of the dead letter Pub/Sub topic."
}
variable "topic_name" {
type = string
description = "The name of the Pub/Sub topic."
}
variable "dead_letter_topic_name" {
type = string
description = "The name of the dead letter topic."
}
variable "subscription_name" {
type = string
description = "The name of the subscription."
}
variable "dead_letter_subscription_name" {
type = string
description = "The name of the dead letter subscription."
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment