So to get the default-key of an Azure Function (not Function App) this worked for me...
# Get the Function Key for 'ProjectOutboxEventFunction'
module "get_function_Key" {
providers = {
azapi = azapi
}
depends_on = [module.create_fapp_re_id]
source = "../../resource_modules/get_function_key"
resource_id = "${module.create_fapp_re_id.function_app_id}/functions/ProjectOutboxEventFunction"
}
A terraform module that returns the default-function-key....
terraform {
required_providers {
# Azure Az API
azapi = {
source = "Azure/azapi"
version = "1.15.0"
}
}
}
data "azurerm_subscription" "current" {}
data "azapi_resource_action" "function_keys" {
type = "Microsoft.Web/sites/functions@2024-04-01"
resource_id = var.resource_id
method = "POST"
action = "listkeys"
response_export_values = ["default"] # seting to * will get the full responce body
}
output "default_key" {
depends_on = [data.azapi_resource_action.function_keys]
value = jsondecode(data.azapi_resource_action.function_keys.output).default
}