Skip to content

azurermApiManagementApiDiagnostic

Manages a API Management Service API Diagnostics Logs.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
new azurerm.provider.AzurermProvider(this, "azurerm", {
  features: [{}],
});
const azurermResourceGroupExample = new azurerm.resourceGroup.ResourceGroup(
  this,
  "example",
  {
    location: "West Europe",
    name: "example-resources",
  }
);
const azurermApiManagementExample = new azurerm.apiManagement.ApiManagement(
  this,
  "example_2",
  {
    location: azurermResourceGroupExample.location,
    name: "example-apim",
    publisher_email: "company@terraform.io",
    publisher_name: "My Company",
    resource_group_name: azurermResourceGroupExample.name,
    sku_name: "Developer_1",
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermApiManagementExample.overrideLogicalId("example");
const azurermApiManagementApiExample =
  new azurerm.apiManagementApi.ApiManagementApi(this, "example_3", {
    api_management_name: azurermApiManagementExample.name,
    display_name: "Example API",
    import: [
      {
        content_format: "swagger-link-json",
        content_value: "http://conferenceapi.azurewebsites.net/?format=json",
      },
    ],
    name: "example-api",
    path: "example",
    protocols: ["https"],
    resource_group_name: azurermResourceGroupExample.name,
    revision: "1",
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermApiManagementApiExample.overrideLogicalId("example");
const azurermApplicationInsightsExample =
  new azurerm.applicationInsights.ApplicationInsights(this, "example_4", {
    application_type: "web",
    location: azurermResourceGroupExample.location,
    name: "example-appinsights",
    resource_group_name: azurermResourceGroupExample.name,
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermApplicationInsightsExample.overrideLogicalId("example");
const azurermApiManagementLoggerExample =
  new azurerm.apiManagementLogger.ApiManagementLogger(this, "example_5", {
    api_management_name: azurermApiManagementExample.name,
    application_insights: [
      {
        instrumentation_key:
          azurermApplicationInsightsExample.instrumentationKey,
      },
    ],
    name: "example-apimlogger",
    resource_group_name: azurermResourceGroupExample.name,
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermApiManagementLoggerExample.overrideLogicalId("example");
const azurermApiManagementApiDiagnosticExample =
  new azurerm.apiManagementApiDiagnostic.ApiManagementApiDiagnostic(
    this,
    "example_6",
    {
      always_log_errors: true,
      api_management_logger_id: azurermApiManagementLoggerExample.id,
      api_management_name: azurermApiManagementExample.name,
      api_name: azurermApiManagementApiExample.name,
      backend_request: [
        {
          body_bytes: 32,
          headers_to_log: ["content-type", "accept", "origin"],
        },
      ],
      backend_response: [
        {
          body_bytes: 32,
          headers_to_log: ["content-type", "content-length", "origin"],
        },
      ],
      frontend_request: [
        {
          body_bytes: 32,
          headers_to_log: ["content-type", "accept", "origin"],
        },
      ],
      frontend_response: [
        {
          body_bytes: 32,
          headers_to_log: ["content-type", "content-length", "origin"],
        },
      ],
      http_correlation_protocol: "W3C",
      identifier: "applicationinsights",
      log_client_ip: true,
      resource_group_name: azurermResourceGroupExample.name,
      sampling_percentage: 5,
      verbosity: "verbose",
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermApiManagementApiDiagnosticExample.overrideLogicalId("example");

Arguments Reference

The following arguments are supported:

  • apiManagementLoggerId - (Required) The ID (name) of the Diagnostics Logger.

  • apiManagementName - (Required) The name of the API Management Service instance. Changing this forces a new API Management Service API Diagnostics Logs to be created.

  • apiName - (Required) The name of the API on which to configure the Diagnostics Logs. Changing this forces a new API Management Service API Diagnostics Logs to be created.

  • identifier - (Required) Identifier of the Diagnostics Logs. Possible values are applicationinsights and azuremonitor. Changing this forces a new API Management Service API Diagnostics Logs to be created.

  • resourceGroupName - (Required) The name of the Resource Group where the API Management Service API Diagnostics Logs should exist. Changing this forces a new API Management Service API Diagnostics Logs to be created.


  • alwaysLogErrors - (Optional) Always log errors. Send telemetry if there is an erroneous condition, regardless of sampling settings.

  • backendRequest - (Optional) A backendRequest block as defined below.

  • backendResponse - (Optional) A backendResponse block as defined below.

  • frontendRequest - (Optional) A frontendRequest block as defined below.

  • frontendResponse - (Optional) A frontendResponse block as defined below.

  • httpCorrelationProtocol - (Optional) The HTTP Correlation Protocol to use. Possible values are none, legacy or w3C.

  • logClientIp - (Optional) Log client IP address.

  • samplingPercentage - (Optional) Sampling (%). For high traffic APIs, please read this documentation to understand performance implications and log sampling. Valid values are between 00 and 1000.

  • verbosity - (Optional) Logging verbosity. Possible values are verbose, information or error.

  • operationNameFormat - (Optional) The format of the Operation Name for Application Insights telemetries. Possible values are name, and url. Defaults to name.


A backendRequest, backendResponse, frontendRequest or frontendResponse block supports the following:

  • bodyBytes - (Optional) Number of payload bytes to log (up to 8192).

  • headersToLog - (Optional) Specifies a list of headers to log.

  • dataMasking - (Optional) A dataMasking block as defined below.


A dataMasking block supports the following:

  • queryParams - (Optional) A queryParams block as defined below.

  • headers - (Optional) A headers block as defined below.


The queryParams and headers blocks support the following:

  • mode - (Required) The data masking mode. Possible values are mask and hide for queryParams. The only possible value is mask for headers.

  • value - (Required) The name of the header or the query parameter to mask.

Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:

  • id - The ID of the API Management Service API Diagnostics Logs.

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

  • create - (Defaults to 30 minutes) Used when creating the API Management Service API Diagnostics Logs.
  • read - (Defaults to 5 minutes) Used when retrieving the API Management Service API Diagnostics Logs.
  • update - (Defaults to 30 minutes) Used when updating the API Management Service API Diagnostics Logs.
  • delete - (Defaults to 30 minutes) Used when deleting the API Management Service API Diagnostics Logs.

Import

API Management Service API Diagnostics Logs can be imported using the resourceId, e.g.

terraform import azurerm_api_management_api_diagnostic.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.ApiManagement/service/instance1/apis/api1/diagnostics/diagnostic1