diff --git a/terraform/main.tf b/terraform/main.tf index 7ba0b9ee48..b0ec60ac9c 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -228,7 +228,7 @@ resource "google_cloud_run_v2_service" "pudl-superset" { volumes { name = "cloudsql" cloud_sql_instance { - instances = ["catalyst-cooperative-pudl:us-central1:superset-database"] + instances = ["catalyst-cooperative-pudl:us-central1:superset-database", "catalyst-cooperative-pudl:us-central1:pudl-usage-metrics-db"] } } } @@ -396,3 +396,47 @@ resource "google_service_account_iam_member" "gce-default-account-iam" { role = "roles/iam.serviceAccountUser" member = "serviceAccount:345950277072@cloudbuild.gserviceaccount.com" } + +resource "google_secret_manager_secret" "pudl_usage_metrics_db_connection_string" { + secret_id = "pudl-usage-metrics-db-connection-string" + replication { + auto {} + } +} + +resource "google_storage_bucket" "pudl_usage_metrics_archive_bucket" { + name = "pudl-usage-metrics-archives.catalyst.coop" + location = "US" + storage_class = "STANDARD" + + uniform_bucket_level_access = true +} + +resource "google_service_account" "usage_metrics_archiver" { + account_id = "usage-metrics-archiver" + display_name = "PUDL usage metrics archiver github action service account" +} + +resource "google_storage_bucket_iam_member" "usage_metrics_archiver_gcs_iam" { + for_each = toset(["roles/storage.objectCreator", "roles/storage.objectViewer"]) + + bucket = google_storage_bucket.pudl_usage_metrics_archive_bucket.name + role = each.key + member = "serviceAccount:${google_service_account.usage_metrics_archiver.email}" +} + +resource "google_storage_bucket_iam_member" "usage_metrics_etl_gcs_iam" { + for_each = toset(["roles/storage.legacyBucketReader", "roles/storage.objectViewer"]) + + bucket = google_storage_bucket.pudl_usage_metrics_archive_bucket.name + role = each.key + member = "serviceAccount:pudl-usage-metrics-etl@catalyst-cooperative-pudl.iam.gserviceaccount.com" +} + +resource "google_storage_bucket_iam_member" "usage_metrics_etl_s3_logs_gcs_iam" { + for_each = toset(["roles/storage.legacyBucketReader", "roles/storage.objectViewer"]) + + bucket = "pudl-s3-logs.catalyst.coop" + role = each.key + member = "serviceAccount:pudl-usage-metrics-etl@catalyst-cooperative-pudl.iam.gserviceaccount.com" +}