Skip to content

Commit c526d00

Browse files
authored
Revert "feat(google_workload_identity): removed data source and updated outpu…" (#287)
This reverts commit f06d51a.
1 parent f6c1ebb commit c526d00

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

google_workload_identity/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ accounts to go with it
99
|------|-------------|------|---------|:--------:|
1010
| <a name="input_automount_service_account_token"></a> [automount\_service\_account\_token](#input\_automount\_service\_account\_token) | Enable automatic mounting of the service account token | `bool` | `false` | no |
1111
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | Cluster name. Required if using existing KSA. | `string` | `""` | no |
12-
| <a name="input_gcp_sa_email"></a> [gcp\_sa\_email](#input\_gcp\_sa\_email) | Email for an existing Google service account. | `string` | `null` | no |
1312
| <a name="input_gcp_sa_name"></a> [gcp\_sa\_name](#input\_gcp\_sa\_name) | Name for the Google service account; overrides `var.name`. | `string` | `null` | no |
1413
| <a name="input_impersonate_service_account"></a> [impersonate\_service\_account](#input\_impersonate\_service\_account) | An optional service account to impersonate for gcloud commands. If this service account is not specified, the module will use Application Default Credentials. | `string` | `""` | no |
1514
| <a name="input_k8s_sa_name"></a> [k8s\_sa\_name](#input\_k8s\_sa\_name) | Name for the Kubernetes service account; overrides `var.name`. | `string` | `null` | no |

google_workload_identity/main.tf

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
locals {
88
gcp_given_name = var.gcp_sa_name != null ? var.gcp_sa_name : substr(var.name, 0, 30)
9-
gcp_sa_email = var.use_existing_gcp_sa ? var.gcp_sa_email : google_service_account.cluster_service_account[0].email
9+
gcp_sa_email = var.use_existing_gcp_sa ? data.google_service_account.cluster_service_account[0].email : google_service_account.cluster_service_account[0].email
1010
gcp_sa_fqn = "serviceAccount:${local.gcp_sa_email}"
1111

1212
# This will cause Terraform to block returning outputs until the service account is created
@@ -17,6 +17,13 @@ locals {
1717
k8s_sa_gcp_derived_name = "serviceAccount:${var.project_id}.svc.id.goog[${var.namespace}/${local.output_k8s_name}]"
1818
}
1919

20+
data "google_service_account" "cluster_service_account" {
21+
count = var.use_existing_gcp_sa ? 1 : 0
22+
23+
account_id = local.gcp_given_name
24+
project = var.project_id
25+
}
26+
2027
resource "google_service_account" "cluster_service_account" {
2128
count = var.use_existing_gcp_sa ? 0 : 1
2229

@@ -39,7 +46,7 @@ resource "kubernetes_service_account" "main" {
3946
}
4047

4148
resource "google_service_account_iam_member" "main" {
42-
service_account_id = var.use_existing_gcp_sa ? var.gcp_sa_name : google_service_account.cluster_service_account[0].name
49+
service_account_id = var.use_existing_gcp_sa ? data.google_service_account.cluster_service_account[0].name : google_service_account.cluster_service_account[0].name
4350
role = "roles/iam.workloadIdentityUser"
4451
member = local.k8s_sa_gcp_derived_name
4552
}
@@ -50,4 +57,4 @@ resource "google_project_iam_member" "workload_identity_sa_bindings" {
5057
project = var.project_id
5158
role = each.value
5259
member = local.gcp_sa_fqn
53-
}
60+
}

google_workload_identity/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ output "gcp_service_account_name" {
2626

2727
output "gcp_service_account" {
2828
description = "GCP service account."
29-
value = var.use_existing_gcp_sa ? var.gcp_sa_name : google_service_account.cluster_service_account[0]
30-
}
29+
value = var.use_existing_gcp_sa ? data.google_service_account.cluster_service_account[0] : google_service_account.cluster_service_account[0]
30+
}

google_workload_identity/variables.tf

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ variable "gcp_sa_name" {
1414
default = null
1515
}
1616

17-
variable "gcp_sa_email" {
18-
description = "Email for an existing Google service account."
19-
type = string
20-
default = null
21-
}
22-
2317
variable "use_existing_gcp_sa" {
2418
description = "Use an existing Google service account instead of creating one"
2519
type = bool
@@ -72,4 +66,4 @@ variable "impersonate_service_account" {
7266
description = "An optional service account to impersonate for gcloud commands. If this service account is not specified, the module will use Application Default Credentials."
7367
type = string
7468
default = ""
75-
}
69+
}

0 commit comments

Comments
 (0)