-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
110 lines (95 loc) · 2.74 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
terraform {
required_providers {
helm = {
source = "hashicorp/helm"
version = "2.5.1"
}
rancher2 = {
source = "rancher/rancher2"
version = "1.23.0"
}
}
}
provider "helm" {
kubernetes {
host = var.kubernetes_api_server_url
client_certificate = var.kubernetes_client_cert
client_key = var.kubernetes_client_key
cluster_ca_certificate = var.kubernetes_ca_crt
}
}
provider "rancher2" {
alias = "bootstrap"
api_url = local.rancher_hosturl
bootstrap = true
insecure = true
}
provider "rancher2" {
alias = "admin"
api_url = local.rancher_hosturl
token_key = rancher2_bootstrap.setup_admin.token
insecure = true
}
locals {
rancher_hosturl = var.rancher_hostname != null ? "https://${var.rancher_hostname}" : "https://rancher.${var.lb_address}.nip.io"
rancher_hostname = var.rancher_hostname != null ? "${var.rancher_hostname}" : "rancher.${var.lb_address}.nip.io"
}
resource "helm_release" "cert_manager" {
name = "cert-manager"
namespace = "cert-manager"
repository = "https://charts.jetstack.io"
chart = "cert-manager"
version = var.cert_manager_version
wait = true
create_namespace = true
force_update = true
replace = true
set {
name = "installCRDs"
value = true
}
}
resource "helm_release" "rancher" {
name = "rancher"
namespace = "cattle-system"
chart = "rancher"
repository = "https://releases.rancher.com/server-charts/stable"
version = var.rancher_version
depends_on = [helm_release.cert_manager]
wait = true
create_namespace = true
force_update = true
replace = true
set {
name = "hostname"
value = local.rancher_hostname
}
set {
name = "ingress.tls.source"
value = "letsEncrypt"
}
set {
name = "letsEncrypt.email"
value = var.letsencrypt_issuer
}
set {
name = "bootstrapPassword"
value = var.rancher_admin_password
}
}
resource "rancher2_bootstrap" "setup_admin" {
provider = rancher2.bootstrap
password = var.rancher_admin_password
initial_password = var.rancher_admin_password
telemetry = true
depends_on = [helm_release.rancher]
}
resource "rancher2_node_driver" "hetzner_node_driver" {
provider = rancher2.admin
active = true
builtin = false
name = "hetzner"
ui_url = "https://storage.googleapis.com/hcloud-rancher-v2-ui-driver/component.js"
url = "https://github.com/JonasProgrammer/docker-machine-driver-hetzner/releases/download/3.3.1/docker-machine-driver-hetzner_3.3.1_linux_amd64.tar.gz"
whitelist_domains = ["storage.googleapis.com"]
}