feat: provider v0.1.10 — source_dir (zip внутри провайдера), убран archive провайдер из всех примеров

This commit is contained in:
“Naeel”
2026-03-09 17:45:45 +04:00
parent 6e236e5998
commit 5f913e9f25
16 changed files with 148 additions and 170 deletions
+2 -17
View File
@@ -1,17 +1,6 @@
# 2026-03-08
# 2026-03-08 / Изменено: 2026-03-09
# 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}/dist/handler-http.zip"
}
resource "sless_function" "hello_http" {
name = "hello-http"
@@ -20,17 +9,13 @@ resource "sless_function" "hello_http" {
memory_mb = 128
timeout_sec = 30
code_path = data.archive_file.handler_http.output_path
# filesha256 исходного файла — надёжнее чем output_md5 zip:
# MD5 zip зависит от метаданных архива и может совпасть при разном содержимом
code_hash = filesha256("${path.module}/code/handler-http.js")
source_dir = "${path.module}/code"
}
resource "sless_trigger" "hello_http" {
name = "hello-http-trigger"
type = "http"
function = sless_function.hello_http.name
# enabled = false — чтобы заморозить функцию (не удаляя ресурс), потом поставить зновь true
enabled = true
}
+3 -19
View File
@@ -1,19 +1,6 @@
# 2026-03-08
# 2026-03-08 / Изменено: 2026-03-09
# job.tf — одноразовая функция: суммирует числа из переданного массива.
# Код: code/handler-job.js
#
# Использование:
# terraform apply
# # apply блокируется до завершения джоба (~2 мин kaniko + выполнение)
# terraform output job_message
#
# Повторный запуск — изменить event_json и снова terraform apply.
data "archive_file" "handler_job" {
type = "zip"
source_file = "${path.module}/code/handler-job.js"
output_path = "${path.module}/dist/handler-job.zip"
}
resource "sless_function" "hello_job" {
name = "hello-job"
@@ -22,13 +9,10 @@ resource "sless_function" "hello_job" {
memory_mb = 128
timeout_sec = 30
code_path = data.archive_file.handler_job.output_path
# filesha256 исходного файла — надёжнее чем output_md5 zip
code_hash = filesha256("${path.module}/code/handler-job.js")
source_dir = "${path.module}/code"
}
# Одноразовый запуск. Все поля immutable — изменение любого пересоздаёт джоб.
# run_id: 0 = не запускать, 1+ = запустить. Для повторного запуска увеличь run_id (1→2→3...).
# Одноразовый запуск. Для повторного запуска увеличь run_id (1→2→3...).
resource "sless_job" "hello_run" {
name = "hello-run"
function = sless_function.hello_job.name
+1 -5
View File
@@ -8,11 +8,7 @@ terraform {
required_providers {
sless = {
source = "terra.k8c.ru/naeel/sless"
version = "~> 0.1.9"
}
archive = {
source = "hashicorp/archive"
version = "~> 2.0"
version = "~> 0.1.10"
}
}
}