Skip to content

Commit 36b8e01

Browse files
committed
force GSA to be created outside the module
1 parent 2205e09 commit 36b8e01

4 files changed

Lines changed: 2 additions & 22 deletions

File tree

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ No modules.
3030
| [google_compute_backend_service.backend](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_backend_service) | resource |
3131
| [google_compute_region_network_endpoint_group.neg](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_region_network_endpoint_group) | resource |
3232
| [google_project_iam_member.sa_role](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/project_iam_member) | resource |
33-
| [google_service_account.service_account](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/service_account) | resource |
3433
| [google_service_account.service_account](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/service_account) | data source |
3534

3635
## Inputs
@@ -41,7 +40,7 @@ No modules.
4140
| <a name="input_containers"></a> [containers](#input\_containers) | List of container configurations to run in the service. At least one container needs a port. This allows easily configuring multi-container deployments. | <pre>list(object({<br/> image = string<br/> name = string<br/> command = optional(list(string), null)<br/> args = optional(list(string), null)<br/> port = optional(number, 0)<br/> memory = optional(string, "512Mi")<br/> cpu = optional(string, "1000m")<br/> liveness_probe = optional(string, "")<br/> gpus = optional(string, "")<br/> volume_mounts = optional(list(object({<br/> name = string<br/> mount_path = string<br/> })), [])<br/> }))</pre> | n/a | yes |
4241
| <a name="input_empty_dir_volumes"></a> [empty\_dir\_volumes](#input\_empty\_dir\_volumes) | List of empty directory volumes to create and mount | <pre>list(object({<br/> name = string<br/> size_limit = optional(string, "2Mi")<br/> }))</pre> | `[]` | no |
4342
| <a name="input_gcs_volumes"></a> [gcs\_volumes](#input\_gcs\_volumes) | List of Google Cloud Storage buckets to mount as volumes. Must ensure the Cloud Run GSA has proper IAM set on the bucket | <pre>list(object({<br/> name = string<br/> bucket = string<br/> read_only = optional(bool, true)<br/> }))</pre> | `[]` | no |
44-
| <a name="input_gsa"></a> [gsa](#input\_gsa) | Service account name the Cloud Run service will run as. If empty, creates a new one. | `string` | `""` | no |
43+
| <a name="input_gsa"></a> [gsa](#input\_gsa) | Service account name the Cloud Run service will run as. If empty, creates a new one. | `string` | n/a | yes |
4544
| <a name="input_invokers"></a> [invokers](#input\_invokers) | List of members to grant Cloud Run invoker role | `list(string)` | <pre>[<br/> "allUsers"<br/>]</pre> | no |
4645
| <a name="input_max_instances"></a> [max\_instances](#input\_max\_instances) | Maximum number of instances to scale to | `string` | `"100"` | no |
4746
| <a name="input_min_instances"></a> [min\_instances](#input\_min\_instances) | Minimum number of instances to keep running | `string` | `"0"` | no |
@@ -60,8 +59,6 @@ No modules.
6059
| Name | Description |
6160
|------|-------------|
6261
| <a name="output_backend"></a> [backend](#output\_backend) | Backend service ID for load balancer (empty if skipNeg is true) |
63-
| <a name="output_gsa"></a> [gsa](#output\_gsa) | Name of the service account used by Cloud Run |
64-
| <a name="output_gsaEmail"></a> [gsaEmail](#output\_gsaEmail) | Email address of the service account used by Cloud Run |
6562
| <a name="output_name"></a> [name](#output\_name) | Map of region to Cloud Run service names |
6663
| <a name="output_url"></a> [url](#output\_url) | Primary Cloud Run service URL (first region) |
6764
| <a name="output_urls"></a> [urls](#output\_urls) | Map of region to Cloud Run service URLs |

main.tf

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,8 @@ terraform {
77
}
88
}
99

10-
resource "google_service_account" "service_account" {
11-
count = var.gsa == "" ? 1 : 0
12-
account_id = "cr-${var.name}"
13-
project = var.project
14-
}
15-
1610
data "google_service_account" "service_account" {
17-
account_id = var.gsa == "" ? google_service_account.service_account[0].name : var.gsa
11+
account_id = var.gsa
1812
project = var.project
1913
}
2014

outputs.tf

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,3 @@ output "url" {
2323
value = values(google_cloud_run_v2_service.cloudrun)[0].uri
2424
description = "Primary Cloud Run service URL (first region)"
2525
}
26-
27-
output "gsaEmail" {
28-
value = data.google_service_account.service_account.email
29-
description = "Email address of the service account used by Cloud Run"
30-
}
31-
32-
output "gsa" {
33-
value = data.google_service_account.service_account.name
34-
description = "Name of the service account used by Cloud Run"
35-
}

variables.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ variable "name" {
55

66
variable "gsa" {
77
type = string
8-
default = ""
98
description = "Service account name the Cloud Run service will run as. If empty, creates a new one."
109
}
1110

0 commit comments

Comments
 (0)