diff --git a/main.tf b/main.tf index 2e80964..2a62e45 100644 --- a/main.tf +++ b/main.tf @@ -86,6 +86,18 @@ resource "google_pubsub_topic_iam_member" "pull_topic_binding" { ] } +resource "google_pubsub_topic_iam_member" "bigquery_topic_binding" { + for_each = var.create_topic ? { for i in var.bigquery_subscriptions : i.name => i if try(i.dead_letter_topic, "") != "" } : {} + + project = var.project_id + topic = each.value.dead_letter_topic + role = "roles/pubsub.publisher" + member = "serviceAccount:${local.pubsub_svc_account_email}" + depends_on = [ + google_pubsub_topic.topic, + ] +} + resource "google_pubsub_subscription_iam_member" "pull_subscription_binding" { for_each = var.create_subscriptions ? { for i in var.pull_subscriptions : i.name => i if try(i.dead_letter_topic, "") != "" } : {} @@ -110,6 +122,18 @@ resource "google_pubsub_subscription_iam_member" "push_subscription_binding" { ] } +resource "google_pubsub_subscription_iam_member" "bigquery_subscription_binding" { + for_each = var.create_subscriptions ? { for i in var.bigquery_subscriptions : i.name => i if try(i.dead_letter_topic, "") != "" } : {} + + project = var.project_id + subscription = each.value.name + role = "roles/pubsub.subscriber" + member = "serviceAccount:${local.pubsub_svc_account_email}" + depends_on = [ + google_pubsub_subscription.bigquery_subscriptions, + ] +} + resource "google_pubsub_topic" "topic" { count = var.create_topic ? 1 : 0 project = var.project_id