-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.tf
60 lines (53 loc) · 2.02 KB
/
run.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#Identify the default service identity for Cloud Run
resource "google_project_service_identity" "cloud_run" {
provider = google-beta
project = module.project-services.project_id
service = "run.googleapis.com"
depends_on = [time_sleep.wait_after_apis]
}
#Create a service account for Cloud Run authorization
resource "google_service_account" "cloud_run_invoke" {
project = module.project-services.project_id
account_id = "gemini-demo-app"
display_name = "Cloud Run Auth Service Account"
create_ignore_already_exists = var.create_ignore_service_accounts
depends_on = [
google_project_service_identity.cloud_run]
}
#Assign IAM permissions to the Cloud Run authorization service account
resource "google_project_iam_member" "cloud_run_invoke_roles" {
for_each = toset([
"roles/pubsub.publisher", // Needs to publish Pub/Sub messages to topic
"roles/run.invoker", // Service account role to manage access to app
"roles/aiplatform.user", // Needs to predict from endpoints
"roles/aiplatform.serviceAgent", // Service account role
"roles/iam.serviceAccountUser",
"roles/bigquery.admin", // Create jobs and modify BigQuery tables
"roles/storage.admin", // Read/write GCS files
"roles/iam.serviceAccountTokenCreator",
]
)
project = module.project-services.project_id
role = each.key
member = "serviceAccount:${google_service_account.cloud_run_invoke.email}"
depends_on = [
module.workflow_polling_4,
google_service_account.cloud_run_invoke
]
}
resource "terraform_data" "bld_and_deploy" {
provisioner "local-exec" {
interpreter = ["bash", "-c"]
command = <<-EOT
cd "${path.module}/src/app"
bash bld.sh
bash deploy.sh
EOT
environment = {
PROJECT_ID = module.project-services.project_id
REGION = var.region
OUTPUT_BUCKET = google_storage_bucket.data_source.name
}
}
depends_on = [google_project_iam_member.cloud_run_invoke_roles]
}