Last active
September 11, 2020 19:46
-
-
Save kevinhillinger/ede5b854691a3469782dcfc41f3512f9 to your computer and use it in GitHub Desktop.
API Management Logging to Application Insights with Terraform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 = "[email protected]" | |
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