Skip to content

azurermFunctionAppFunction

Manages a Function App Function.

Example Usage - Basic HTTP Trigger

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
const azurermResourceGroupExample = new azurerm.resourceGroup.ResourceGroup(
  this,
  "example",
  {
    location: "West Europe",
    name: "example-group",
  }
);
const azurermServicePlanExample = new azurerm.servicePlan.ServicePlan(
  this,
  "example_1",
  {
    location: azurermResourceGroupExample.location,
    name: "example-service-plan",
    os_type: "Linux",
    resource_group_name: azurermResourceGroupExample.name,
    sku_name: "S1",
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermServicePlanExample.overrideLogicalId("example");
const azurermStorageAccountExample = new azurerm.storageAccount.StorageAccount(
  this,
  "example_2",
  {
    account_replication_type: "LRS",
    account_tier: "Standard",
    location: azurermResourceGroupExample.location,
    name: "examplesa",
    resource_group_name: azurermResourceGroupExample.name,
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermStorageAccountExample.overrideLogicalId("example");
const azurermLinuxFunctionAppExample =
  new azurerm.linuxFunctionApp.LinuxFunctionApp(this, "example_3", {
    location: azurermResourceGroupExample.location,
    name: "example-function-app",
    resource_group_name: azurermResourceGroupExample.name,
    service_plan_id: azurermServicePlanExample.id,
    site_config: [
      {
        application_stack: [
          {
            python_version: "3.9",
          },
        ],
      },
    ],
    storage_account_access_key: azurermStorageAccountExample.primaryAccessKey,
    storage_account_name: azurermStorageAccountExample.name,
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermLinuxFunctionAppExample.overrideLogicalId("example");
const azurermFunctionAppFunctionExample =
  new azurerm.functionAppFunction.FunctionAppFunction(this, "example_4", {
    config_json:
      '${jsonencode({\n    "bindings" = [\n      {\n        "authLevel" = "function"\n        "direction" = "in"\n        "methods" = [\n          "get",\n          "post",\n        ]\n        "name" = "req"\n        "type" = "httpTrigger"\n      },\n      {\n        "direction" = "out"\n        "name"      = "$return"\n        "type"      = "http"\n      },\n    ]\n  })}',
    function_app_id: azurermLinuxFunctionAppExample.id,
    language: "Python",
    name: "example-function-app-function",
    test_data: '${jsonencode({\n    "name" = "Azure"\n  })}',
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermFunctionAppFunctionExample.overrideLogicalId("example");

Example Usage - HTTP Trigger with code upload

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
new azurerm.functionAppFunction.FunctionAppFunction(this, "example", {
  config_json:
    '${jsonencode({\n    "bindings" = [\n      {\n        "authLevel" = "function"\n        "direction" = "in"\n        "methods" = [\n          "get",\n          "post",\n        ]\n        "name" = "req"\n        "type" = "httpTrigger"\n      },\n      {\n        "direction" = "out"\n        "name"      = "$return"\n        "type"      = "http"\n      },\n    ]\n  })}',
  file: [
    {
      content: '${file("exampledata/run.csx")}',
      name: "run.csx",
    },
  ],
  function_app_id: "${azurerm_linux_function_app.example.id}",
  language: "CSharp",
  name: "example-function-app-function",
  test_data: '${jsonencode({\n    "name" = "Azure"\n  })}',
});
const azurermResourceGroupExample = new azurerm.resourceGroup.ResourceGroup(
  this,
  "example_1",
  {
    location: "West Europe",
    name: "example-group",
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermResourceGroupExample.overrideLogicalId("example");
const azurermServicePlanExample = new azurerm.servicePlan.ServicePlan(
  this,
  "example_2",
  {
    location: azurermResourceGroupExample.location,
    name: "example-service-plan",
    os_type: "Windows",
    resource_group_name: azurermResourceGroupExample.name,
    sku_name: "S1",
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermServicePlanExample.overrideLogicalId("example");
const azurermStorageAccountExample = new azurerm.storageAccount.StorageAccount(
  this,
  "example_3",
  {
    account_replication_type: "LRS",
    account_tier: "Standard",
    location: azurermResourceGroupExample.location,
    name: "examplesa",
    resource_group_name: azurermResourceGroupExample.name,
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermStorageAccountExample.overrideLogicalId("example");
new azurerm.windowsFunctionApp.WindowsFunctionApp(this, "test", {
  location: "${azurerm_resource_group.test.location}",
  name: "example-function-app",
  resource_group_name: "${azurerm_resource_group.test.name}",
  service_plan_id: "${azurerm_service_plan.test.id}",
  site_config: [
    {
      application_stack: [
        {
          dotnet_version: "6",
        },
      ],
    },
  ],
  storage_account_access_key:
    "${azurerm_storage_account.test.primary_access_key}",
  storage_account_name: "${azurerm_storage_account.test.name}",
});

Arguments Reference

The following arguments are supported:

  • name - (Required) The name of the function. Changing this forces a new resource to be created.

  • functionAppId - (Required) The ID of the Function App in which this function should reside. Changing this forces a new resource to be created.

  • configJson - (Required) The config for this Function in JSON format.


  • enabled - (Optional) Should this function be enabled. Defaults to true.

  • file - (Optional) A file block as detailed below. Changing this forces a new resource to be created.

  • language - (Optional) The language the Function is written in. Possible values are cSharp, custom, java, javascript, python, powerShell, and typeScript.

\~> NOTE: when using custom language, you must specify the code handler in the hostJson file for your function. See the official docs for more information.

  • testData - (Optional) The test data for the function.

A file block supports the following:

  • name - (Required) The filename of the file to be uploaded. Changing this forces a new resource to be created.

  • content - (Required) The content of the file. Changing this forces a new resource to be created.

Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:

  • id - The ID of the Function App Function

  • configUrl - The URL of the configuration JSON.

  • invocationUrl - The invocation URL.

  • scriptRootPathUrl - The Script root path URL.

  • scriptUrl - The script URL.

  • secretsFileUrl - The URL for the Secrets File.

  • testDataUrl - The Test data URL.

  • url - The function URL.

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

  • create - (Defaults to 30 minutes) Used when creating the Function App Function.
  • update - (Defaults to 30 minutes) Used when updating the Function App Function.
  • read - (Defaults to 5 minutes) Used when retrieving the Function App Function.
  • delete - (Defaults to 5 minutes) Used when deleting the Function App Function.

Import

a Function App Function can be imported using the resourceId, e.g.

terraform import azurerm_function_app_function.example "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Web/sites/site1/functions/function1"