Deploying an Event Function using Terraform

This section describes on how to deploy an Event Function using Terraform.

Prerequisite

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

    resource "opentelekomcloud_functiongraph_function_v2" "MyEventFunction" {
      ...
      code_type     = "zip"
      func_code     = filebase64(var.zip_file_local)
      code_filename = basename(var.zip_file_local)
      ...
    }
    
  • configure an Timer Trigger for the Function

    • of type TIMER

    • using a cron expression triggering every 3 minutes

    see: api_trigger.tf

  • configure logging for the Function using LTS Log Group and Log Stream, see function.tf

  • configure test events for the Function to be used in the Function Graph console, see func_testevents.tf

To deploy the Event Function using terraform follow these steps:

  1. Adjust the net6.tfvars file 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"
    
  2. To deploy using the terraform/http.tfvars configuration, execute the following commands in the project folder of http_minimalWebAPI:

    make deploy
    

Note

To destroy the deployed resources again you can use:

make destroy