-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiam.tf
175 lines (157 loc) · 7.98 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// service account for truefoundry platform feature
resource "google_service_account" "truefoundry_platform_feature_service_account" {
account_id = local.serviceaccount_name
project = var.project
display_name = "Terraform-managed truefoundry platform service account"
description = "Truefoundry platform user with access to artifact registry, blob storage and secrets manager"
}
// custom role for secret manager
resource "google_project_iam_custom_role" "truefoundry_platform_feature_secret_manager_role" {
count = var.feature_secrets_enabled ? 1 : 0
project = var.project
role_id = trimsuffix(substr(replace("${local.truefoundry_platform_resources}_bucket_secret_manager_role", "-", "_"), 0, 64), "_")
title = trimsuffix(substr("truefoundry/${var.cluster_name}/platform-features/${local.truefoundry_platform_resources}_bucket_secret_manager_role", 0, 100), "_")
description = "TrueFoundry platform feature role to manage secrets in GSM"
permissions = [
"secretmanager.secrets.get",
"secretmanager.secrets.list",
"secretmanager.secrets.create",
"secretmanager.secrets.delete",
"secretmanager.secrets.update",
"secretmanager.versions.access",
"secretmanager.versions.list",
"secretmanager.versions.get",
"secretmanager.versions.add",
"secretmanager.versions.destroy",
"resourcemanager.projects.get",
]
}
resource "google_project_iam_member" "truefoundry_platform_feature_secret_manager_role_binding" {
count = var.feature_secrets_enabled ? 1 : 0
project = var.project
role = google_project_iam_custom_role.truefoundry_platform_feature_secret_manager_role[count.index].id
member = "serviceAccount:${google_service_account.truefoundry_platform_feature_service_account.email}"
condition {
title = "Condition to allow access to secrets starting with 'tfy'"
description = "TrueFoundry platform feature role to allows access to secrets that start with 'tfy'"
expression = "resource.name.startsWith('projects/${data.google_project.truefoundry_platform_feature_project.number}/secrets/tfy')"
}
}
// custom role for GCS bucket
resource "google_project_iam_custom_role" "truefoundry_platform_feature_gcs_bucket_role" {
count = var.feature_blob_storage_enabled ? 1 : 0
project = var.project
role_id = trimsuffix(substr(replace("${local.truefoundry_platform_resources}_bucket_gcs_role", "-", "_"), 0, 64), "_")
title = trimsuffix(substr("truefoundry/${var.cluster_name}/platform-features/${local.truefoundry_platform_resources}_bucket-gcs-role", 0, 100), "_")
description = "TrueFoundry platform feature role to manage GCS bucket"
permissions = [
"storage.objects.create",
"storage.objects.delete",
"storage.objects.get",
"storage.objects.list",
"storage.objects.update",
"storage.buckets.create",
"storage.buckets.get",
"storage.buckets.list",
"storage.buckets.create",
"storage.buckets.update",
"storage.multipartUploads.create",
"storage.multipartUploads.list",
"storage.multipartUploads.listParts",
"storage.multipartUploads.abort",
"resourcemanager.projects.get"
]
}
resource "google_project_iam_member" "truefoundry_platform_feature_gcs_role_binding" {
count = var.feature_blob_storage_enabled ? 1 : 0
project = var.project
role = google_project_iam_custom_role.truefoundry_platform_feature_gcs_bucket_role[count.index].id
member = "serviceAccount:${google_service_account.truefoundry_platform_feature_service_account.email}"
condition {
title = "Condition to allow access to truefoundry bucket"
description = "TrueFoundry platform feature role to allows access to buckets that start with 'tfy'"
expression = "resource.name.startsWith('projects/_/buckets/${module.blob_storage[0].name}')"
}
}
// cluster integration role
resource "google_project_iam_custom_role" "truefoundry_platform_feature_cluster_integration_role" {
count = var.feature_cluster_integration_enabled ? 1 : 0
project = var.project
role_id = trimsuffix(substr(replace("${local.truefoundry_platform_resources}_cluster_integration_role", "-", "_"), 0, 64), "_")
title = trimsuffix(substr("truefoundry/${var.cluster_name}/platform-features/${local.truefoundry_platform_resources}_cluster_integration_role", 0, 100), "_")
description = "TrueFoundry platform feature role to view GKE cluster"
permissions = [
"container.clusters.get",
"container.clusters.list",
"container.nodes.get",
"container.nodes.getStatus",
"container.nodes.list",
"resourcemanager.projects.get",
]
}
resource "google_project_iam_member" "truefoundry_platform_feature_cluster_integration_role_binding" {
count = var.feature_cluster_integration_enabled ? 1 : 0
project = var.project
role = google_project_iam_custom_role.truefoundry_platform_feature_cluster_integration_role[count.index].id
member = "serviceAccount:${google_service_account.truefoundry_platform_feature_service_account.email}"
}
// artifact registry role
resource "google_project_iam_custom_role" "truefoundry_platform_feature_artifact_registry_role" {
count = var.feature_docker_registry_enabled ? 1 : 0
project = var.project
role_id = trimsuffix(substr(replace("${local.truefoundry_platform_resources}_artifact_registry_role", "-", "_"), 0, 64), "_")
title = trimsuffix(substr("truefoundry/${var.cluster_name}/platform-features/${local.truefoundry_platform_resources}_artifact_registry_role", 0, 100), "_")
description = "TrueFoundry platform feature role for artifact registry"
permissions = [
"artifactregistry.dockerimages.get",
"artifactregistry.dockerimages.list",
"artifactregistry.locations.get",
"artifactregistry.locations.list",
"artifactregistry.repositories.get",
"artifactregistry.repositories.list",
"artifactregistry.repositories.create",
"artifactregistry.repositories.createTagBinding",
"artifactregistry.repositories.delete",
"artifactregistry.repositories.deleteArtifacts",
"artifactregistry.repositories.deleteTagBinding",
"artifactregistry.repositories.downloadArtifacts",
"artifactregistry.repositories.get",
"artifactregistry.repositories.getIamPolicy",
"artifactregistry.repositories.list",
"artifactregistry.repositories.listEffectiveTags",
"artifactregistry.repositories.listTagBindings",
"artifactregistry.repositories.update",
"artifactregistry.repositories.uploadArtifacts",
"artifactregistry.tags.get",
"artifactregistry.tags.list",
"artifactregistry.tags.create",
"artifactregistry.tags.update",
"artifactregistry.versions.get",
"artifactregistry.versions.list",
"artifactregistry.versions.delete"
]
}
resource "google_project_iam_member" "truefoundry_platform_feature_artifact_registry_role_binding" {
count = var.feature_docker_registry_enabled ? 1 : 0
project = var.project
role = google_project_iam_custom_role.truefoundry_platform_feature_artifact_registry_role[count.index].id
member = "serviceAccount:${google_service_account.truefoundry_platform_feature_service_account.email}"
}
// role binding token creator role to service account
resource "google_project_iam_member" "truefoundry_platform_feature_token_creator_role_binding" {
count = var.feature_blob_storage_enabled ? 1 : 0
project = var.project
role = "roles/iam.serviceAccountTokenCreator"
member = "serviceAccount:${google_service_account.truefoundry_platform_feature_service_account.email}"
}
// role binding logs viewer role to service account
resource "google_project_iam_member" "truefoundry_platform_feature_logs_viewer_role_binding" {
count = var.feature_logs_viewer_enabled ? 1 : 0
project = var.project
role = "roles/logging.viewer"
member = "serviceAccount:${google_service_account.truefoundry_platform_feature_service_account.email}"
}
// service account key
resource "google_service_account_key" "truefoundry_platform_feature_service_account_key" {
service_account_id = google_service_account.truefoundry_platform_feature_service_account.id
}