From 92a7171943ff40cb3d1f6d390677f7e9bb40894c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Sat, 7 Mar 2026 18:46:23 +0400 Subject: [PATCH] examples: auto-zip via hashicorp/archive, remove manual zip step --- hello-node/main.tf | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/hello-node/main.tf b/hello-node/main.tf index 9c3bab8..c5ce58b 100644 --- a/hello-node/main.tf +++ b/hello-node/main.tf @@ -6,6 +6,9 @@ # 2. После apply (~2 мин kaniko): # curl -s -X POST -H 'Content-Type: application/json' -d '{"name":"Naeel"}' # Ожидаемый ответ: {"message":"Hello, Naeel! (nodejs20)"} +# +# Zip собирается автоматически из handler.js через hashicorp/archive. +# Пересборка при изменении handler.js: просто terraform apply. terraform { required_providers { @@ -13,6 +16,10 @@ terraform { source = "terra.k8c.ru/naeel/sless" version = "~> 0.1.1" } + archive = { + source = "hashicorp/archive" + version = "~> 2.0" + } } } @@ -21,6 +28,13 @@ provider "sless" { token = "dev-token-change-me" } +# Автоматически собирает handler.zip из handler.js при каждом изменении файла +data "archive_file" "handler" { + type = "zip" + source_file = "${path.module}/handler.js" + output_path = "${path.module}/handler.zip" +} + resource "sless_function" "hello_node" { namespace = "default" name = "hello-node" @@ -29,8 +43,8 @@ resource "sless_function" "hello_node" { memory_mb = 128 timeout_sec = 30 - code_path = "${path.module}/handler.zip" - code_hash = filemd5("${path.module}/handler.zip") + code_path = data.archive_file.handler.output_path + code_hash = data.archive_file.handler.output_md5 } resource "sless_trigger" "hello_node_http" {