forked from castai/terraform-provider-castai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
163 lines (147 loc) · 3.91 KB
/
main.tf
File metadata and controls
163 lines (147 loc) · 3.91 KB
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
# Start Minikube using the Docker driver
resource "null_resource" "start_minikube" {
provisioner "local-exec" {
command = "minikube start --driver=docker"
}
}
# Wait for Minikube to be ready
data "external" "wait_for_minikube" {
program = ["bash", "-c", "while ! kubectl get nodes >/dev/null 2>&1; do sleep 5; done; echo '{}'"]
depends_on = [null_resource.start_minikube]
}
# Configure the Kubernetes provider
provider "kubernetes" {
config_path = "~/.kube/config"
config_context = "minikube"
}
# Configure the Helm provider
provider "helm" {
kubernetes {
config_path = "~/.kube/config"
config_context = "minikube"
}
}
# Create the namespace "castai-agent"
resource "kubernetes_namespace" "castai" {
depends_on = [data.external.wait_for_minikube]
metadata {
name = "castai-agent"
labels = {
"app.kubernetes.io/managed-by" = "Helm"
}
annotations = {
"meta.helm.sh/release-name" = "castai-agent"
"meta.helm.sh/release-namespace" = "castai-agent"
}
}
}
# Install CAST AI Agent
resource "helm_release" "castai_agent" {
depends_on = [kubernetes_namespace.castai]
name = "castai-agent"
repository = "https://castai.github.io/helm-charts"
chart = "castai-agent"
namespace = "castai-agent"
create_namespace = false
timeout = 600
set {
name = "apiKey"
value = var.cast_ai_api_key
}
set {
name = "clusterName"
value = var.cluster_name
}
set {
name = "provider"
value = "anywhere"
}
}
# Install CAST AI Cluster Controller
resource "helm_release" "castai_cluster_controller" {
depends_on = [helm_release.castai_agent]
name = "castai-cluster-controller"
repository = "https://castai.github.io/helm-charts"
chart = "castai-cluster-controller"
namespace = "castai-agent"
create_namespace = false
timeout = 600
set {
name = "castai.apiKey"
value = var.cast_ai_api_key
}
set {
name = "castai.clusterID"
value = var.cluster_id
}
set {
name = "enableTopologySpreadConstraints"
value = "true"
}
}
# Install CAST AI Evictor
resource "helm_release" "castai_evictor" {
depends_on = [helm_release.castai_cluster_controller]
name = "castai-evictor"
repository = "https://castai.github.io/helm-charts"
chart = "castai-evictor"
namespace = "castai-agent"
create_namespace = false
timeout = 600
set {
name = "managedByCASTAI"
value = var.managed_by_castai
}
set {
name = "replicaCount"
value = "1"
}
set {
name = "aggressive_mode"
value = "false" # change to true if needed but use with caution
}
}
# Install CAST AI Pod Mutator
resource "helm_release" "castai_pod_mutator" {
depends_on = [helm_release.castai_cluster_controller]
name = "castai-pod-mutator"
repository = "https://castai.github.io/helm-charts"
chart = "castai-pod-mutator"
namespace = "castai-agent"
create_namespace = false
timeout = 600
set {
name = "castai.apiKey"
value = var.cast_ai_api_key
}
set {
name = "castai.clusterID"
value = var.cluster_id
}
set {
name = "enableTopologySpreadConstraints"
value = "true"
}
set {
name = "castai.organizationID"
value = var.organization_id
}
}
# Install CAST AI Workload Autoscaler
resource "helm_release" "castai_workload_autoscaler" {
depends_on = [helm_release.castai_pod_mutator]
name = "castai-workload-autoscaler"
repository = "https://castai.github.io/helm-charts"
chart = "castai-workload-autoscaler"
namespace = "castai-agent"
create_namespace = false
timeout = 600
set {
name = "castai.apiKey"
value = var.cast_ai_api_key
}
set {
name = "castai.clusterID"
value = var.cluster_id
}
}