sless-primer/hello-node/job.tf
“Naeel” 1770a9b84b feat: trigger.enabled + job.run_id lifecycle control (operator v0.1.6, provider v0.1.4)
- TriggerSpec.Enabled bool (default=true): enabled=false масштабирует Deployment до 0
- FunctionJobSpec.RunID int64 (default=0): run_id=0 = skip, >0 = run
- API: PATCH /v1/namespaces/{ns}/triggers/{name} (UpdateTrigger)
- Provider: enabled attribute (Optional, Computed, in-place update)
- Provider: run_id attribute (Optional, Computed, default=0, RequiresReplace)
- operator image: naeel/sless-operator:v0.1.6
- provider: terra.k8c.ru/naeel/sless v0.1.4
2026-03-08 10:10:32 +04:00

52 lines
1.6 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
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 = 120
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
}