examples: switch hello-node to sless_job (one-shot run)
This commit is contained in:
parent
92a7171943
commit
9d922de489
@ -1,14 +1,13 @@
|
|||||||
# 2026-03-07
|
# 2026-03-07
|
||||||
# main.tf — e2e тест: hello-world функция на Node.js 20.
|
# main.tf — пример одноразового запуска serverless функции (sless_job) на Node.js 20.
|
||||||
#
|
#
|
||||||
# Использование:
|
# Использование:
|
||||||
# 1. terraform init && terraform apply
|
# 1. terraform init && terraform apply
|
||||||
# 2. После apply (~2 мин kaniko):
|
# 2. apply блокируется: сначала ~2 мин kaniko собирает образ, затем ждёт завершения джоба
|
||||||
# curl -s -X POST <trigger_url> -H 'Content-Type: application/json' -d '{"name":"Naeel"}'
|
# 3. После apply в output — результат выполнения функции (phase, message, completion_time)
|
||||||
# Ожидаемый ответ: {"message":"Hello, Naeel! (nodejs20)"}
|
|
||||||
#
|
#
|
||||||
# Zip собирается автоматически из handler.js через hashicorp/archive.
|
# Zip собирается автоматически из handler.js через hashicorp/archive.
|
||||||
# Пересборка при изменении handler.js: просто terraform apply.
|
# Пересборка + повторный запуск при изменении handler.js или event_json: terraform apply.
|
||||||
|
|
||||||
terraform {
|
terraform {
|
||||||
required_providers {
|
required_providers {
|
||||||
@ -47,13 +46,24 @@ resource "sless_function" "hello_node" {
|
|||||||
code_hash = data.archive_file.handler.output_md5
|
code_hash = data.archive_file.handler.output_md5
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "sless_trigger" "hello_node_http" {
|
# Одноразовый запуск функции. terraform apply ждёт завершения джоба.
|
||||||
namespace = "default"
|
# Чтобы перезапустить — изменить event_json (или любое поле) и снова apply.
|
||||||
name = "hello-node-http"
|
resource "sless_job" "hello_run" {
|
||||||
type = "http"
|
namespace = "default"
|
||||||
function = sless_function.hello_node.name
|
name = "hello-run"
|
||||||
|
function = sless_function.hello_node.name
|
||||||
|
event_json = jsonencode({ name = "Naeel" })
|
||||||
|
wait_timeout_sec = 120
|
||||||
}
|
}
|
||||||
|
|
||||||
output "trigger_url" {
|
output "job_phase" {
|
||||||
value = sless_trigger.hello_node_http.url
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user