Skip to content

Commit 721cdd2

Browse files
committed
fixing exception with iam svc account missing
1 parent b97b578 commit 721cdd2

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

modules/pipelines/main.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
# Cloud Build Pipeline for gcp-python-fastapi
22
# https://github.com/The-DevSec-Blueprint/gcp-python-fastapi/tree/main
3+
resource "google_service_account" "cloudbuild_service_account" {
4+
account_id = "${var.cloudbuild_trigger_name}-sa"
5+
display_name = "${var.cloudbuild_trigger_name}-sa"
6+
description = "Cloud Build Service Account for ${var.cloudbuild_trigger_name}"
7+
}
8+
9+
resource "google_project_iam_member" "act_as" {
10+
project = var.project_id
11+
role = "roles/iam.serviceAccountUser"
12+
member = "serviceAccount:${google_service_account.cloudbuild_service_account.email}"
13+
}
14+
15+
resource "google_project_iam_member" "logs_writer" {
16+
project = var.project_id
17+
role = "roles/logging.logWriter"
18+
member = "serviceAccount:${google_service_account.cloudbuild_service_account.email}"
19+
}
20+
321
resource "google_cloudbuild_trigger" "build_trigger" {
422
name = var.cloudbuild_trigger_name
523
description = var.description
624
filename = var.filename
725

26+
service_account = google_service_account.cloudbuild_service_account.id
27+
828
github {
929
owner = "The-DevSec-Blueprint"
1030
name = var.github_repo_name

modules/pipelines/variable.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@ variable "filename" {
1717
variable "github_repo_name" {
1818
description = "Name of the GitHub repository"
1919
type = string
20+
}
21+
22+
variable "project_id" {
23+
description = "ID of the Google Cloud project"
24+
type = string
2025
}

pipelines.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module "gcp_python_fastapi_pipeline" {
2-
source = "./modules/pipelines"
2+
source = "./modules/pipelines"
3+
4+
project_id = var.project_id
35
cloudbuild_trigger_name = "gcp-python-fastapi"
46
description = "Cloud Build Trigger for GCP Python FastAPI"
57
github_repo_name = "gcp-python-fastapi"

0 commit comments

Comments
 (0)