Skip to content

Commit 1b99c07

Browse files
fstrbharathkkb
andauthored
feat: Add new property to explicitly return GKE private_endpoint for auth module (#841)
* Add new property to explicitly return GKE private_endpoint * Return private_endpoint if explicitly requested, otherwise return default endpoint Co-authored-by: Bharath KKB <[email protected]>
1 parent 6dc1eb1 commit 1b99c07

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

modules/auth/README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@ This module retrieves a token for the account configured with the `google`
99
provider as the Terraform runner using the provider's `credentials`,
1010
`access_token`, or other means of authentication.
1111

12+
If you run a [private cluster](https://cloud.google.com/kubernetes-engine/docs/concepts/private-cluster-concept), you can set the `use_private_endpoint` property to return the GKE private_endpoint IP address.
13+
1214
## Usage
1315

1416
```tf
1517
module "gke_auth" {
16-
source = "terraform-google-modules/kubernetes-engine/google//modules/auth"
18+
source = "terraform-google-modules/kubernetes-engine/google//modules/auth"
1719
18-
project_id = "my-project-id"
19-
cluster_name = "my-cluster-name"
20-
location = module.gke.location
20+
project_id = "my-project-id"
21+
cluster_name = "my-cluster-name"
22+
location = module.gke.location
23+
use_private_endpoint = true
2124
}
2225
```
2326

modules/auth/main.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616

1717
locals {
1818
cluster_ca_certificate = data.google_container_cluster.gke_cluster.master_auth != null ? data.google_container_cluster.gke_cluster.master_auth[0].cluster_ca_certificate : ""
19-
endpoint = data.google_container_cluster.gke_cluster.endpoint != null ? data.google_container_cluster.gke_cluster.endpoint : ""
20-
host = data.google_container_cluster.gke_cluster.endpoint != null ? "https://${data.google_container_cluster.gke_cluster.endpoint}" : ""
19+
private_endpoint = try(data.google_container_cluster.gke_cluster.private_cluster_config[0].private_endpoint, "")
20+
default_endpoint = data.google_container_cluster.gke_cluster.endpoint != null ? data.google_container_cluster.gke_cluster.endpoint : ""
21+
endpoint = var.use_private_endpoint == true ? local.private_endpoint : local.default_endpoint
22+
host = local.endpoint != "" ? "https://${local.endpoint}" : ""
2123
context = data.google_container_cluster.gke_cluster.name != null ? data.google_container_cluster.gke_cluster.name : ""
2224
}
2325

modules/auth/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ variable "cluster_name" {
2828
description = "The name of the GKE cluster."
2929
type = string
3030
}
31+
32+
variable "use_private_endpoint" {
33+
description = "Connect on the private GKE cluster endpoint"
34+
type = bool
35+
default = false
36+
}

0 commit comments

Comments
 (0)