-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathcluster.tf
91 lines (75 loc) · 2.54 KB
/
cluster.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
variable "general_purpose_machine_type" {
type = "string"
description = "Machine type to use for the general-purpose node pool. See https://cloud.google.com/compute/docs/machine-types"
}
variable "general_purpose_min_node_count" {
type = "string"
description = "The minimum number of nodes PER ZONE in the general-purpose node pool"
default = 1
}
variable "general_purpose_max_node_count" {
type = "string"
description = "The maximum number of nodes PER ZONE in the general-purpose node pool"
default = 5
}
resource "google_container_cluster" "cluster" {
name = "${var.project}-cluster"
location = "${var.region}"
# We can't create a cluster with no node pool defined, but we want to only use
# separately managed node pools. So we create the smallest possible default
# node pool and immediately delete it.
remove_default_node_pool = true
initial_node_count = 1
# Setting an empty username and password explicitly disables basic auth
master_auth {
username = ""
password = ""
}
addons_config {
network_policy_config {
disabled = "false"
}
}
network_policy {
enabled = "true"
provider = "CALICO"
}
}
resource "google_container_node_pool" "general_purpose" {
name = "${var.project}-general"
location = "${var.region}"
cluster = "${google_container_cluster.cluster.name}"
management {
auto_repair = "true"
auto_upgrade = "true"
}
autoscaling {
min_node_count = "${var.general_purpose_min_node_count}"
max_node_count = "${var.general_purpose_max_node_count}"
}
initial_node_count = "${var.general_purpose_min_node_count}"
node_config {
machine_type = "${var.general_purpose_machine_type}"
metadata = {
disable-legacy-endpoints = "true"
}
# Needed for correctly functioning cluster, see
# https://www.terraform.io/docs/providers/google/r/container_cluster.html#oauth_scopes
oauth_scopes = [
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
"https://www.googleapis.com/auth/devstorage.read_only"
]
}
}
# The following outputs allow authentication and connectivity to the GKE Cluster
# by using certificate-based authentication.
output "client_certificate" {
value = "${google_container_cluster.cluster.master_auth.0.client_certificate}"
}
output "client_key" {
value = "${google_container_cluster.cluster.master_auth.0.client_key}"
}
output "cluster_ca_certificate" {
value = "${google_container_cluster.cluster.master_auth.0.cluster_ca_certificate}"
}