Deploying a HTTP Function using Terraform

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

Prerequisite

Example

An example for deploying a HTTP Function using Terraform can be found in: samples-doc/http_minimalWebAPI/terraform.

This example deploys a minimal C# HTTP Function and demonstrates how to:

  • upload the Function code as zip file to an OBS bucket (and update on changes), see: code_from_obs_bucket.tf

  • create the Function using the code from the OBS bucket, see: function.tf

    resource "opentelekomcloud_functiongraph_function_v2" "MyEventFunction" {
      ...
       code_type = "obs"
       code_url = format("https://%s/%s/%s",
            opentelekomcloud_obs_bucket.codebucket.bucket_domain_name,
            "code",
            basename(var.zip_file_local)
       )
      ...
    }
    
  • configure the API Trigger for the Function using

    • API-Group,

    • API and

    • publishment to an environment,

    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 HTTP Function using terraform follow these steps:

  1. Create an API Gateway or use an existing one. (Creating an API Gateway is not part of this terraform setup.) See Creating a Gateway for instructions on how to create an API Gateway. Note down the instance ID to be used in terraform configuration.

  2. Adjust the http.tfvars file according to your needs.

    Set the API_GATEWAY_INSTANCE_ID variable to your API Gateway instance ID (or define it as environment variable TF_VAR_API_GATEWAY_INSTANCE_ID).

    # Terraform variables for http_minimalWebAPI sample
    
    # prefix of all resources
    prefix="csharp" 
    
    # name of the function (will be prefixed)
    function_name="doc-sample-minimal-webapi"
    
    # function handler name, for http functions always "bootstrap"
    function_handler_name="bootstrap"
    
    # function runtime, for http functions always "http"
    function_runtime="http"
    
    # path to local zip file to be deployed
    zip_file_local="../src/http_minimalWebAPI_net8.0.zip"
    
    # resources will be tagged with this app_group tag
    tag_app_group="csharp-doc-sample-minimal-webapi"
    
    # change to your API Gateway instance ID
    # set as env var TF_VAR_API_GATEWAY_INSTANCE_ID or uncomment and set here
    #API_GATEWAY_INSTANCE_ID="YOUR_API_GATEWAY_INSTANCE_ID"
    
  3. 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