|
| 1 | +# Documentation: |
| 2 | +# https://docs.mastheadata.com/saas-manual-resource-creation-google-cloud-+-bigquery |
| 3 | + |
| 4 | +# 1. Create Pub/Sub resources |
| 5 | +resource "google_pubsub_topic" "masthead_topic" { |
| 6 | + project = local.project |
| 7 | + name = "masthead-topic" |
| 8 | +} |
| 9 | + |
| 10 | +resource "google_pubsub_subscription" "masthead_agent_subscription" { |
| 11 | + project = local.project |
| 12 | + ack_deadline_seconds = 60 |
| 13 | + expiration_policy { |
| 14 | + ttl = "2678400s" |
| 15 | + } |
| 16 | + message_retention_duration = "604800s" |
| 17 | + name = "masthead-agent-subscription" |
| 18 | + topic = "projects/${local.project}/topics/masthead-topic" |
| 19 | +} |
| 20 | + |
| 21 | +# 2. Create Logs Router |
| 22 | +resource "google_logging_project_sink" "masthead_agent_sink" { |
| 23 | + destination = "pubsub.googleapis.com/projects/${local.project}/topics/masthead-topic" |
| 24 | + filter = <<EOT |
| 25 | + protoPayload.methodName="google.cloud.bigquery.v2.JobService.InsertJob" OR "google.cloud.bigquery.v2.TableService.InsertTable" OR "google.cloud.bigquery.v2.JobService.Query" OR |
| 26 | + resource.type="bigquery_dataset" OR "bigquery_project" OR |
| 27 | + (resource.type="bigquery_table" AND protoPayload.methodName!="google.cloud.bigquery.storage.v1.BigQueryWrite.AppendRows") OR |
| 28 | + (resource.type="bigquery_table" AND protoPayload.methodName="google.cloud.bigquery.storage.v1.BigQueryWrite.AppendRows" AND sample(insertId, 0.0001)) |
| 29 | + EOT |
| 30 | + name = "masthead-agent-sink" |
| 31 | +} |
| 32 | + |
| 33 | + |
| 34 | +resource "google_project_iam_member" "masthead_pubsub_publisherer_member" { |
| 35 | + role = "roles/pubsub.publisher" |
| 36 | + member = "serviceAccount:[email protected]" |
| 37 | + project = local.project |
| 38 | +} |
| 39 | + |
| 40 | +# 3. Grant Masthead Service Account roles |
| 41 | +resource "google_project_iam_custom_role" "masthead_bq_meta_reader" { |
| 42 | + project = local.project |
| 43 | + description = "Masthead BigQuery assets metadata reader" |
| 44 | + permissions = ["bigquery.datasets.get", "bigquery.tables.get", "bigquery.tables.list"] |
| 45 | + role_id = "masthead_bq_meta_reader" |
| 46 | + stage = "GA" |
| 47 | + title = "masthead_bq_meta_reader" |
| 48 | +} |
| 49 | + |
| 50 | +resource "google_project_iam_binding" "masthead_bq_meta_reader_binding" { |
| 51 | + role = google_project_iam_custom_role.masthead_bq_meta_reader.id |
| 52 | + members = [ "serviceAccount:[email protected]"] |
| 53 | + project = local.project |
| 54 | +} |
| 55 | + |
| 56 | +resource "google_project_iam_member" "masthead_pubsub_subscriber_member" { |
| 57 | + role = "roles/pubsub.subscriber" |
| 58 | + member = "serviceAccount:[email protected]" |
| 59 | + project = local.project |
| 60 | +} |
| 61 | + |
| 62 | +# 4. Grant Masthead Service Account to quickly onboard from retrospective data |
| 63 | +resource "google_project_iam_binding" "private_logs_viewer_binding" { |
| 64 | + role = "roles/logging.privateLogViewer" |
| 65 | + members = [ "serviceAccount:[email protected]"] |
| 66 | + project = local.project |
| 67 | +} |
0 commit comments