Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

github-bots: optionally use a pre-defined service account email #598

Merged
merged 4 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/github-bots/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ No requirements.
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | Project ID to create resources in. | `string` | n/a | yes |
| <a name="input_raw_filter"></a> [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 |
| <a name="input_regions"></a> [regions](#input\_regions) | A map from region names to a network and subnetwork. | <pre>map(object({<br/> network = string<br/> subnet = string<br/> }))</pre> | n/a | yes |
| <a name="input_service_account_email"></a> [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

Expand Down
10 changes: 9 additions & 1 deletion modules/github-bots/main.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
resource "google_service_account" "sa" {
count = var.service_account_email == "" ? 1 : 0
hectorj2f marked this conversation as resolved.
Show resolved Hide resolved
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

k4leung4 marked this conversation as resolved.
Show resolved Hide resolved
service_account = var.service_account_email == "" ? google_service_account.sa[0].email : var.service_account_email


egress = "PRIVATE_RANGES_ONLY" // Makes GitHub API calls

Expand Down
4 changes: 2 additions & 2 deletions modules/github-bots/outputs.tf
Original file line number Diff line number Diff line change
@@ -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
}


6 changes: 6 additions & 0 deletions modules/github-bots/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
}
Loading