Deploy FunctionGraph Event Function from ZIP¶
This sample demonstrates how to deploy a simple event function to FunctionGraph with code from ZIP using Terraform.
This approach is used, if your unpacked FunctionGraph deployment package is less than 40MB.
Prerequisites¶
running on Linux / Windows Subsystem for Linux (WSL)
make installed
Terraform/OpenTofu installed and Terraform/OpenTofu configured, see Terraform Setup.
Example¶
An example for deploying a Event Function using Terraform can be found in: samples-doc/event-timer/terraform.
This example deploys a Event Function (C# .NET 6) and demonstrates how to:
create the Function using the code from zip file uploaded in function, see: function.tf
########################################################## # Create Function ########################################################## resource "opentelekomcloud_fgs_function_v2" "MyFunction" { name = format("%s_%s", var.prefix, var.function_name) app = "default" handler = var.function_handler_name description = "Sample for timer triggered FunctionGraph using terraform." memory_size = 128 timeout = 30 max_instance_num = 10 runtime = var.function_runtime # -------------------------------------------------------------- # # Upload code as ZIP file directly code_type = "zip" func_code = filebase64(var.zip_file_local) code_filename = basename(var.zip_file_local) # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # log_group_id = opentelekomcloud_lts_group_v2.MyLogGroup.id log_group_name = opentelekomcloud_lts_group_v2.MyLogGroup.group_name log_topic_id = opentelekomcloud_lts_stream_v2.MyLogStream.id log_topic_name = opentelekomcloud_lts_stream_v2.MyLogStream.stream_name tags = { "app_group" = var.tag_app_group } } output "MY_FUNCTION_URN" { value = opentelekomcloud_fgs_function_v2.MyFunction.urn } output "MY_FUNCTION_VERSION" { value = opentelekomcloud_fgs_function_v2.MyFunction.version }
configure an Timer Trigger for the Function
of type TIMER
using a cron expression triggering every 3 minutes
see: trigger_timer.tf
########################################################## # Create Trigger ########################################################## resource "opentelekomcloud_fgs_trigger_v2" "timer_cron" { function_urn = opentelekomcloud_fgs_function_v2.MyFunction.urn type = "TIMER" event_data = jsonencode({ "name" : "CronTrigger_3m", "schedule_type" : "Cron", "user_event" : "Created by terraform script", "schedule" : "@every 3m" }) }
configure logging for the Function using LTS Log Group and Log Stream, see loggroup.tf
########################################################## # Create Log Group ########################################################## resource "opentelekomcloud_lts_group_v2" "MyLogGroup" { group_name = format("%s_%s_%s", var.prefix, var.function_name, "log_group") ttl_in_days = 1 tags = { "app_group" = var.tag_app_group } } ########################################################## # Create Log Stream ########################################################## resource "opentelekomcloud_lts_stream_v2" "MyLogStream" { group_id = opentelekomcloud_lts_group_v2.MyLogGroup.id stream_name = format("%s_%s_%s", var.prefix, var.function_name, "log_stream") tags = { "app_group" = var.tag_app_group } }
configure test events for the Function to be used in the Function Graph console, see testevent.tf
########################################################## # Create Test Event ########################################################## resource "opentelekomcloud_fgs_event_v2" "test_event" { function_urn = opentelekomcloud_fgs_function_v2.MyFunction.urn name = "timer-test-event" content = base64encode(jsonencode({ "version" = "v1.0", "time" = "2025-10-24T08:30:00+08:00", "trigger_type" = "TIMER", "trigger_name" = "timer-test-event", "user_event" = "Test event created by terraform script" })) }
To deploy the Event Function using terraform follow these steps:
Adjust the
net6.tfvarsfile according to your needs.# Terraform variables for event-timer sample # prefix of all resources prefix="csharp" # name of the function (will be prefixed) function_name="doc-sample-event-timer-csharp" # function handler name, see handler.txt function_handler_name="event_timer::src.Program::Handler" # function runtime, use ".NET Core 6.0" in this sample function_runtime="C#(.NET Core 6.0)" # path to local zip file to be deployed created # by 'dotnet build' command zip_file_local="../src/event_timer_net6.0.zip" # resources will be tagged with this app_group tag tag_app_group="csharp-doc-sample-event-timer"
Create a Makefile in the project folder and adjust the variables in the Makefile according to your needs:
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))/.. current_dir := $(notdir $(patsubst %/,%,$(dir $(mkfile_path)))) BACKEND_CONFIG_BUCKET := "doc-samples-tf-backend" BACKEND_CONFIG_KEY := "terraform_state/csharp/doc-sample-event-timer.tf" BACKEND_CONFIG_REGION := "eu-de" BACKEND_CONFIG_ENDPOINTS := "endpoints={s3=\"https://obs.eu-de.otc.t-systems.com\"}" clean: rm -f $(mkfile_path)/src/*.zip rm -rf $(mkfile_path)/src/bin rm -rf $(mkfile_path)/src/obj build: dotnet build all: build release: dotnet build -c Release initTerraform: terraform -chdir=terraform \ init \ -backend-config=$(BACKEND_CONFIG_ENDPOINTS) \ -backend-config="bucket=$(BACKEND_CONFIG_BUCKET)" \ -backend-config="key=$(BACKEND_CONFIG_KEY)" \ -backend-config="region=$(BACKEND_CONFIG_REGION)" plan: release if [ ! -f "terraform/.terraform.lock.hcl" ]; then \ $(MAKE) initTerraform; \ fi terraform -chdir=terraform \ plan \ -var-file="net6.tfvars" deploy: release if [ ! -f "terraform/.terraform.lock.hcl" ]; then \ $(MAKE) initTerraform; \ fi terraform -chdir=terraform \ apply -auto-approve \ -var-file="net6.tfvars" destroy: terraform -chdir=terraform \ destroy -auto-approve \ -var-file="net6.tfvars" .PHONY: build zip clean all release deploy destroy initTerraform plan
To deploy using the terraform/http.tfvars configuration, execute the following commands in the project root folder:
make deploy
Note
To destroy the deployed resources again you can use:
make destroy