在Azure中部署具有多个工作空间目标的Terrafrom的数据收集规则?

gmxoilav  于 2023-11-21  发布在  其他
关注(0)|答案(1)|浏览(119)

我们是否可以将Azure DCR部署到两个或更多日志分析工作区目标?
我已经尝试了一个目的地的基本代码,但我无法添加另一个

resource "azurerm_monitor_data_collection_rule" "this" {
  name                = local.naming.dcr_name
  resource_group_name = azurerm_resource_group.this.name
  location            = azurerm_resource_group.this.location

  destinations {
    **log_analytics {
      workspace_resource_id = azurerm_log_analytics_workspace.this.id
      name                  = local.naming.log_name
    }**
  }

  data_flow {
    streams      = ["Microsoft-Table-Perf"]
    destinations = [local.naming.log_name]
  }
}

字符串

b5lpy0ml

b5lpy0ml1#

我们是否可以将Azure DCR部署到两个或更多日志分析工作区目标?
我使用下面的terraform代码创建了一个DCR规则,并将其与两个log analytics workspaces关联。

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "example" {
  name     = "dcr-resources"
  location = "East US"
}

resource "azurerm_log_analytics_workspace" "workspace1" {
  name                = "workspace1"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  sku                 = "PerGB2018"
  retention_in_days   = 30
  depends_on = [ azurerm_resource_group.example ]
}

resource "azurerm_log_analytics_workspace" "workspace2" {
  name                = "workspace2"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  sku                 = "PerGB2018"
  retention_in_days   = 30
  depends_on = [ azurerm_log_analytics_workspace.workspace1 ]
}

resource "azurerm_monitor_data_collection_rule" "example" {
  name                = "sample-dcr-rule"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location

  destinations {
    log_analytics {
      workspace_resource_id = azurerm_log_analytics_workspace.workspace1.id
      name                  = "destination-log1"
    }
    log_analytics {
      workspace_resource_id = azurerm_log_analytics_workspace.workspace2.id
      name                  = "destination-log2"
    }
  }

  data_sources {
    syslog {
      facility_names = ["*"]
      log_levels     = ["*"]
      name           = "datasource-syslog"
      streams        = ["Microsoft-Syslog"]
    }
     performance_counter {
      streams                       = ["Microsoft-Perf"]
      sampling_frequency_in_seconds = 60
      counter_specifiers            = ["Processor(*)\\% Processor Time"]
      name                          = "datasource-perfcounter"
    }
  }

data_flow {
    streams      = ["Microsoft-Syslog"]
    destinations = ["destination-log1"]
  }

  data_flow {
    streams      = ["Microsoft-Perf"]
    destinations = ["destination-log2"]
  }

  description = "data collection rule example"
  tags = {
    foo = "bar"
  }

  depends_on = [
    azurerm_log_analytics_workspace.workspace1,
    azurerm_log_analytics_workspace.workspace2
  ]
}

字符串
运行代码后,用两个log analytics workspaces创建了一个DCR


的数据

相关问题