Skip to content

Instantly share code, notes, and snippets.

@kevinhillinger
Last active September 11, 2020 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinhillinger/ede5b854691a3469782dcfc41f3512f9 to your computer and use it in GitHub Desktop.
Save kevinhillinger/ede5b854691a3469782dcfc41f3512f9 to your computer and use it in GitHub Desktop.
API Management Logging to Application Insights with Terraform
# Terraform version 0.13
# variables
variable "apis" {
type = map
default = {
conferenceApi = {
name = "conference-api"
}
}
}
provider "azurerm" {
version = "=2.27.0"
features {}
}
resource "azurerm_resource_group" "apis" {
name = "apis"
location = "East US"
}
resource "azurerm_application_insights" "appInsights" {
name = "apm4apim001"
location = azurerm_resource_group.apis.location
resource_group_name = azurerm_resource_group.apis.name
application_type = "web"
}
resource "azurerm_api_management" "apim" {
name = "apim11092020"
location = azurerm_resource_group.apis.location
resource_group_name = azurerm_resource_group.apis.name
publisher_name = "Microsoft"
publisher_email = "kevin.hillinger@microsoft.com"
sku_name = "Developer_1"
}
resource "azurerm_api_management_api" "conferenceApi" {
name = var.apis.conferenceApi.name
resource_group_name = azurerm_resource_group.apis.name
api_management_name = azurerm_api_management.apim.name
revision = "1"
display_name = "conference API"
path = "conferences"
protocols = ["https"]
import {
content_format = "swagger-link-json"
content_value = "http://conferenceapi.azurewebsites.net/?format=json"
}
}
resource "azurerm_api_management_logger" "logger" {
name = "appInsightsLogger"
api_management_name = azurerm_api_management.apim.name
resource_group_name = azurerm_resource_group.apis.name
application_insights {
instrumentation_key = azurerm_application_insights.appInsights.instrumentation_key
}
}
resource "azurerm_api_management_api_diagnostic" "apiDiagnostics" {
for_each = var.apis
resource_group_name = azurerm_resource_group.apis.name
api_management_name = azurerm_api_management.apim.name
api_name = each.value.name
api_management_logger_id = azurerm_api_management_logger.logger.id
identifier = "applicationinsights"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment