forked from UpCloudLtd/uks-instructions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
78 lines (63 loc) · 2.63 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
# Create a router for your network
resource "upcloud_router" "example" {
name = "${var.basename}-router"
}
# Create a network for your cluster
resource "upcloud_network" "example" {
name = "${var.basename}-net"
zone = var.zone
ip_network {
address = var.ip_network_range
dhcp = true
family = "IPv4"
}
# If router is omitted here, UpCloud Kubernetes Service will add a router to this network automatically. In Terraform, we recommend defining the router explicitly to avoid Terraform trying to detach the automatically created router which is not recognized by Terraform.
router = upcloud_router.example.id
# If you do not expicitly set the router, you'll need to ignore changes to it. Otherwise, Terraform will attempt to detach the router on subsequent applies.
# lifecycle {
# ignore_changes = [router]
# }
}
# Create a cluster
resource "upcloud_kubernetes_cluster" "example" {
name = "${var.basename}-cluster"
network = upcloud_network.example.id
zone = var.zone
}
# Create a node group for your cluster
# Node group is a group of worker nodes that are created based on the same template
# You can have multiple node groups with different configurations in your cluster
resource "upcloud_kubernetes_node_group" "group" {
name = "medium"
// All nodes in this group will be joined to this cluster
cluster = upcloud_kubernetes_cluster.example.id
// The amount of created nodes (servers)
node_count = 2
// Plan for each node; you can check available plans with upcloud CLI tool (`upctl server plans`) or by making a call to API (https://developers.upcloud.com/1.3/7-plans/)
plan = "2xCPU-4GB"
// With `anti_affinity` set to true, UKS will attempt to deploy nodes in this group to different compute hosts
anti_affinity = true
// Each node in this group will have the following labels
labels = {
managedBy = "terraform"
project = "uks-instructions"
}
// If uncommented, Eeach node in this group will have this taint
# taint {
# effect = "NoExecute"
# key = "key"
# value = "value"
# }
// Each node in this group will have keys defined in this list configured as authorized keys (for "debian" user)
ssh_keys = []
}
data "upcloud_kubernetes_cluster" "example" {
id = upcloud_kubernetes_cluster.example.id
}
# With `hashicorp/local` Terraform provider one can output the kubeconfig to a file. The file can be easily
# used to configure `kubectl` or any other Kubernetes client.
resource "local_file" "kubeconfig" {
count = var.store_kubeconfig ? 1 : 0
content = data.upcloud_kubernetes_cluster.example.kubeconfig
filename = "${path.module}/kubeconfig.yml"
}