-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
64 lines (57 loc) · 1.31 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
resource "kubernetes_namespace" "example_namespace" {
metadata {
name = "${var.label}-namespace"
}
}
resource "kubernetes_service" "example_service" {
metadata {
name = "${var.label}-service"
namespace = kubernetes_namespace.example_namespace.metadata[0].name
labels = {
app = kubernetes_deployment.example_deployment.metadata[0].labels.app
}
}
spec {
selector = {
app = kubernetes_deployment.example_deployment.metadata[0].labels.app
}
port {
port = var.service_internal_port
target_port = kubernetes_deployment.example_deployment.spec[0].template[0].spec[0].container[0].port[0].container_port
}
type = var.service_exposure
}
}
resource "kubernetes_deployment" "example_deployment" {
metadata {
name = "${var.label}-deployment"
namespace = kubernetes_namespace.example_namespace.metadata[0].name
labels = {
app = var.label
}
}
spec {
replicas = 2
selector {
match_labels = {
app = var.label
}
}
template {
metadata {
labels = {
app = var.label
}
}
spec {
container {
name = var.label
image = var.image
port {
container_port = var.container_port
}
}
}
}
}
}