Skip to content

Commit 24ecd03

Browse files
Some infra adjustments (#55)
* masthead draft * sync recent adjustment
1 parent 7fed48a commit 24ecd03

File tree

5 files changed

+104
-33
lines changed

5 files changed

+104
-33
lines changed

infra/tf/.terraform.lock.hcl

Lines changed: 28 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infra/tf/attachments/documentation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Update Frequency: Monthly
88

99
## Dataset Access
1010

11+
[Get Started](https://har.fyi/guides/getting-started/#setting-up-bigquery-to-access-the-http-archive)
12+
1113
The dataset is free and can be publicly accessed via Google BigQuery for fast, scalable analysis or download for offline research. Ideal for developers, analysts, and researchers exploring web performance trends and optimization opportunities.
1214

1315
## Dataset Contents

infra/tf/data_exchange.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ resource "google_bigquery_analytics_hub_listing" "crawl" {
4949
}
5050

5151
resource "google_bigquery_analytics_hub_listing_iam_member" "member" {
52+
for_each = toset(["roles/analyticshub.viewer", "roles/analyticshub.subscriber"])
53+
5254
project = local.project
5355
location = local.location
5456
data_exchange_id = google_bigquery_analytics_hub_data_exchange.default.data_exchange_id
5557
listing_id = google_bigquery_analytics_hub_listing.crawl.listing_id
56-
role = "roles/analyticshub.viewer"
58+
role = each.value
5759
member = "allUsers"
5860
}

infra/tf/function_dataform_trigger.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ resource "google_storage_bucket_object" "dataform_trigger_build" {
1212
source = data.archive_file.dataform-trigger.output_path
1313
}
1414

15-
resource "google_cloudfunctions2_function" "default" {
15+
resource "google_cloudfunctions2_function" "dataform_trigger" {
1616
name = "dataform-trigger"
1717
location = local.region
1818
build_config {
@@ -36,12 +36,12 @@ resource "google_cloudfunctions2_function" "default" {
3636
}
3737

3838
locals {
39-
function_uri = google_cloudfunctions2_function.default.service_config[0].uri
39+
function_uri = google_cloudfunctions2_function.dataform_trigger.service_config[0].uri
4040
}
4141

4242
resource "google_cloud_run_service_iam_member" "member" {
43-
location = google_cloudfunctions2_function.default.location
44-
service = google_cloudfunctions2_function.default.name
43+
location = google_cloudfunctions2_function.dataform_trigger.location
44+
service = google_cloudfunctions2_function.dataform_trigger.name
4545
role = "roles/run.invoker"
4646
member = "serviceAccount:${local.function_identity}"
4747
}

infra/tf/masthead.tf

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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

Comments
 (0)