-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgke.tf
More file actions
87 lines (67 loc) · 2.08 KB
/
gke.tf
File metadata and controls
87 lines (67 loc) · 2.08 KB
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
resource "google_service_account" "default" {
account_id = var.project_name
display_name = var.project_name
}
# google_client_config and kubernetes provider must be explicitly specified like the following.
# Retrieve an access token as the Terraform runner
data "google_client_config" "default" {}
resource "google_container_cluster" "primary" {
name = "${var.project_name}-gke-primary"
location = var.region
workload_identity_config {
workload_pool = "${var.project_name}.svc.id.goog"
}
ip_allocation_policy {
cluster_ipv4_cidr_block = var.pod_cidr
services_ipv4_cidr_block = var.service_cidr
}
service_external_ips_config {
enabled = true
}
# 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
network = google_compute_network.vpc.name
subnetwork = google_compute_subnetwork.subnet.name
node_config {
workload_metadata_config {
mode = "GKE_METADATA"
}
}
}
resource "google_container_node_pool" "nodes" {
location = var.region
name = google_container_cluster.primary.name
cluster = google_container_cluster.primary.name
node_count = 1
node_locations = [
"${var.region}-b",
]
autoscaling {
total_min_node_count = 1
total_max_node_count = 1
location_policy = "ANY"
}
node_config {
disk_size_gb = 160
machine_type = "e2-standard-4"
# Google recommends custom service accounts that have cloud-platform scope and permissions granted via IAM Roles.
service_account = google_service_account.default.email
oauth_scopes = [
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
]
labels = {
env = var.project_name
}
metadata = {
disable-legacy-endpoints = "true"
}
}
depends_on = [
google_container_cluster.primary,
]
}