sless-primer/hello-node/http.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

40 lines
1.2 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
# http.tf — HTTP-функция: принимает запросы, возвращает приветствие.
# Код: code/handler-http.js
#
# Использование:
# terraform apply
# curl -s -X POST $(terraform output -raw trigger_url) \
# -H 'Content-Type: application/json' -d '{"name":"Naeel"}'
data "archive_file" "handler_http" {
type = "zip"
source_file = "${path.module}/code/handler-http.js"
output_path = "${path.module}/handler-http.zip"
}
resource "sless_function" "hello_http" {
namespace = "default"
name = "hello-http"
runtime = "nodejs20"
entrypoint = "handler-http.handle"
memory_mb = 128
timeout_sec = 30
code_path = data.archive_file.handler_http.output_path
code_hash = data.archive_file.handler_http.output_md5
}
resource "sless_trigger" "hello_http" {
namespace = "default"
name = "hello-http-trigger"
type = "http"
function = sless_function.hello_http.name
# enabled = false — чтобы заморозить функцию (не удаляя ресурс), потом поставить зновь true
enabled = true
}
output "trigger_url" {
value = sless_trigger.hello_http.url
}