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.51k stars 4.6k forks source link

azurerm_monitor_diagnostic_setting is having problem in read and creation. #26545

Open findajay opened 2 months ago

findajay commented 2 months ago

Is there an existing issue for this?

Community Note

Terraform Version

1.3.7

AzureRM Provider Version

3.75.0

Affected Resource(s)/Data Source(s)

azurerm_monitor_diagnostic_setting

Terraform Configuration Files

# resource "azurerm_monitor_diagnostic_setting" "function_diagnostic_log" {
#   for_each           = data.azurerm_linux_function_app.function_apps
#   name               = "${each.key}-diagnostic-logs"
#   target_resource_id = data.azurerm_linux_function_app.function_apps[each.key].id
#   storage_account_id = data.azurerm_storage_account.function_storageaccount[each.key].id

#   enabled_log {
#     category = "FunctionAppLogs"
#   }
# }

Debug Output/Panic Output

╷
│ Error: checking for presence of existing Monitor Diagnostic Setting "worker-diagnostic-logs" for Resource "/subscriptions/5f7f3495-660d-40b7-8bc1-6f36a22c7565/resourceGroups/nucleus-dev-contracts/providers/Microsoft.Web/sites/vs-nucleus-dev-contracts-worker": diagnosticsettings.DiagnosticSettingsClient#Get: Failure responding to request: StatusCode=500 -- Original Error: autorest/azure: Service returned an error. Status=500 Code="Unknown" Message="Unknown service error" Details=[{"code":"InternalServerError","message":""}]
│ 
│   with module.service.azurerm_monitor_diagnostic_setting.function_diagnostic_log["worker"],
│   on .terraform/modules/service/terraform/modules/services/web_api/function_app.tf line 320, in resource "azurerm_monitor_diagnostic_setting" "function_diagnostic_log":
│  320: resource "azurerm_monitor_diagnostic_setting" "function_diagnostic_log" {
│ 
╵
##[error]Script failed with error: Error: The process '/usr/bin/bash' failed with exit code 1
    at ExecState._setResult (/agent/_work/_tasks/AzureCLI_46e4be58-730b-4389-8a2f-ea10b3e5e815/1.238.4/node_modules/azure-pipelines-task-lib/toolrunner.js:1219:25)
    at ExecState.CheckComplete (/agent/_work/_tasks/AzureCLI_46e4be58-730b-4389-8a2f-ea10b3e5e815/1.238.4/node_modules/azure-pipelines-task-lib/toolrunner.js:1202:18)
    at ChildProcess.<anonymous> (/agent/_work/_tasks/AzureCLI_46e4be58-730b-4389-8a2f-ea10b3e5e815/1.238.4/node_modules/azure-pipelines-task-lib/toolrunner.js:1115:19)
    at ChildProcess.emit (node:events:513:28)
    at maybeClose (node:internal/child_process:1100:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5)

Expected Behaviour

Existing Diagnotic settings must be read during plan or new must be created

Actual Behaviour

terraform fails in both step in reading the resource in plan and create in apply step

Steps to Reproduce

Create an azure function and try to enable diagnostic setting on azure function using azurerm_monitor_diagnostic_setting

Important Factoids

No response

References

No response

teowa commented 2 months ago

Hi @findajay , The Status=500 Code="Unknown" Message="Unknown service error" Details=[{"code":"InternalServerError","message":""}] error message should be backend issue which means the API has some error. I am unable to reproduce it with below config. Could you please reproduce it with the latest provider 3.111.0 version and provide the config which can be reproduced? thanks.

terraform config ```hcl provider "azurerm" { features {} } resource "azurerm_resource_group" "example" { name = "example-funcapp-resources" location = "West Europe" } resource "azurerm_storage_account" "example" { name = "linuxfunctionappsawtte" resource_group_name = azurerm_resource_group.example.name location = azurerm_resource_group.example.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_service_plan" "example" { name = "example-app-service-plan" resource_group_name = azurerm_resource_group.example.name location = azurerm_resource_group.example.location os_type = "Linux" sku_name = "Y1" } resource "azurerm_linux_function_app" "example" { name = "example-linux-function-appwttest" resource_group_name = azurerm_resource_group.example.name location = azurerm_resource_group.example.location storage_account_name = azurerm_storage_account.example.name storage_account_access_key = azurerm_storage_account.example.primary_access_key service_plan_id = azurerm_service_plan.example.id site_config {} } resource "azurerm_monitor_diagnostic_setting" "example" { name = "example" target_resource_id = azurerm_linux_function_app.example.id storage_account_id = azurerm_storage_account.example.id enabled_log { category = "FunctionAppLogs" } } ```
alexkunde commented 1 month ago

We had the same problem and contacted Microsoft support. The product team for the API should have rolled out a fix which inherently fixes the terraform. Maybe it already works for you as well.