Skip to content

Commit 5ba5380

Browse files
eeatondaniel-cit
andauthored
chore(functions): update cloud functions to specify build SA (#1282)
Co-authored-by: Daniel Andrade <[email protected]>
1 parent 4365eab commit 5ba5380

File tree

6 files changed

+57
-14
lines changed

6 files changed

+57
-14
lines changed

1-org/envs/shared/cai_monitoring.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
module "cai_monitoring" {
1818
source = "../../modules/cai-monitoring"
1919

20-
org_id = local.org_id
21-
billing_account = local.billing_account
22-
project_id = module.scc_notifications.project_id
23-
location = local.default_region
20+
org_id = local.org_id
21+
billing_account = local.billing_account
22+
project_id = module.scc_notifications.project_id
23+
location = local.default_region
24+
build_service_account = "projects/${module.scc_notifications.project_id}/serviceAccounts/${google_service_account.cai_monitoring_builder.email}"
2425
}

1-org/envs/shared/iam.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,14 @@ resource "google_project_iam_member" "kms_admin" {
188188
role = "roles/cloudkms.viewer"
189189
member = "group:${var.gcp_groups.kms_admin}"
190190
}
191+
192+
resource "google_project_iam_member" "cai_monitoring_builder" {
193+
project = module.scc_notifications.project_id
194+
for_each = toset([
195+
"roles/logging.logWriter",
196+
"roles/storage.objectViewer",
197+
"roles/artifactregistry.writer",
198+
])
199+
role = each.key
200+
member = "serviceAccount:${google_service_account.cai_monitoring_builder.email}"
201+
}

1-org/envs/shared/sa.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
resource "google_service_account" "cai_monitoring_builder" {
18+
project = module.scc_notifications.project_id
19+
account_id = "cai-monitoring-builder"
20+
description = "Cloud Functions has an underlying dependency on Cloud Build and other services. This service account allows Cloud Build to provision the necessary resources for Cloud Functions."
21+
create_ignore_already_exists = true
22+
}

1-org/modules/cai-monitoring/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module "secure_cai_notification" {
2323
| Name | Description | Type | Default | Required |
2424
|------|-------------|------|---------|:--------:|
2525
| billing\_account | The ID of the billing account to associate projects with. | `string` | n/a | yes |
26+
| build\_service\_account | Cloud Function Build Service Account Id. This is The fully-qualified name of the service account to be used for building the container. | `string` | n/a | yes |
2627
| enable\_cmek | The KMS Key to Encrypt Artifact Registry repository, Cloud Storage Bucket and Pub/Sub. | `bool` | `false` | no |
2728
| encryption\_key | The KMS Key to Encrypt Artifact Registry repository, Cloud Storage Bucket and Pub/Sub. | `string` | `null` | no |
2829
| labels | Labels to be assigned to resources. | `map(any)` | `{}` | no |

1-org/modules/cai-monitoring/main.tf

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,17 @@ resource "google_scc_source" "cai_monitoring" {
142142
// Cloud Function
143143
module "cloud_function" {
144144
source = "GoogleCloudPlatform/cloud-functions/google"
145-
version = "~> 0.5"
146-
147-
function_name = "caiMonitoring"
148-
description = "Check on the Organization for members (users, groups and service accounts) that contains the IAM roles listed."
149-
project_id = var.project_id
150-
labels = var.labels
151-
function_location = var.location
152-
runtime = "nodejs20"
153-
entrypoint = "caiMonitoring"
154-
docker_repository = google_artifact_registry_repository.cloudfunction.id
145+
version = "~> 0.6"
146+
147+
function_name = "caiMonitoring"
148+
description = "Check on the Organization for members (users, groups and service accounts) that contains the IAM roles listed."
149+
project_id = var.project_id
150+
labels = var.labels
151+
function_location = var.location
152+
runtime = "nodejs20"
153+
entrypoint = "caiMonitoring"
154+
docker_repository = google_artifact_registry_repository.cloudfunction.id
155+
build_service_account = var.build_service_account
155156

156157
storage_source = {
157158
bucket = module.cloudfunction_source_bucket.name

1-org/modules/cai-monitoring/variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,10 @@ variable "random_suffix" {
7070
type = bool
7171
default = true
7272
}
73+
74+
variable "build_service_account" {
75+
description = "Cloud Function Build Service Account Id. This is The fully-qualified name of the service account to be used for building the container."
76+
type = string
77+
}
78+
79+

0 commit comments

Comments
 (0)