Skip to content

Commit

Permalink
fix(tf): don't use default service accounts in eventarc
Browse files Browse the repository at this point in the history
  • Loading branch information
nielm committed Oct 25, 2024
1 parent 5c6f0a9 commit d20dfa3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
22 changes: 10 additions & 12 deletions terraform/modules/autoscaler-functions/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ data "google_project" "project" {

}

locals {
eventarc_sa = "${data.google_project.project.number}[email protected]"
}

// PubSub

resource "google_pubsub_topic" "poller_topic" {
Expand Down Expand Up @@ -129,9 +125,10 @@ resource "google_cloudfunctions2_function" "poller_function" {
}

event_trigger {
event_type = "google.cloud.pubsub.topic.v1.messagePublished"
pubsub_topic = google_pubsub_topic.poller_topic.id
retry_policy = "RETRY_POLICY_RETRY"
event_type = "google.cloud.pubsub.topic.v1.messagePublished"
pubsub_topic = google_pubsub_topic.poller_topic.id
retry_policy = "RETRY_POLICY_RETRY"
service_account_email = var.poller_sa_email
}

lifecycle {
Expand Down Expand Up @@ -165,9 +162,10 @@ resource "google_cloudfunctions2_function" "scaler_function" {
}

event_trigger {
event_type = "google.cloud.pubsub.topic.v1.messagePublished"
pubsub_topic = google_pubsub_topic.scaler_topic.id
retry_policy = "RETRY_POLICY_RETRY"
event_type = "google.cloud.pubsub.topic.v1.messagePublished"
pubsub_topic = google_pubsub_topic.scaler_topic.id
retry_policy = "RETRY_POLICY_RETRY"
service_account_email = var.scaler_sa_email
}

lifecycle {
Expand All @@ -182,13 +180,13 @@ resource "google_cloud_run_service_iam_member" "cloud_run_poller_invoker" {
location = google_cloudfunctions2_function.poller_function.location
service = google_cloudfunctions2_function.poller_function.name
role = "roles/run.invoker"
member = "serviceAccount:${local.eventarc_sa}"
member = "serviceAccount:${var.poller_sa_email}"
}

resource "google_cloud_run_service_iam_member" "cloud_run_scaler_invoker" {
project = google_cloudfunctions2_function.scaler_function.project
location = google_cloudfunctions2_function.scaler_function.location
service = google_cloudfunctions2_function.scaler_function.name
role = "roles/run.invoker"
member = "serviceAccount:${local.eventarc_sa}"
member = "serviceAccount:${var.scaler_sa_email}"
}
13 changes: 5 additions & 8 deletions terraform/modules/forwarder/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ data "google_project" "project" {

}

locals {
eventarc_sa = "${data.google_project.project.number}[email protected]"
}

resource "google_service_account" "build_sa" {
project = var.project_id
account_id = "build-sa"
Expand Down Expand Up @@ -125,9 +121,10 @@ resource "google_cloudfunctions2_function" "forwarder_function" {
}

event_trigger {
event_type = "google.cloud.pubsub.topic.v1.messagePublished"
pubsub_topic = google_pubsub_topic.forwarder_topic.id
retry_policy = "RETRY_POLICY_RETRY"
event_type = "google.cloud.pubsub.topic.v1.messagePublished"
pubsub_topic = google_pubsub_topic.forwarder_topic.id
retry_policy = "RETRY_POLICY_RETRY"
service_account_email = google_service_account.forwarder_sa.email
}

depends_on = [
Expand All @@ -141,5 +138,5 @@ resource "google_cloud_run_service_iam_member" "cloud_run_forwarder_invoker" {
location = google_cloudfunctions2_function.forwarder_function.location
service = google_cloudfunctions2_function.forwarder_function.name
role = "roles/run.invoker"
member = "serviceAccount:${local.eventarc_sa}"
member = google_service_account.forwarder_sa.member
}

0 comments on commit d20dfa3

Please sign in to comment.