4

using below snippet I can create application insights and function_app but I am not sure how to configure function-app to use the created application insights.

module "resource_group" {
  source      = "git::ssh://address"
  environment = "${var.environment}"
  application = "${var.application}"
  app_version = "${var.app_version}"
}

module "function_app" {
  source                            = "git::ssh://address"
  environment                       = "${var.environment}"
  application                       = "${var.application}"
  resource_group_name               = "${module.resource_group.name}"
  app_version                       = "${var.app_version}"
  app_service_plan_id               = "${module.app_service_plan.id}"
  storage_primary_connection_string = "${module.storage_account.primary_connection_string}"
}

resource "azurerm_application_insights" "application_insights" {
  name                = "${var.environment}-${var.application}-appInsights"
  location            = "${module.resource_group.location}"
  resource_group_name = "${module.resource_group.name}"
  application_type    = "Web"
}

but When I visit azure > function_app > Monitor, it still shows to configure application_insights.

configure application insights

any suggestion?

2
  • Please check answer for similar case here. Commented Oct 4, 2023 at 4:42
  • 1
    Worth noting, web in application_type = "Web" shouldn't be capitalized. Commented Dec 14, 2023 at 14:20

1 Answer 1

13

See sample here: https://www.olivercoding.com/2018-06-24-terraform/. You need to add the APPINSIGHTS_INSTRUMENTATIONKEY to the app_settings of your function app.

Update - 10/09/2023

Adding application_insights_connection_string and application_insights_key inside the site_config block is the new way. Terraform automatically sets up the app_settings map.

Credit: Rajesh Swarnkar

Sign up to request clarification or add additional context in comments.

5 Comments

is there a document for app_settings?
Documentation for App_setting can be found here: terraform.io/docs/providers/azurerm/r/…
just to udate on this answer casing matters and should be "APPINSIGHTS_INSTRUMENTATIONKEY"
I think, this has changed, using 0.12.6 I now go app_settings =: ` app_settings = { "APPINSIGHTS_INSTRUMENTATIONKEY" = "${azurerm_application_insights.appInsight.instrumentation_key}" }`
Adding application_insights_connection_string and application_insights_key inside the site_config block is the new way. Terraform automatically sets up the app_settings map.

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.