Skip to content

Instantly share code, notes, and snippets.

@magodo
Created April 30, 2020 08:18
Show Gist options
  • Save magodo/e249a45e0d3b4e61ed5956bd9e1ea479 to your computer and use it in GitHub Desktop.
Save magodo/e249a45e0d3b4e61ed5956bd9e1ea479 to your computer and use it in GitHub Desktop.
provider "azurerm" {
features {}
}
variable "suffix" {
default = "test"
}
resource "azurerm_resource_group" "example" {
name = "example-resources-${var.suffix}"
location = "East US"
}
resource "azurerm_app_service_plan" "example" {
name = "acctestASP-${var.suffix}"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
sku {
tier = "Standard"
size = "S1"
}
}
resource "azurerm_app_service" "example" {
name = "acctestAS-${var.suffix}"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
app_service_plan_id = azurerm_app_service_plan.example.id
}
locals {
id = azurerm_app_service.example.id
}
data "azurerm_monitor_diagnostic_categories" "diagnostic_categories" {
resource_id = local.id
}
resource "azurerm_log_analytics_workspace" "example" {
name = "acctest-01-${var.suffix}"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
sku = "PerGB2018"
retention_in_days = 30
}
resource "azurerm_monitor_diagnostic_setting" "diagnostic_settings" {
name = "Send all to log analytics"
target_resource_id = local.id
log_analytics_workspace_id = azurerm_log_analytics_workspace.example.id
# Uncomment below attribute will cause diff
# log_analytics_destination_type = "Dedicated"
dynamic "log" {
for_each = data.azurerm_monitor_diagnostic_categories.diagnostic_categories.logs
content {
category = log.value
enabled = true
retention_policy {
enabled = false
}
}
}
dynamic "metric" {
for_each = data.azurerm_monitor_diagnostic_categories.diagnostic_categories.metrics
content {
category = metric.value
enabled = true
retention_policy {
enabled = false
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment