|
| 1 | +# ------------------------------------------------------------ |
| 2 | +# PROJECT-LEVEL BINDINGS |
| 3 | +# ------------------------------------------------------------ |
| 4 | + |
| 5 | +# SA to enable repository deployment |
| 6 | +resource "google_service_account_iam_member" "github_deployer_sa" { |
| 7 | + service_account_id = google_service_account.platform_accounts["github-actions-deployer"].name |
| 8 | + role = "roles/iam.workloadIdentityUser" |
| 9 | + member = "principalSet://iam.googleapis.com/${google_iam_workload_identity_pool.github_pool.name}/attribute.repository/${var.github_repo}" |
| 10 | +} |
| 11 | + |
| 12 | +# Roles for github-actions-deployer |
| 13 | +locals { |
| 14 | + deployer_roles = [ |
| 15 | + "roles/run.developer", |
| 16 | + "roles/workflows.editor", |
| 17 | + "roles/cloudscheduler.admin", |
| 18 | + "roles/iam.serviceAccountUser" |
| 19 | + ] |
| 20 | +} |
| 21 | + |
| 22 | +# Enables to: |
| 23 | +# Deploy Cloud Run containers |
| 24 | +# Deploy pipeline-dispatcher.yml |
| 25 | +# Update the cron job |
| 26 | +# Attach SAs to Cloud Run |
| 27 | +resource "google_project_iam_member" "github_deployer_permissions" { |
| 28 | + for_each = toset(local.deployer_roles) |
| 29 | + project = var.project_id |
| 30 | + role = each.key |
| 31 | + member = "serviceAccount:${google_service_account.platform_accounts["github-actions-deployer"].email}" |
| 32 | +} |
| 33 | + |
| 34 | +# Enable to receive events |
| 35 | +resource "google_project_iam_member" "eventarc_event_receiver" { |
| 36 | + project = var.project_id |
| 37 | + role = "roles/eventarc.eventReceiver" |
| 38 | + member = "serviceAccount:${google_service_account.platform_accounts["eventarc-invoker-sa"].email}" |
| 39 | +} |
| 40 | + |
| 41 | +# Enable Eventarc to trigger Workflows |
| 42 | +resource "google_project_iam_member" "eventarc_workflows_invoker" { |
| 43 | + project = var.project_id |
| 44 | + role = "roles/workflows.invoker" |
| 45 | + member = "serviceAccount:${google_service_account.platform_accounts["eventarc-invoker-sa"].email}" |
| 46 | +} |
| 47 | + |
| 48 | + |
| 49 | +# ------------------------------------------------------------ |
| 50 | +# RESOURCE-LEVEL BINDINGS (Storage & Compute) |
| 51 | +# ------------------------------------------------------------ |
| 52 | + |
| 53 | +# Extractor Bucket Access |
| 54 | +resource "google_storage_bucket_iam_member" "extractor_pipeline_bucket_access" { |
| 55 | + bucket = google_storage_bucket.ops_pipeline_bucket.name |
| 56 | + role = "roles/storage.objectAdmin" |
| 57 | + member = "serviceAccount:${google_service_account.platform_accounts["drive-extractor-sa"].email}" |
| 58 | +} |
| 59 | + |
| 60 | +# Pipeline Runner Bucket Access |
| 61 | +resource "google_storage_bucket_iam_member" "pipeline_runner_archival_access" { |
| 62 | + bucket = google_storage_bucket.ops_archival_bucket.name |
| 63 | + role = "roles/storage.objectAdmin" |
| 64 | + member = "serviceAccount:${google_service_account.platform_accounts["ops-pipeline-sa"].email}" |
| 65 | +} |
| 66 | + |
| 67 | +resource "google_storage_bucket_iam_member" "pipeline_runner_pipeline_access" { |
| 68 | + bucket = google_storage_bucket.ops_pipeline_bucket.name |
| 69 | + role = "roles/storage.objectAdmin" |
| 70 | + member = "serviceAccount:${google_service_account.platform_accounts["ops-pipeline-sa"].email}" |
| 71 | +} |
| 72 | + |
| 73 | + |
| 74 | +# ------------------------------------------------------------ |
| 75 | +# GOOGLE SERVICE AGENTS (Pub/Sub) |
| 76 | +# ------------------------------------------------------------ |
| 77 | + |
| 78 | +# GCS Service Agent email |
| 79 | +data "google_storage_project_service_account" "gcs_account" { |
| 80 | + project = var.project_id |
| 81 | +} |
| 82 | + |
| 83 | +# Enable permssion to publishing to agent |
| 84 | +resource "google_project_iam_member" "gcs_pubsub_publishing" { |
| 85 | + project = var.project_id |
| 86 | + role = "roles/pubsub.publisher" |
| 87 | + member = "serviceAccount:${data.google_storage_project_service_account.gcs_account.email_address}" |
| 88 | +} |
0 commit comments