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.58k stars 4.62k forks source link

For azurerm_api_management_diagnostic, Event Hub Configuration not working #19970

Closed sandykardile closed 11 months ago

sandykardile commented 1 year ago

Is there an existing issue for this?

Community Note

Terraform Version

3.38.0

AzureRM Provider Version

3.38.0

Affected Resource(s)/Data Source(s)

azurerm_api_management_diagnostic

Terraform Configuration Files

resource "azurerm_api_management_logger" "apim" {
  name                = "logger-apim-001"
  api_management_name = azurerm_api_management.apim.name
  resource_group_name = azurerm_resource_group.apim.name

  eventhub {
    name              = "evh-apim-001"
    connection_string = "primary_connection_string"
  }
}

resource "azurerm_api_management_diagnostic" "apim" {
  identifier               = "azuremonitor"
  resource_group_name      = azurerm_resource_group.apimfrc.name
  api_management_name      = azurerm_api_management.apim.name
  api_management_logger_id = azurerm_api_management_logger.apim.id
  always_log_errors        = true
  log_client_ip            = true
  verbosity                = "verbose"
  sampling_percentage      = 100

  frontend_request {
    headers_to_log = [
      "x-appgw-trace-id",
    ]
  }
  frontend_response {
    headers_to_log = [
      "x-appgw-trace-id",
    ]
  }
  backend_request {
    headers_to_log = [
      "x-appgw-trace-id",
    ]
  }
  backend_response {
    headers_to_log = [
      "x-appgw-trace-id",
    ]
  }
}

Debug Output/Panic Output

We are trying to set up an azure monitor for the event hub and the error is on operationNameFormat which is only used in the case of application insight.
Error:
Apimanagement.DiagnosticClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="ValidationError" Message="One or more fields contain incorrect values:" Details=[{"code":"ValidationError","message":"Property 'OperationNameFormat' is only supported for Application Insights diagnostics.","target":"operationNameFormat"}]

Expected Behaviour

Azure event hub monitoring could be configured correctly

Actual Behaviour

Error: Apimanagement.DiagnosticClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="ValidationError" Message="One or more fields contain incorrect values:" Details=[{"code":"ValidationError","message":"Property 'OperationNameFormat' is only supported for Application Insights diagnostics.","target":"operationNameFormat"}]

Steps to Reproduce

No response

Important Factoids

No response

References

No response

ghost commented 1 year ago

This is still an issue with azurerm v3.50. I am not setting event hub details, but it is throwing the same error.

My resource configuration:

resource "azurerm_api_management_diagnostic" "azure_monitor_logger_diagnostic" {
  api_management_logger_id = azurerm_api_management_logger.azure_monitor_logger.id
  api_management_name      = "[apim name]"
  identifier               = "azuremonitor"
  resource_group_name      = local.resource_group_name
  depends_on = [
    azurerm_api_management_logger.azure_monitor_logger,
  ]
}

When I run the script, it says it will create the following:

# azurerm_api_management_diagnostic.azure_monitor_logger_diagnostic will be created
  + resource "azurerm_api_management_diagnostic" "azure_monitor_logger_diagnostic" {
      + always_log_errors         = (known after apply)
      + api_management_logger_id  = "[id]"
      + api_management_name       = "[apim name]"
      + http_correlation_protocol = (known after apply)
      + id                        = (known after apply)
      + identifier                = "azuremonitor"
      + log_client_ip             = (known after apply)
      + operation_name_format     = "Name"
      + resource_group_name       = "[rg name]"
      + sampling_percentage       = (known after apply)
      + verbosity                 = (known after apply)
    }

And the error output is:

│ Error: creating or updating Diagnostic: (Name "azuremonitor" / Service Name "[apim name]" / Resource Group "[rg name]"): apimanagement.DiagnosticClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="ValidationError" Message="One or more fields contain incorrect values:" Details=[{"code":"ValidationError","message":"Property 'OperationNameFormat' is only supported for Application Insights diagnostics.","target":"operationNameFormat"}]
github-actions[bot] commented 5 months ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.