Python файлы: - handler.py → sql_runner.py (entrypoint: sql_runner.handle) - handler.py → notes_crud.py (entrypoint: notes_crud.handle) - handler.py → notes_list.py (entrypoint: notes_list.handle) TF ресурсы переименованы: - sless_function.notes → sless_function.notes_crud - sless_trigger.notes_http → sless_trigger.notes_crud_http - sless_job.create_table → sless_job.notes_table_init - sless_job.create_index → sless_job.notes_index_init - archive_file.notes → archive_file.notes_crud_zip - archive_file.sql_runner → archive_file.sql_runner_zip - archive_file.notes_list → archive_file.notes_list_zip Добавлены подробные комментарии во все .tf файлы
44 lines
1.5 KiB
HCL
44 lines
1.5 KiB
HCL
# 2026-03-09
|
|
# notes-list.tf — функция для чтения всех заметок одним запросом.
|
|
#
|
|
# Отдельная от CRUD функция — «read-only» эндпоинт без роутинга.
|
|
# Принимает GET или POST, параметры игнорирует.
|
|
# Возвращает JSON-массив всех записей, сортировка: новые первые.
|
|
#
|
|
# Пример запроса:
|
|
# curl https://sless-api.kube5s.ru/fn/default/notes-list
|
|
|
|
# Упаковка исходников notes_list.py в zip.
|
|
data "archive_file" "notes_list_zip" {
|
|
type = "zip"
|
|
source_dir = "${path.module}/code/notes-list"
|
|
output_path = "${path.module}/dist/notes-list.zip"
|
|
}
|
|
|
|
# Read-only функция в кластере.
|
|
# entrypoint = "notes_list.handle" → файл notes_list.py, функция handle().
|
|
resource "sless_function" "notes_list" {
|
|
namespace = "default"
|
|
name = "notes-list"
|
|
runtime = "python3.11"
|
|
entrypoint = "notes_list.handle"
|
|
memory_mb = 128
|
|
timeout_sec = 30
|
|
|
|
env_vars = {
|
|
PG_DSN = var.pg_dsn
|
|
}
|
|
|
|
code_path = data.archive_file.notes_list_zip.output_path
|
|
code_hash = filesha256("${path.module}/code/notes-list/notes_list.py")
|
|
}
|
|
|
|
# HTTP-триггер для read-only функции.
|
|
# Создаёт Ingress, URL доступен в outputs.tf.
|
|
resource "sless_trigger" "notes_list_http" {
|
|
namespace = "default"
|
|
name = "notes-list-http"
|
|
type = "http"
|
|
function = sless_function.notes_list.name
|
|
}
|