-
Notifications
You must be signed in to change notification settings - Fork 15
/
iam.tf
74 lines (64 loc) · 2.61 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
resource "google_service_account" "vault_sa" {
account_id = "vault-server-sa"
display_name = "HashiCorp Vault service account"
}
resource "google_storage_bucket_iam_binding" "bucket_iam_binding" {
bucket = google_storage_bucket.vault_backend.name
role = "roles/storage.objectAdmin"
members = [
"serviceAccount:${google_service_account.vault_sa.email}",
]
}
resource "google_secret_manager_secret_iam_binding" "secret_iam_binding" {
project = var.project_id
secret_id = google_secret_manager_secret.vault_secret.secret_id
role = "roles/secretmanager.secretAccessor"
members = [
"serviceAccount:${google_service_account.vault_sa.email}",
]
}
# https://developer.hashicorp.com/vault/docs/configuration/seal/gcpckms#authentication-permissions
# this provides the cloudkms.cryptoKeyVersions.useToEncrypt and .useToDecrypt perms
resource "google_kms_crypto_key_iam_binding" "auto_unseal_iam_binding_encdec" {
crypto_key_id = google_kms_crypto_key.auto_unseal.id
role = "roles/cloudkms.cryptoKeyEncrypterDecrypter"
members = [
"serviceAccount:${google_service_account.vault_sa.email}",
]
}
# this provides the cloudkms.cryptoKeys.get perm
resource "google_kms_crypto_key_iam_binding" "auto_unseal_iam_binding_viewer" {
crypto_key_id = google_kms_crypto_key.auto_unseal.id
role = "roles/cloudkms.viewer"
members = [
"serviceAccount:${google_service_account.vault_sa.email}",
]
}
#-------------------------------
# Cloud Build service account
#-------------------------------
resource "google_project_iam_member" "builder" {
project = var.project_id
role = "roles/cloudbuild.builds.builder"
member = "serviceAccount:${data.google_project.project.number}[email protected]"
}
resource "google_project_iam_member" "run_admin" {
project = var.project_id
role = "roles/run.admin"
member = "serviceAccount:${data.google_project.project.number}[email protected]"
}
resource "google_project_iam_member" "act_as" {
project = var.project_id
role = "roles/iam.serviceAccountUser"
member = "serviceAccount:${data.google_project.project.number}[email protected]"
}
resource "google_project_iam_member" "gcs_admin" {
project = var.project_id
role = "roles/storage.admin"
member = "serviceAccount:${data.google_project.project.number}[email protected]"
}
resource "google_project_iam_member" "logs_writer" {
project = var.project_id
role = "roles/logging.logWriter"
member = "serviceAccount:${data.google_project.project.number}[email protected]"
}