File tree Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,9 @@ To deploy this config:
4141| gke\_ hub\_ sa\_ name | Name for the GKE Hub SA stored as a secret ` creds-gcp ` in the ` gke-connect ` namespace. | string | ` "gke-hub-sa" ` | no |
4242| location | The location (zone or region) this cluster has been created in. | string | n/a | yes |
4343| project\_ id | The project in which the resource belongs. | string | n/a | yes |
44+ | sa\_ private\_ key | Private key for service account base64 encoded. Required only if ` use_existing_sa ` is set to ` true ` . | string | ` "null" ` | no |
4445| skip\_ gcloud\_ download | Whether to skip downloading gcloud (assumes gcloud and kubectl already available outside the module) | bool | ` "true" ` | no |
46+ | use\_ existing\_ sa | Uses an existing service account to register membership. Requires sa_private_key | bool | ` "false" ` | no |
4547| use\_ tf\_ google\_ credentials\_ env\_ var | Optional GOOGLE_CREDENTIALS environment variable to be activated. | bool | ` "false" ` | no |
4648
4749## Outputs
Original file line number Diff line number Diff line change 1515 */
1616
1717locals {
18- gke_hub_sa_key = google_service_account_key. gke_hub_key . private_key
18+ gke_hub_sa_key = var . use_existing_sa ? var . sa_private_key : google_service_account_key. gke_hub_key [ 0 ] . private_key
1919}
2020
2121data "google_client_config" "default" {
2222}
2323
2424resource "google_service_account" "gke_hub_sa" {
25+ count = var. use_existing_sa ? 0 : 1
2526 account_id = var. gke_hub_sa_name
2627 project = var. project_id
2728 display_name = " Service Account for GKE Hub Registration"
2829}
2930
3031resource "google_project_iam_member" "gke_hub_member" {
32+ count = var. use_existing_sa ? 0 : 1
3133 project = var. project_id
3234 role = " roles/gkehub.connect"
33- member = " serviceAccount:${ google_service_account . gke_hub_sa . email } "
35+ member = " serviceAccount:${ google_service_account . gke_hub_sa [ 0 ] . email } "
3436}
3537
3638resource "google_service_account_key" "gke_hub_key" {
37- service_account_id = google_service_account. gke_hub_sa . name
39+ count = var. use_existing_sa ? 0 : 1
40+ service_account_id = google_service_account. gke_hub_sa [0 ]. name
3841}
3942
4043module "gke_hub_registration" {
Original file line number Diff line number Diff line change @@ -69,3 +69,15 @@ variable "gke_hub_membership_name" {
6969 type = string
7070 default = " gke-hub-membership"
7171}
72+
73+ variable "use_existing_sa" {
74+ description = " Uses an existing service account to register membership. Requires sa_private_key"
75+ type = bool
76+ default = false
77+ }
78+
79+ variable "sa_private_key" {
80+ description = " Private key for service account base64 encoded. Required only if `use_existing_sa` is set to `true`."
81+ type = string
82+ default = null
83+ }
You can’t perform that action at this time.
0 commit comments