terraform-google-modules/terraform-google-scheduled-function

Ability to use existing Cloud Scheduler

ocervell opened this issue · 5 comments

It would be nice if we could pass in an existing Cloud Scheduler job instead of creating one every time: this is useful when we have multiple functions that need to be synchronized (i.e: triggered by the same Cloud Scheduler job).

Is that something doable ?

It could be done. We'd probably want to do it by providing an output (from this module) as an input (into an additional instance of this module).

@morgante, @aaron-lane
Created 2 draft pull requests.
The first one #26 doesn’t pass tests, because it requires adding enable variable to pubsub module.
The second draft #27 passes all tests.
But I don’t think we need to change anything in the scheduled function module, because the original issue can be solved by creating multiple event-function module instances with a single scheduler and using the same pubsub topic name as follows:


module "pubsub_scheduleder” {
  providers = {
    google = google-beta
  }

  source                    = "../../"
  project_id                = var.project_id
  job_name                  = "pubsub-example"
  job_schedule              = "*/1 * * * *"
  function_entry_point      = "doSomething"
  function_source_directory = "${path.module}/function_source"
  function_name             = "testfunction-1"
  region                    = var.region
  topic_name                = "pubsub-1"
}

module “event_function_2” {
  source  = "terraform-google-modules/event-function/google"
  version = "~> 1.1"

  entry_point =  "doSomething2"
  event_trigger = {
    event_type = "google.pubsub.topic.publish"
    resource   = "pubsub-1"
  }
  name             = "testfunction-2"
  project_id       = var.project_id
  region           = var.region
  runtime          = "nodejs8”
  source_directory =  "${path.module}/function_source_2"


}

module “event_function_3” {
  source  = "terraform-google-modules/event-function/google"
  version = "~> 1.1"

  entry_point =  "doSomething3”
  event_trigger = {
    event_type = "google.pubsub.topic.publish"
    resource   = "pubsub-1"
  }
  name             = "testfunction-3”
  project_id       = var.project_id
  region           = var.region
  runtime          = "nodejs8”
  source_directory =  "${path.module}/function_source_3”


}

@ocervell does @omazin's proposal satisfy your use case?

I think #26 is much more user-friendly (modifications to the existing module) than #27 (using a separate module without the Cloud Scheduler / PubSub topic resources), so I would prefer we continue the work on #26 and close #27.

Fixed by #26.