# 2026-03-08 # job.tf — одноразовая функция: суммирует числа из переданного массива. # Код: code/handler-job.js # # Использование: # terraform apply # # apply блокируется до завершения джоба (~2 мин kaniko + выполнение) # terraform output job_message # # Повторный запуск — изменить event_json и снова terraform apply. data "archive_file" "handler_job" { type = "zip" source_file = "${path.module}/code/handler-job.js" output_path = "${path.module}/handler-job.zip" } resource "sless_function" "hello_job" { namespace = "default" name = "hello-job" runtime = "nodejs20" entrypoint = "handler-job.handle" memory_mb = 128 timeout_sec = 30 code_path = data.archive_file.handler_job.output_path code_hash = data.archive_file.handler_job.output_md5 } # Одноразовый запуск. Все поля immutable — изменение любого пересоздаёт джоб. # run_id: 0 = не запускать, 1+ = запустить. Для повторного запуска увеличь run_id (1→2→3...). resource "sless_job" "hello_run" { namespace = "default" name = "hello-run" function = sless_function.hello_job.name event_json = jsonencode({ numbers = [1, 2, 3, 4, 5] }) wait_timeout_sec = 600 run_id = 1 } output "job_phase" { value = sless_job.hello_run.phase } output "job_message" { value = sless_job.hello_run.message } output "job_completion_time" { value = sless_job.hello_run.completion_time }