forked from kookmin-sw/cap-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
233 lines (204 loc) · 7.32 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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
provider "aws" {
region = var.region
profile = var.awscli_profile
}
provider "random" {}
resource "random_id" "random_string" {
byte_length = 8
}
resource "aws_s3_bucket" "tfstate_bucket" {
bucket = "sskai-terraform-state-${random_id.random_string.hex}"
force_destroy = true
}
module "kubernetes_cluster" {
source = "./IaC/kubernetes_cluster"
main_suffix = var.main_suffix
awscli_profile = var.awscli_profile
region = var.region
}
module "deploy_streamlit" {
source = "./automation/deploy_streamlit/IaC"
awscli_profile = var.awscli_profile
region = var.region
eks_cluster_name = module.kubernetes_cluster.cluster_name
db_api_url = module.deploy_db_api.api_endpoint_url
container_registry = var.container_registry
depends_on = [ module.kubernetes_cluster, module.deploy_db_api]
}
module "deploy_train" {
source = "./automation/deploy_train/IaC"
awscli_profile = var.awscli_profile
region = var.region
eks_cluster_name = module.kubernetes_cluster.cluster_name
db_api_url = module.deploy_db_api.api_endpoint_url
upload_s3_url = "${module.deploy_db_api.api_endpoint_url}/upload"
container_registry = var.container_registry
depends_on = [ module.kubernetes_cluster, module.deploy_db_api]
}
module "family_recommend" {
source = "./recommend/family_recommend/IaC"
container_registry = var.container_registry
awscli_profile = var.awscli_profile
region = var.region
}
module "karpenter_node_pool_deploy" {
source = "./automation/karpenter_node_pool_deploy/IaC"
awscli_profile = var.awscli_profile
region = var.region
eks_cluster_name = module.kubernetes_cluster.cluster_name
container_registry = var.container_registry
depends_on = [ module.kubernetes_cluster ]
}
module "kubernetes_inference_deploy" {
source = "./automation/kubernetes_inference_deploy/IaC"
awscli_profile = var.awscli_profile
region = var.region
eks_cluster_name = module.kubernetes_cluster.cluster_name
db_api_url = module.deploy_db_api.api_endpoint_url
container_registry = var.container_registry
depends_on = [ module.kubernetes_cluster, module.deploy_db_api ]
}
module "kubernetes_model_profiler_deploy" {
source = "./automation/kubernetes_model_profiler_deploy/IaC"
awscli_profile = var.awscli_profile
region = var.region
eks_cluster_name = module.kubernetes_cluster.cluster_name
db_api_url = module.deploy_db_api.api_endpoint_url
container_registry = var.container_registry
depends_on = [ module.kubernetes_cluster, module.deploy_db_api ]
}
module "serverless_inference_deploy" {
source = "./automation/serverless_inference_deploy/IaC"
awscli_profile = var.awscli_profile
region = var.region
db_api_url = module.deploy_db_api.api_endpoint_url
state_bucket_name = aws_s3_bucket.tfstate_bucket.bucket
container_registry = var.container_registry
depends_on = [ module.deploy_db_api ]
}
module "llama_inference_deploy" {
source = "./automation/llama_inference_deploy/IaC"
awscli_profile = var.awscli_profile
region = var.region
eks_cluster_name = module.kubernetes_cluster.cluster_name
db_api_url = module.deploy_db_api.api_endpoint_url
container_registry = var.container_registry
depends_on = [ module.kubernetes_cluster, module.deploy_db_api ]
}
module "diffusion_inference_deploy" {
source = "./automation/diffusion_inference_deploy/IaC"
awscli_profile = var.awscli_profile
region = var.region
eks_cluster_name = module.kubernetes_cluster.cluster_name
db_api_url = module.deploy_db_api.api_endpoint_url
container_registry = var.container_registry
depends_on = [ module.kubernetes_cluster, module.deploy_db_api ]
}
module "diffusion_train_deploy" {
source = "./automation/diffusion_train_deploy/IaC"
awscli_profile = var.awscli_profile
region = var.region
eks_cluster_name = module.kubernetes_cluster.cluster_name
db_api_url = module.deploy_db_api.api_endpoint_url
container_registry = var.container_registry
upload_s3_url = "${module.deploy_db_api.api_endpoint_url}/upload"
depends_on = [ module.kubernetes_cluster, module.deploy_db_api ]
}
module "llama_train_deploy" {
source = "./automation/llama_train_deploy/IaC"
awscli_profile = var.awscli_profile
region = var.region
eks_cluster_name = module.kubernetes_cluster.cluster_name
db_api_url = module.deploy_db_api.api_endpoint_url
container_registry = var.container_registry
upload_s3_url = "${module.deploy_db_api.api_endpoint_url}/upload"
depends_on = [ module.kubernetes_cluster, module.deploy_db_api ]
}
module "deploy_db_api" {
source = "./automation/deploy_db_api"
awscli_profile = var.awscli_profile
region = var.region
}
module "deploy_s3_web" {
source = "./automation/deploy_s3_web"
awscli_profile = var.awscli_profile
region = var.region
db_api_url = module.deploy_db_api.api_endpoint_url
diffusion_train_api_url = module.diffusion_train_deploy.diffusion_train_deploy_function_url
llama_train_api_url = module.llama_train_deploy.llama_train_deploy_function_url
inference_diffusion_api_url = module.diffusion_inference_deploy.diffusion_inference_deploy_function_url
inference_llama_api_url = module.llama_inference_deploy.llama_inference_deploy_function_url
streamlit_api_url = module.deploy_streamlit.streamlit_function_url
user_train_api_url = module.deploy_train.train_deploy_function_url
model_profile_api_url = module.kubernetes_model_profiler_deploy.kubernetes_model_profiler_deploy_function_url
inference_serverless_api_url = module.serverless_inference_deploy.function_url
inference_spot_api_url = module.kubernetes_inference_deploy.kubernetes_inference_deploy_function_url
depends_on = [ module.deploy_db_api ]
}
resource "aws_lambda_invocation" "nodepool_deploy" {
function_name = module.karpenter_node_pool_deploy.karpenter_nodepool_manager_function_name
input = jsonencode({
"a": "b"
})
}
resource "null_resource" "add_ddb_genai_record" {
provisioner "local-exec" {
command = <<EOT
aws s3 cp s3://sskai-model-storage/llama-2-7b-chat-hf.zip s3://${module.deploy_db_api.model_storage_bucket_name}/llama-2-7b-chat-hf.zip --profile ${var.awscli_profile} --region ${var.region}
aws s3 cp s3://sskai-model-storage/stable-diffusion.zip s3://${module.deploy_db_api.model_storage_bucket_name}/stable-diffusion.zip --profile ${var.awscli_profile} --region ${var.region}
aws dynamodb put-item --table-name sskai-models --profile ${var.awscli_profile} --region ${var.region} --item '{
"uid": {
"S": "llama"
},
"deploy_platform": {
"S": "nodepool-3"
},
"inference_time": {
"N": "0"
},
"max_used_gpu_mem": {
"N": "0"
},
"max_used_ram": {
"N": "2048"
},
"name": {
"S": "llama-2-7b-chat-hf"
},
"s3_url": {
"S": "https://${module.deploy_db_api.model_storage_bucket_name}.s3.${var.region}.amazonaws.com/llama-2-7b-chat-hf.zip"
},
"type": {
"S": "llama"
}
}'
aws dynamodb put-item --table-name sskai-models --profile ${var.awscli_profile} --region ${var.region} --item '{
"uid": {
"S": "diffusion"
},
"deploy_platform": {
"S": "nodepool-2"
},
"inference_time": {
"N": "0"
},
"max_used_gpu_mem": {
"N": "0"
},
"max_used_ram": {
"N": "2048"
},
"name": {
"S": "stable-diffusion-v1-4"
},
"s3_url": {
"S": "https://${module.deploy_db_api.model_storage_bucket_name}.s3.${var.region}.amazonaws.com/stable-diffusion.zip"
},
"type": {
"S": "diffusion"
}
}'
EOT
}
depends_on = [ module.deploy_db_api ]
}