diff --git a/modules/github-bots/README.md b/modules/github-bots/README.md index bfa94e0b..10a090c4 100644 --- a/modules/github-bots/README.md +++ b/modules/github-bots/README.md @@ -120,6 +120,7 @@ No requirements. | [project\_id](#input\_project\_id) | Project ID to create resources in. | `string` | n/a | yes | | [raw\_filter](#input\_raw\_filter) | Raw PubSub filter to apply, ignores other variables. https://cloud.google.com/pubsub/docs/subscription-message-filter#filtering_syntax | `string` | `""` | no | | [regions](#input\_regions) | A map from region names to a network and subnetwork. |
map(object({
network = string
subnet = string
}))
| n/a | yes | +| [service\_account\_email](#input\_service\_account\_email) | The email of the service account being authorized to invoke the private Cloud Run service. If empty, a service account will be created and used. | `string` | `""` | no | ## Outputs diff --git a/modules/github-bots/main.tf b/modules/github-bots/main.tf index cd2ee661..94c36648 100644 --- a/modules/github-bots/main.tf +++ b/modules/github-bots/main.tf @@ -1,15 +1,23 @@ resource "google_service_account" "sa" { + count = var.service_account_email == "" ? 1 : 0 account_id = "bot-${var.name}" display_name = "Service Account for ${var.name}" } +moved { + from = google_service_account.sa + to = google_service_account.sa[0] +} + module "service" { source = "../regional-go-service" name = var.name project_id = var.project_id regions = var.regions - service_account = google_service_account.sa.email + + service_account = var.service_account_email == "" ? google_service_account.sa[0].email : var.service_account_email + egress = "PRIVATE_RANGES_ONLY" // Makes GitHub API calls diff --git a/modules/github-bots/outputs.tf b/modules/github-bots/outputs.tf index 05665939..e6ff28a9 100644 --- a/modules/github-bots/outputs.tf +++ b/modules/github-bots/outputs.tf @@ -1,11 +1,11 @@ output "serviceaccount-id" { description = "The ID of the service account for the bot." - value = google_service_account.sa.unique_id + value = var.service_account_email == "" ? google_service_account.sa[0].unique_id : "" } output "serviceaccount-email" { description = "The email of the service account for the bot." - value = google_service_account.sa.email + value = var.service_account_email == "" ? google_service_account.sa[0].email : var.service_account_email } diff --git a/modules/github-bots/variables.tf b/modules/github-bots/variables.tf index e28049e3..83261ff1 100644 --- a/modules/github-bots/variables.tf +++ b/modules/github-bots/variables.tf @@ -123,3 +123,9 @@ variable "deletion_protection" { description = "Whether to enable delete protection for the service." default = true } + +variable "service_account_email" { + description = "The email of the service account being authorized to invoke the private Cloud Run service. If empty, a service account will be created and used." + type = string + default = "" +}