forked from terraform-iaac/terraform-kubernetes-ingress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
88 lines (83 loc) · 2.24 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
resource "kubernetes_ingress_v1" "ingress" {
count = var.ingress_v1_enable ? 1 : 0
metadata {
name = var.ingress_name != null ? var.ingress_name : var.service_name
namespace = var.service_namespace
annotations = var.annotations
}
spec {
ingress_class_name = var.ingress_class_name
dynamic "rule" {
for_each = var.rule
content {
host = "${rule.value.sub_domain}${rule.value.domain == null ? var.domain_name : rule.value.domain}"
http {
path {
path = rule.value.path
path_type = rule.value.path_type == null ? var.path_type : rule.value.path_type
backend {
service {
name = rule.value.service_name == null ? var.service_name : rule.value.service_name
port {
number = rule.value.external_port
}
}
}
}
}
}
}
dynamic "tls" {
for_each = var.tls
content {
secret_name = tls.value
}
}
dynamic "tls" {
for_each = var.tls_hosts
content {
secret_name = tls.value.secret_name
hosts = tls.value.hosts
}
}
}
}
resource "kubernetes_ingress" "ingress" {
count = var.ingress_v1_enable ? 0 : 1
metadata {
name = var.ingress_name != null ? var.ingress_name : var.service_name
namespace = var.service_namespace
annotations = var.annotations
}
spec {
ingress_class_name = var.ingress_class_name
dynamic "rule" {
for_each = var.rule
content {
host = "${rule.value.sub_domain}${rule.value.domain == null ? var.domain_name : rule.value.domain}"
http {
path {
path = rule.value.path
backend {
service_name = rule.value.service_name == null ? var.service_name : rule.value.service_name
service_port = rule.value.external_port
}
}
}
}
}
dynamic "tls" {
for_each = var.tls
content {
secret_name = tls.value
}
}
dynamic "tls" {
for_each = var.tls_hosts
content {
secret_name = tls.value.secret_name
hosts = tls.value.hosts
}
}
}
}