Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update from functions to functions2 #196

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 56 additions & 30 deletions terraform/modules/autoscaler-functions/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -96,46 +96,72 @@ 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_account = var.build_sa_id
}

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
build_service_account = var.build_sa_id

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_account = var.build_sa_id
}

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
build_service_account = var.build_sa_id

lifecycle {
ignore_changes = [max_instances]
ignore_changes = [
build_config[0].max_instance_count
]
}
}
46 changes: 29 additions & 17 deletions terraform/modules/forwarder/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,37 @@ 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_account = google_service_account.build_sa.id
}
environment_variables = {
POLLER_TOPIC = var.target_pubsub_topic

service_config {
available_memory = "256M"
ingress_settings = "ALLOW_INTERNAL_AND_GCLB"
service_account_email = google_service_account.forwarder_sa.email
}
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
build_service_account = google_service_account.build_sa.id

event_trigger {
event_type = "google.cloud.pubsub.topic.v1.messagePublished"
pubsub_topic = google_pubsub_topic.forwarder_topic.id
}

depends_on = [
time_sleep.wait_for_iam,
google_pubsub_topic_iam_member.forwader_pubsub_sub_binding
Expand Down
Loading