From 9d922de489812ae9f83f483902f45ae7f1452871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Sat, 7 Mar 2026 23:05:09 +0400 Subject: [PATCH] examples: switch hello-node to sless_job (one-shot run) --- hello-node/main.tf | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/hello-node/main.tf b/hello-node/main.tf index c5ce58b..2abdde1 100644 --- a/hello-node/main.tf +++ b/hello-node/main.tf @@ -1,14 +1,13 @@ # 2026-03-07 -# main.tf — e2e тест: hello-world функция на Node.js 20. +# main.tf — пример одноразового запуска serverless функции (sless_job) на Node.js 20. # # Использование: # 1. terraform init && terraform apply -# 2. После apply (~2 мин kaniko): -# curl -s -X POST -H 'Content-Type: application/json' -d '{"name":"Naeel"}' -# Ожидаемый ответ: {"message":"Hello, Naeel! (nodejs20)"} +# 2. apply блокируется: сначала ~2 мин kaniko собирает образ, затем ждёт завершения джоба +# 3. После apply в output — результат выполнения функции (phase, message, completion_time) # # Zip собирается автоматически из handler.js через hashicorp/archive. -# Пересборка при изменении handler.js: просто terraform apply. +# Пересборка + повторный запуск при изменении handler.js или event_json: terraform apply. terraform { required_providers { @@ -47,13 +46,24 @@ resource "sless_function" "hello_node" { code_hash = data.archive_file.handler.output_md5 } -resource "sless_trigger" "hello_node_http" { - namespace = "default" - name = "hello-node-http" - type = "http" - function = sless_function.hello_node.name +# Одноразовый запуск функции. terraform apply ждёт завершения джоба. +# Чтобы перезапустить — изменить event_json (или любое поле) и снова apply. +resource "sless_job" "hello_run" { + namespace = "default" + name = "hello-run" + function = sless_function.hello_node.name + event_json = jsonencode({ name = "Naeel" }) + wait_timeout_sec = 120 } -output "trigger_url" { - value = sless_trigger.hello_node_http.url +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 }