Skip to content

Commit e3ea6e9

Browse files
authored
feat: add option to use connect gateway (#155)
1 parent 7c0ba9f commit e3ea6e9

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

modules/kubectl-wrapper/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ module "kubectl" {
4040
| service\_account\_key\_file | Path to service account key file to auth as for running `gcloud container clusters get-credentials`. | `string` | `""` | no |
4141
| skip\_download | Whether to skip downloading gcloud (assumes gcloud and kubectl is already available outside the module) | `bool` | `true` | no |
4242
| upgrade | Whether to upgrade gcloud at runtime | `bool` | `true` | no |
43+
| use\_connect\_gateway | Use Connect Gateway to obtain credentials. The provided cluster\_name will be used as the fleet membership name. | `bool` | `false` | no |
4344
| use\_existing\_context | Use existing kubecontext to auth kube-api. | `bool` | `false` | no |
4445
| use\_tf\_google\_credentials\_env\_var | Use `GOOGLE_CREDENTIALS` environment variable to run `gcloud auth activate-service-account` with. Optional. | `bool` | `false` | no |
4546

modules/kubectl-wrapper/main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2020 Google LLC
2+
* Copyright 2020-2023 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,7 +15,8 @@
1515
*/
1616

1717
locals {
18-
base_cmd = "${var.cluster_name} ${var.cluster_location} ${var.project_id} ${var.internal_ip} ${var.use_existing_context}"
18+
connect_cmd = var.use_connect_gateway ? "fleet memberships" : "clusters"
19+
base_cmd = "${var.cluster_name} ${var.cluster_location} ${var.project_id} ${var.internal_ip} ${var.use_existing_context} ${local.connect_cmd}"
1920
}
2021

2122
module "gcloud_kubectl" {

modules/kubectl-wrapper/scripts/kubectl_wrapper.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
# Copyright 2020 Google LLC
2+
# Copyright 2020-2023 Google LLC
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
1616

1717
set -xeo pipefail
1818

19-
if [ "$#" -lt 5 ]; then
19+
if [ "$#" -lt 6 ]; then
2020
>&2 echo "Not all expected arguments set."
2121
exit 1
2222
fi
@@ -26,10 +26,11 @@ LOCATION=$2
2626
PROJECT_ID=$3
2727
INTERNAL=$4
2828
USE_EXISTING_CONTEXT=$5
29-
ENABLE_IMPERSONATE_SERVICE_ACCOUNT=$6
30-
IMPERSONATE_SERVICE_ACCOUNT=$7
29+
CONNECT_CMD=$6
30+
ENABLE_IMPERSONATE_SERVICE_ACCOUNT=$7
31+
IMPERSONATE_SERVICE_ACCOUNT=$8
3132

32-
shift 5
33+
shift 6
3334

3435
if $USE_EXISTING_CONTEXT ;then
3536

@@ -51,7 +52,7 @@ else
5152

5253
LOCATION_TYPE=$(grep -o "-" <<< "${LOCATION}" | wc -l)
5354

54-
CMD="gcloud container clusters get-credentials ${CLUSTER_NAME} --project ${PROJECT_ID}"
55+
CMD="gcloud container ${CONNECT_CMD} get-credentials ${CLUSTER_NAME} --project ${PROJECT_ID}"
5556
if [[ "${ENABLE_IMPERSONATE_SERVICE_ACCOUNT}" == true ]]; then
5657
CMD+=" --impersonate-service-account ${IMPERSONATE_SERVICE_ACCOUNT}"
5758
shift 2

modules/kubectl-wrapper/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,9 @@ variable "impersonate_service_account" {
113113
description = "An optional service account to impersonate for gcloud commands. If this service account is not specified, the module will use Application Default Credentials."
114114
default = ""
115115
}
116+
117+
variable "use_connect_gateway" {
118+
type = bool
119+
description = "Use Connect Gateway to obtain credentials. The provided cluster_name will be used as the fleet membership name."
120+
default = false
121+
}

0 commit comments

Comments
 (0)