-
Notifications
You must be signed in to change notification settings - Fork 5
/
iam.tf
92 lines (70 loc) · 2.48 KB
/
iam.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
locals {
google_cloud_build_default_service_account = "${data.google_project.project.number}@cloudbuild.gserviceaccount.com"
}
resource "google_service_account" "cloud_run_service_account" {
account_id = var.cloud_run_service_account_name
display_name = "Cloud Run Service Account"
}
resource "google_storage_bucket_iam_binding" "storage_object_admin" {
bucket = var.gcs_bucket_name
role = "roles/storage.objectAdmin"
members = [
"serviceAccount:${google_service_account.cloud_run_service_account.email}",
]
depends_on = [google_service_account.cloud_run_service_account]
}
resource "google_project_iam_binding" "secret_manager_secret_accessor" {
project = var.project_id
role = "roles/secretmanager.secretAccessor"
members = [
"serviceAccount:${google_service_account.cloud_run_service_account.email}",
"serviceAccount:${local.google_cloud_build_default_service_account}"
]
depends_on = [
google_project_service.gcp_services,
google_service_account.cloud_run_service_account
]
}
resource "google_project_iam_binding" "run_invoker" {
project = var.project_id
role = "roles/run.invoker"
members = [
"serviceAccount:${google_service_account.cloud_run_service_account.email}",
]
depends_on = [google_service_account.cloud_run_service_account]
}
resource "google_project_iam_binding" "run_admin" {
project = var.project_id
role = "roles/run.admin"
members = [
"serviceAccount:${local.google_cloud_build_default_service_account}"
]
depends_on = [google_project_service.gcp_services]
}
resource "google_project_iam_binding" "cloudsql_client" {
project = var.project_id
role = "roles/cloudsql.client"
members = [
"serviceAccount:${google_service_account.cloud_run_service_account.email}",
]
depends_on = [google_project_service.gcp_services]
}
resource "google_project_iam_binding" "cloudsql_admin" {
project = var.project_id
role = "roles/cloudsql.admin"
members = [
"serviceAccount:${local.google_cloud_build_default_service_account}"
]
depends_on = [
google_service_account.cloud_run_service_account,
google_project_service.gcp_services
]
}
resource "google_service_account_iam_binding" "admin-account-iam" {
service_account_id = google_service_account.cloud_run_service_account.name
role = "roles/iam.serviceAccountUser"
members = [
"serviceAccount:${local.google_cloud_build_default_service_account}"
]
depends_on = [google_project_service.gcp_services]
}