-
Notifications
You must be signed in to change notification settings - Fork 0
/
digital-ocean.tf
102 lines (86 loc) · 2.8 KB
/
digital-ocean.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
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "~> 2.0"
}
}
}
variable "do_token" {}
provider "digitalocean" {
token = var.do_token
}
resource "digitalocean_custom_image" "talos" {
name = "talos"
url = "https://github.com/antonleviathan/talos-image/raw/3879e5d8bfaaa1a8368f21b06abd1db64a8d2aa6/disk.raw"
regions = ["sfo3"]
}
resource "digitalocean_ssh_key" "dummy" {
# DigitalOcean requires a key when deploying an image even if the machine
# will not have SSH access
name = "Dummy Talos Key"
public_key = file("files/dummy_key.pub")
}
resource "digitalocean_loadbalancer" "public" {
name = "loadbalancer-1"
region = "sfo3"
forwarding_rule {
entry_port = 443
entry_protocol = "tcp"
target_port = 6443
target_protocol = "tcp"
}
healthcheck {
port = 6443
protocol = "tcp"
check_interval_seconds = 10
response_timeout_seconds = 5
healthy_threshold = 5
unhealthy_threshold = 3
}
droplet_tag = "talos-digital-ocean-control-plane"
provisioner "local-exec" {
command = "sh scripts/init-talos-config.sh ${self.ip}"
}
}
data "local_file" "controlplane" {
depends_on = [digitalocean_loadbalancer.public]
filename = "${path.module}/talos-config/controlplane.yaml"
}
data "local_file" "worker" {
depends_on = [digitalocean_loadbalancer.public]
filename = "${path.module}/talos-config/worker.yaml"
}
resource "digitalocean_droplet" "control-plane" {
// Depends on LB as it generates the configs used as `user_data`
depends_on = [digitalocean_loadbalancer.public]
count = 3
name = "talos-control-plane-${count.index}"
region = "sfo3"
image = digitalocean_custom_image.talos.id
size = "s-2vcpu-4gb"
# required by load balancer for routing purposes
tags = ["talos-digital-ocean-control-plane"]
user_data = data.local_file.controlplane.content
ssh_keys = [digitalocean_ssh_key.dummy.fingerprint]
}
resource "digitalocean_droplet" "worker" {
// Depends on LB as it generates the configs used as `user_data`
depends_on = [digitalocean_loadbalancer.public, digitalocean_droplet.control-plane]
name = "talos-worker-node-1"
region = "sfo3"
image = digitalocean_custom_image.talos.id
size = "s-2vcpu-4gb"
user_data = data.local_file.worker.content
ssh_keys = [digitalocean_ssh_key.dummy.fingerprint]
}
# TODO(RyanSquared): Commenting this part out until I get Kustomizations built
# for all the necessary resources
/*
resource "null_resource" "init-cluster" {
depends_on = [digitalocean_droplet.worker]
provisioner "local-exec" {
command = "sh scripts/init-cluster.sh ${digitalocean_droplet.control-plane[0].ipv4_address}"
}
}
*/