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 файлы
47 lines
1.8 KiB
HCL
47 lines
1.8 KiB
HCL
# 2026-03-09
|
|
# notes.tf — CRUD функция для управления заметками (CREATE / UPDATE / DELETE).
|
|
#
|
|
# Одна функция обрабатывает все операции — роутинг по sub-path URL.
|
|
# Sub-path и query string пробрасывает прокси (invoke.go) → runtime добавляет
|
|
# их в event как _path и _query.
|
|
#
|
|
# Маршруты (все методы принимаются, рекомендуется POST):
|
|
# /fn/default/notes/add?title=...&body=... → INSERT, возвращает запись
|
|
# /fn/default/notes/update?id=1&title=...&body=... → UPDATE, возвращает запись
|
|
# /fn/default/notes/delete?id=1 → DELETE, возвращает {deleted: id}
|
|
|
|
# Упаковка исходников notes_crud.py в zip.
|
|
data "archive_file" "notes_crud_zip" {
|
|
type = "zip"
|
|
source_dir = "${path.module}/code/notes"
|
|
output_path = "${path.module}/dist/notes.zip"
|
|
}
|
|
|
|
# CRUD функция в кластере.
|
|
# entrypoint = "notes_crud.handle" → файл notes_crud.py, функция handle().
|
|
resource "sless_function" "notes_crud" {
|
|
namespace = "default"
|
|
name = "notes"
|
|
runtime = "python3.11"
|
|
entrypoint = "notes_crud.handle"
|
|
memory_mb = 128
|
|
timeout_sec = 30
|
|
|
|
env_vars = {
|
|
PG_DSN = var.pg_dsn
|
|
}
|
|
|
|
code_path = data.archive_file.notes_crud_zip.output_path
|
|
code_hash = filesha256("${path.module}/code/notes/notes_crud.py")
|
|
}
|
|
|
|
# HTTP-триггер для CRUD функции.
|
|
# Создаёт Ingress в кластере, URL доступен в outputs.tf.
|
|
# Базовый URL: https://sless-api.kube5s.ru/fn/default/notes
|
|
resource "sless_trigger" "notes_crud_http" {
|
|
namespace = "default"
|
|
name = "notes-http"
|
|
type = "http"
|
|
function = sless_function.notes_crud.name
|
|
}
|