Skip to content

Commit fe84696

Browse files
Updating Documentation for exchanging credentials with the kubernetes… (#10153) (#7176)
[upstream:998f5520a45fc16b48a950715447335bb566364a] Signed-off-by: Modular Magician <[email protected]>
1 parent 3d39532 commit fe84696

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

.changelog/10153.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:none
2+
3+
```

website/docs/guides/using_gke_with_terraform.html.markdown

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,29 @@ provider "kubernetes" {
5959
)
6060
}
6161
```
62+
Although the above can result in authentication errors, over time, as the token recorded in the google_client_cofig data resource is short lived (thus it expires) and it's stored in state. Fortunately, the [kubernetes provider can accept valid credentials from an exec-based plugin](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs#exec-plugins) to fetch a new token before each Terraform operation (so long as you have the [gke-cloud-auth-plugin for kubectl installed](https://cloud.google.com/blog/products/containers-kubernetes/kubectl-auth-changes-in-gke)), like so:
63+
64+
```hcl
65+
# Retrieve an access token as the Terraform runner
66+
data "google_client_config" "provider" {}
67+
68+
data "google_container_cluster" "my_cluster" {
69+
name = "my-cluster"
70+
location = "us-central1"
71+
}
72+
73+
provider "kubernetes" {
74+
host = "https://${data.google_container_cluster.my_cluster.endpoint}"
75+
token = data.google_client_config.provider.access_token
76+
cluster_ca_certificate = base64decode(
77+
data.google_container_cluster.my_cluster.master_auth[0].cluster_ca_certificate,
78+
)
79+
exec {
80+
api_version = "client.authentication.k8s.io/v1beta1"
81+
command = "gke-gcloud-auth-plugin"
82+
}
83+
}
84+
```
6285

6386
Alternatively, you can authenticate as another service account on which your
6487
Terraform user has been granted the `roles/iam.serviceAccountTokenCreator`

0 commit comments

Comments
 (0)