refactor: pg-query — code/ исходники, dist/ zip, archive_file datasource

This commit is contained in:
“Naeel”
2026-03-09 09:07:57 +04:00
parent e8497644e6
commit 237a636097
3 changed files with 19 additions and 7 deletions
+19 -7
View File
@@ -1,11 +1,13 @@
# 2026-03-07
# 2026-03-09
# main.tf — e2e тест: создать serverless функцию, которая читает из PostgreSQL.
#
# Структура:
# code/ — исходники (handler.py, requirements.txt)
# dist/ — zip-архив (генерируется archive_file datasource)
#
# Использование:
# 1. zip handler.py + requirements.txt:
# zip handler.zip handler.py requirements.txt
# 2. terraform init && terraform apply
# 3. После apply (ждёт ~2 мин пока kaniko соберёт образ):
# terraform init && terraform apply
# После apply (ждёт ~2 мин пока kaniko соберёт образ):
# curl -s -X POST <url_из_trigger> -d '{}'
#
# Оператор запущен в кластере: https://sless-api.kube5s.ru
@@ -18,6 +20,10 @@ terraform {
source = "terra.k8c.ru/naeel/sless"
version = "~> 0.1.7"
}
archive = {
source = "hashicorp/archive"
version = "~> 2.0"
}
}
}
@@ -26,6 +32,12 @@ provider "sless" {
token = "dev-token-change-me"
}
data "archive_file" "handler_pg_query" {
type = "zip"
source_dir = "${path.module}/code"
output_path = "${path.module}/dist/handler.zip"
}
resource "sless_function" "pg_query" {
namespace = "default"
name = "pg-query"
@@ -40,8 +52,8 @@ resource "sless_function" "pg_query" {
PG_DSN = "postgres://sless:sless-pg-password@postgres.sless.svc.cluster.local:5432/sless?sslmode=disable"
}
code_path = "${path.module}/handler.zip"
code_hash = filesha256("${path.module}/handler.py")
code_path = data.archive_file.handler_pg_query.output_path
code_hash = filesha256("${path.module}/code/handler.py")
}
resource "sless_trigger" "pg_query_http" {