sless-primer/hello-node/job.tf

53 lines
1.7 KiB
HCL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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
# filesha256 исходного файла — надёжнее чем output_md5 zip
code_hash = filesha256("${path.module}/code/handler-job.js")
}
# Одноразовый запуск. Все поля 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
}