-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
184 lines (150 loc) · 3.7 KB
/
main.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
* Input variables.
*/
variable "cluster_name" {
description = "GKE cluster name"
type = string
}
variable "google_project_id" {
description = "GCE project ID"
type = string
}
variable "image_type" {
description = "Type of the image to use for instances"
default = "cos"
type = string
}
variable "initial_node_count" {
description = "Initial number of nodes in a cluster"
default = 3
type = string
}
# Latest Kubernetes engine version can be found at https://cloud.google.com/kubernetes-engine/docs/release-notes
variable "kubernetes_version" {
description = "Kubernetes version"
default = "latest"
type = string
}
variable "machine_type" {
description = "Type of instances to use for a cluster"
default = "e2-standard-1"
type = string
}
variable "max_node_count" {
description = "Maximum number of nodes in a cluster"
default = 50
type = string
}
variable "preemptible" {
description = "Whether or not the underlying node VMs are preemptible"
default = false
type = string
}
variable "zones" {
description = "Zones to create a cluster in"
default = ["us-central1-a", "us-central1-b"]
type = list
}
/*
* Terraform providers.
*/
provider "google" {
version = "~> 3.18"
project = var.google_project_id
}
provider "kubernetes" {
version = "~> 1.11"
}
/*
* GCS remote state storage.
*/
terraform {
backend "gcs" {}
}
/*
* Terraform resources.
*/
# GKE cluster.
resource "google_container_cluster" "default" {
name = var.cluster_name
location = var.zones[0]
node_locations = slice(var.zones, 1, length(var.zones))
initial_node_count = 1
logging_service = "logging.googleapis.com/kubernetes"
monitoring_service = "monitoring.googleapis.com/kubernetes"
remove_default_node_pool = "true"
min_master_version = var.kubernetes_version
addons_config {
http_load_balancing {
disabled = "false"
}
horizontal_pod_autoscaling {
disabled = "false"
}
network_policy_config {
disabled = "true"
}
}
lifecycle {
ignore_changes = [initial_node_count]
}
timeouts {
create = "30m"
update = "30m"
delete = "30m"
}
}
# Default node pool.
resource "google_container_node_pool" "default_pool" {
name = "default-pool"
cluster = google_container_cluster.default.name
initial_node_count = 1
location = var.zones[0]
autoscaling {
max_node_count = var.max_node_count
min_node_count = var.initial_node_count
}
lifecycle {
ignore_changes = [initial_node_count]
}
management {
auto_repair = "true"
auto_upgrade = "true"
}
node_config {
disk_size_gb = 50
disk_type = "pd-standard"
image_type = var.image_type
machine_type = var.machine_type
preemptible = var.preemptible
oauth_scopes = [
"https://www.googleapis.com/auth/compute",
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
"https://www.googleapis.com/auth/service.management.readonly",
"https://www.googleapis.com/auth/servicecontrol",
"https://www.googleapis.com/auth/trace.append",
]
}
timeouts {
create = "30m"
update = "30m"
delete = "30m"
}
upgrade_settings {
max_surge = 2
max_unavailable = 1
}
}
resource "kubernetes_storage_class" "fast" {
depends_on = [google_container_cluster.default]
metadata {
name = "fast"
}
storage_provisioner = "kubernetes.io/gce-pd"
reclaim_policy = "Delete"
parameters = {
type = "pd-ssd"
}
}