examples: switch hello-node to sless_job (one-shot run)

This commit is contained in:
“Naeel” 2026-03-07 23:05:09 +04:00
parent 92a7171943
commit 9d922de489

View File

@ -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 <trigger_url> -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" {
# Одноразовый запуск функции. terraform apply ждёт завершения джоба.
# Чтобы перезапустить изменить event_json (или любое поле) и снова apply.
resource "sless_job" "hello_run" {
namespace = "default"
name = "hello-node-http"
type = "http"
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
}