hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.45k stars 4.53k forks source link

Connecting Application Insights API key & ID to Azure Bot #26407

Open pdzienisiewicz opened 1 week ago

pdzienisiewicz commented 1 week ago

Is there an existing issue for this?

Community Note

My Terraform code somehow is not saving correctly Application Insights API key and Application Insights Application ID (instead of id it saves the resource name):

11

I check if I can do it manually - I generated a new Application Insights API key and attached it to the azure bot and provided the correct Application Insights Application ID (instead of just the name of app ins). It seems to me that everything is fine this way - the only thing is that I will still have to look for the reason why I cannot do it via Terraform properly.

Inside Azure Bot Service there is a backend log coming from: "UserAgent":"Go/go1.21.6 (amd64-windows) go-autorest/v14.2.1 tombuildsstuff/kermit/v0.20240122.1123108 botservice/2021-05-01-preview HashiCorp Terraform/1.8.5 (+https://www.terraform.io) Terraform Plugin SDK/2.10.1 terraform-provider-azurerm/3.98.0 VSTS_b329faa1-658e-4371-a085-ad5fac5a49ac_build_13_0 pid-222c6c49-1b0a-5959-a213-6608f9eb8820"

This call has a status code 400 – Bad Request, but no further details shown. It sounds to me that Terraform sent a request to Azure Resource Manager with an invalid payload, probably, cannot confirm.

When doing “apply” in TF, I dont get any logs/messages from the terraform deployment - I don't get any incorrect alerts, everything is going well.

Terraform Version

1.8.5

AzureRM Provider Version

3.98.0

Affected Resource(s)/Data Source(s)

azurerm_bot_service_azure_bot

Terraform Configuration Files

resource "azurerm_application_insights_api_key" "insights_api_key_bot_1" {
  name                    = "insights_READONLYKEY_${local.bot_name}"
  application_insights_id = module.webapp_1_linux.app_insights_id
  read_permissions        = ["aggregate", "api", "draft", "extendqueries", "search"]

  depends_on = [ module.cognitive_account_4_cont ]
}

module "azure_bot_service_1" {
  source                      = "./modules/azure_bot_service"
  bot_name                    = local.bot_name
  resource_group_name         = local.resource_group_name
  location_bot                = var.location_bot
  microsoft_app_id_bot        = data.azurerm_client_config.current.object_id
  microsoft_app_tenant_id_bot = local.tenant_id
  sku_bot                     = var.sku_bot
  microsoft_app_type_bot      = var.microsoft_app_type_bot
  network_access_bot          = var.network_access_bot
  local_authentication_bot    = var.local_authentication_bot
  endpoint_bot                = var.endpoint_bot
  dev_app_insights_api_key    = azurerm_application_insights_api_key.insights_api_key_bot_1.api_key 
  dev_app_insights_app_id     = module.webapp_1_linux.app_insights_app_id  
  dev_app_insights_key        = module.webapp_1_linux.instrumentation_key
  cmk_vault_key_url           = module.key_vault_bot_1_enc_key[0].key_vault_key_id

  depends_on = [ module.key_vault_bot_1_enc_key ]
}

Debug Output/Panic Output

azurerm_application_insights_api_key.insights_api_key_bot_1: Creating...
azurerm_application_insights_api_key.insights_api_key_bot_1: Creation complete after 2s
module.azure_bot_service_1.azurerm_bot_service_azure_bot.azure_bot: Creating...
module.azure_bot_service_1.azurerm_bot_service_azure_bot.azure_bot: Creation complete after 4s

As You can see - any error during deployment, the problem can only be noticed in Configuration Tab in Azure Bot Resource on Azure Portal.

Expected Behaviour

Correct Application Insights API key and Application Insights Application ID addition to Azure Bot via Terraform Deployment

Actual Behaviour

Not saving correctly Application Insights API key and Application Insights Application ID (instead of id it saves the resource name).

Steps to Reproduce

No response

Important Factoids

No response

References

No response

teowa commented 1 week ago

Hi @pdzienisiewicz, thanks for submitting the issue!

Terraform is not saving correctly Application Insights Application ID (instead of id it saves the resource name)

From the provided config dev_app_insights_app_id = module.webapp_1_linux.app_insights_app_id, could you please check if module.webapp_1_linux.app_insights_app_id is set to the app insight name by mistake? According to the provider doc, developer_app_insights_application_id should be set to azurerm_application_insights.app_id.