Skip to content

Commit

Permalink
update: from functions to functions2
Browse files Browse the repository at this point in the history
  • Loading branch information
a5chin committed Jan 30, 2024
1 parent 2568952 commit 92a3ff3
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 44 deletions.
82 changes: 54 additions & 28 deletions terraform/modules/autoscaler-functions/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -82,44 +82,70 @@ resource "google_storage_bucket_object" "gcs_functions_source" {
source = data.archive_file.local_source.output_path
}

resource "google_cloudfunctions_function" "poller_function" {
name = "tf-poller-function"
project = var.project_id
region = var.region
ingress_settings = "ALLOW_INTERNAL_AND_GCLB"
available_memory_mb = "256"
entry_point = "checkSpannerScaleMetricsPubSub"
runtime = "nodejs${var.nodejs_version}"
resource "google_cloudfunctions2_function" "poller_function" {
name = "tf-poller-function"
project = var.project_id
location = var.region

build_config {
runtime = "nodejs${var.nodejs_version}"
entry_point = "checkSpannerScaleMetricsPubSub"
source {
storage_source {
bucket = google_storage_bucket.bucket_gcf_source.name
object = google_storage_bucket_object.gcs_functions_source.name
}
}
}

service_config {
available_memory = "256M"
ingress_settings = "ALLOW_INTERNAL_AND_GCLB"
service_account_email = var.poller_sa_email
}

event_trigger {
event_type = "google.pubsub.topic.publish"
resource = google_pubsub_topic.poller_topic.id
event_type = "google.cloud.pubsub.topic.v1.messagePublished"
pubsub_topic = google_pubsub_topic.poller_topic.id
}
source_archive_bucket = google_storage_bucket.bucket_gcf_source.name
source_archive_object = google_storage_bucket_object.gcs_functions_source.name
service_account_email = var.poller_sa_email

lifecycle {
ignore_changes = [max_instances]
ignore_changes = [
build_config[0].max_instance_count
]
}
}

resource "google_cloudfunctions_function" "scaler_function" {
name = "tf-scaler-function"
project = var.project_id
region = var.region
ingress_settings = "ALLOW_INTERNAL_AND_GCLB"
available_memory_mb = "256"
entry_point = "scaleSpannerInstancePubSub"
runtime = "nodejs${var.nodejs_version}"
resource "google_cloudfunctions2_function" "scaler_function" {
name = "tf-scaler-function"
project = var.project_id
location = var.region

build_config {
runtime = "nodejs${var.nodejs_version}"
entry_point = "scaleSpannerInstancePubSub"
source {
storage_source {
bucket = google_storage_bucket.bucket_gcf_source.name
object = google_storage_bucket_object.gcs_functions_source.name
}
}
}

service_config {
available_memory = "256M"
ingress_settings = "ALLOW_INTERNAL_AND_GCLB"
service_account_email = var.scaler_sa_email
}

event_trigger {
event_type = "google.pubsub.topic.publish"
resource = google_pubsub_topic.scaler_topic.id
event_type = "google.cloud.pubsub.topic.v1.messagePublished"
pubsub_topic = google_pubsub_topic.scaler_topic.id
}
source_archive_bucket = google_storage_bucket.bucket_gcf_source.name
source_archive_object = google_storage_bucket_object.gcs_functions_source.name
service_account_email = var.scaler_sa_email

lifecycle {
ignore_changes = [max_instances]
ignore_changes = [
build_config[0].max_instance_count
]
}
}
43 changes: 27 additions & 16 deletions terraform/modules/forwarder/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,33 @@ resource "google_storage_bucket_object" "gcs_functions_forwarder_source" {
source = data.archive_file.local_forwarder_source.output_path
}

resource "google_cloudfunctions_function" "forwarder_function" {
name = "tf-forwarder-function"
project = var.project_id
region = var.region
ingress_settings = "ALLOW_INTERNAL_AND_GCLB"
available_memory_mb = "256"
entry_point = "forwardFromPubSub"
runtime = "nodejs${var.nodejs_version}"
event_trigger {
event_type = "google.pubsub.topic.publish"
resource = google_pubsub_topic.forwarder_topic.id
resource "google_cloudfunctions2_function" "forwarder_function" {
name = "tf-forwarder-function"
project = var.project_id
location = var.region

build_config {
runtime = "nodejs${var.nodejs_version}"
entry_point = "forwardFromPubSub"
environment_variables = {
POLLER_TOPIC = var.target_pubsub_topic
}
source {
storage_source {
bucket = google_storage_bucket.bucket_gcf_source.name
object = google_storage_bucket_object.gcs_functions_forwarder_source.name
}
}
}

service_config {
available_memory = "256M"
ingress_settings = "ALLOW_INTERNAL_AND_GCLB"
service_account_email = google_service_account.forwarder_sa.email
}
environment_variables = {
POLLER_TOPIC = var.target_pubsub_topic

event_trigger {
event_type = "google.cloud.pubsub.topic.v1.messagePublished"
pubsub_topic = google_pubsub_topic.forwarder_topic.id
}
source_archive_bucket = google_storage_bucket.bucket_gcf_source.name
source_archive_object = google_storage_bucket_object.gcs_functions_forwarder_source.name
service_account_email = google_service_account.forwarder_sa.email
}

0 comments on commit 92a3ff3

Please sign in to comment.