Recently, the successful implementation of the following requirements took me quite a bit of time, which is why I decided to write a blog post about it.
- Get Azure Function key (key type
function) using AzAPI provider - Set the Azure Function key as value of a not managed key vault secret using AzAPI provider
I was able to solve this challenge using the following configuration.
data "azurerm_key_vault" "kv" { name = "KV_NAME_HERE" resource_group_name = "RG_NAME_HERE"}resource "azapi_resource_action" "azure_function_listkeys" { type = "Microsoft.Web/sites/functions@2026-03-15" resource_id = "${azurerm_function_app_flex_consumption.example_app.id}/functions/ExampleFunction" action = "listkeys" method = "POST" response_export_values = ["*"] when = "apply"}resource "azapi_resource_action" "set_keyvault_secret_value_with_function_key" { type = "Microsoft.KeyVault/vaults/secrets@2026-03-01-preview" resource_id = "${data.azurerm_key_vault.kv.id}/secrets/arbitrary-secret" method = "PUT" body = { properties = { value = try( jsondecode(azapi_resource_action.azure_function_listkeys.output).default, azapi_resource_action.azure_function_listkeys.output.default ) } } when = "apply"}


Leave a Reply