-
Notifications
You must be signed in to change notification settings - Fork 0
/
rancher.tf
163 lines (137 loc) · 3.66 KB
/
rancher.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
resource "random_password" "rancher_bootstrap_password" {
length = 32
special = true
}
resource "kubernetes_namespace" "ingress_nginx" {
provider = kubernetes.rancher_cluster
metadata {
name = "ingress-nginx"
}
lifecycle {
ignore_changes = [
metadata.0.annotations,
metadata.0.labels,
]
}
}
resource "kubernetes_namespace" "cert_manager" {
provider = kubernetes.rancher_cluster
metadata {
name = "cert-manager"
}
lifecycle {
ignore_changes = [
metadata.0.annotations,
metadata.0.labels,
]
}
}
resource "kubernetes_namespace" "cattle_system" {
provider = kubernetes.rancher_cluster
metadata {
name = "cattle-system"
}
lifecycle {
ignore_changes = [
metadata.0.annotations,
metadata.0.labels,
]
}
}
resource "helm_release" "ingress_nginx" {
provider = helm.rancher_cluster
repository = "https://kubernetes.github.io/ingress-nginx"
chart = "ingress-nginx"
name = "ingress-nginx"
namespace = kubernetes_namespace.ingress_nginx.metadata.0.name
version = "4.11.2"
values = [<<-EOT
controller:
replicaCount: 2
watchIngressWithoutClass: true
EOT
]
}
resource "helm_release" "cert_manager" {
provider = helm.rancher_cluster
repository = "https://charts.jetstack.io"
chart = "cert-manager"
name = "cert-manager"
namespace = kubernetes_namespace.cert_manager.metadata.0.name
version = "v1.15.3"
values = [<<-EOT
installCRDs: true
extraArgs:
- --dns01-recursive-nameservers-only
- --dns01-recursive-nameservers=9.9.9.9:53,8.8.8.8:53
EOT
]
}
locals {
ingress_tls_source = var.cert_manager_cluster_issuer_yaml != null ? "secret" : "rancher"
}
resource "kubernetes_manifest" "cluster_issuer" {
provider = kubernetes.rancher_cluster
count = local.ingress_tls_source == "secret" ? 1 : 0
manifest = yamldecode(var.cert_manager_cluster_issuer_yaml)
depends_on = [
helm_release.cert_manager,
]
}
resource "kubernetes_manifest" "rancher_certificate" {
provider = kubernetes.rancher_cluster
count = local.ingress_tls_source == "secret" ? 1 : 0
manifest = {
apiVersion = "cert-manager.io/v1"
kind = "Certificate"
metadata = {
name = "rancher"
namespace = kubernetes_namespace.cattle_system.metadata.0.name
}
spec = {
secretName = "tls-rancher-ingress"
issuerRef = {
name = var.cert_manager_cluster_issuer_name
kind = "ClusterIssuer"
}
dnsNames = ["${var.rancher_hostname}"]
}
}
depends_on = [
kubernetes_manifest.cluster_issuer,
]
}
locals {
rancher_replicas = var.rancher_replicas == null ? var.cluster_size : var.rancher_replicas
}
resource "helm_release" "rancher" {
provider = helm.rancher_cluster
repository = "https://releases.rancher.com/server-charts/latest"
chart = "rancher"
name = "rancher"
namespace = kubernetes_namespace.cattle_system.metadata.0.name
version = var.rancher_chart_version
values = [<<-EOT
rancherImage: ${var.rancher_image_repo}
%{if var.rancher_image_tag != null}
rancherImageTag: ${var.rancher_image_tag}
%{endif}
hostname: ${var.rancher_hostname}
replicas: ${local.rancher_replicas}
ingress:
extraAnnotations:
# fix error code 413 with large helm deployments
"nginx.ingress.kubernetes.io/proxy-body-size": "512m"
tls:
source: ${local.ingress_tls_source}
EOT
]
set_sensitive {
name = "bootstrapPassword"
value = random_password.rancher_bootstrap_password.result
}
depends_on = [
kubernetes_manifest.rancher_certificate,
helm_release.ingress_nginx,
]
}