forked from nkoson/gke-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kubernetes.tf
42 lines (35 loc) · 1.98 KB
/
kubernetes.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Configure kubernetes provider with Oauth2 access token.
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/client_config
# This fetches a new token, which will expire in 1 hour.
data "google_client_config" "default" {
}
# Retrieve information separately to the cluster resource in module.cluster,
# because it appears that otherwise this information can be cached in the state in an incorrect manner,
# at least if used as a parameter to a provider.
# Probably related to https://github.com/hashicorp/terraform/issues/4149
# and https://github.com/hashicorp/terraform-provider-kubernetes/issues/1028
data google_container_cluster "cluster" {
name = local.cluster_name
location = local.zone
# Don't retrieve this information until the cluster is ready.
# May allow this to work in a single config.
depends_on = [module.cluster.cluster-id]
}
provider "kubernetes" {
# config_path = "~/.kube/config"
host = "https://${data.google_container_cluster.cluster.endpoint}"
token = data.google_client_config.default.access_token
client_certificate = base64decode(data.google_container_cluster.cluster.master_auth[0].client_certificate)
client_key = base64decode(data.google_container_cluster.cluster.master_auth[0].client_key)
cluster_ca_certificate = base64decode(data.google_container_cluster.cluster.master_auth[0].cluster_ca_certificate)
}
provider "kubectl" {
# config_path = "~/.kube/config"
host = "https://${data.google_container_cluster.cluster.endpoint}"
token = data.google_client_config.default.access_token
client_certificate = base64decode(data.google_container_cluster.cluster.master_auth[0].client_certificate)
client_key = base64decode(data.google_container_cluster.cluster.master_auth[0].client_key)
cluster_ca_certificate = base64decode(data.google_container_cluster.cluster.master_auth[0].cluster_ca_certificate)
# Possibly necessary per https://github.com/gavinbunney/terraform-provider-kubectl/pull/107
load_config_file = false
}