-1

I am using Terraform to deploy both an Azure "function app" and "function" which is successful.

Now in terraform i now need to get the 'deafult key' of the function - this is what i dont know how to do even after looking at the terraform docs.

so under the 'function'(note not the function-app) I need to get the value...

enter image description here

2 Answers 2

1

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
}
Sign up to request clarification or add additional context in comments.

Comments

0

There is a dedicated datasource for this, namely data "azurerm_function_app_host_keys" "functionkeys"

By using this, you should be able to access the key with azurerm_function_app_host_key.functionkeys.default_function_key

If you need further information, please have a look at the documentation:

2 Comments

I tried 'default_function_key' - it seem to read the function-app ok however the problem I have is which one of the returned value(s) from 'azurerm_function_app_host_keys' contains the 'default-key' of the particular function I am interested in...?
most probably the property "default_function_key" contains the default-key, I assume?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.