azure - 如何设置一个 bool 值来调用我的日志分析工作区?

标签 azure terraform terraform-provider-azure

我将 Terraform 与 A​​zure 结合使用,并且创建了 NSG 和 log_analytics_workspace。

我想创建一个 bool 值,当 true 时将创建 log_analytics_workspace,该工作区应放置在与 NSG 相同的资源组中。

Main.tf

    resource "azurerm_network_security_group" "example" {
    name                = "NSG-group"
    location            = azurerm_resource_group.example.location
    resource_group_name = azurerm_resource_group.example.name
    count = var.nsg-log-analytics-workspace == "nsg-log-main" ? 1 : 0 
    
    }
    
    resource "azurerm_log_analytics_workspace" "example" {
      name                = "log-analytics-workspace"
      location            = azurerm_resource_group.example.location
      resource_group_name = azurerm_resource_group.example.name
      sku                 = "PerGB2018"
      retention_in_days   = 30
    
     nsg_log_category {
     category = log.value
     enabled  = true

     retention_policy {

     enabled = true
     days = 365

    }

变量.tf

variable "nsg_log_category" {
  type = list(string) #convert the logs into a list of strings
  default = nsg-main
}

任何关于我所缺少的内容的建议将不胜感激。

最佳答案

我不明白你的设计要点。然而,如果您想在日志分析工作区中收集 nsg 的日志,则必须创建 azurerm_monitor_diagnostic_setting并将 nsg 和工作区的 ids 插入资源中。

关于azure - 如何设置一个 bool 值来调用我的日志分析工作区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74524319/

相关文章:

azure - 从 Terraform 在 Azure 存储帐户中设置 CORS

azure - azurerm_linux_virtual_machine 中的云初始化脚本中的错误处理

Azure 数据工厂 - 重试插入复制事件 (Azure SQL DB)

c# - 无法加载文件或程序集 'Microsoft.Azure.Storage.Emulator.Controller'

Azure 专用端点和 Terraform

terraform - Terraform 资源名称中可以有一个点吗?

azure - terraform 计划不与 azurerm 提供商合作

multithreading - Azure 服务 TopicClient 线程安全且可重用吗?

azure - Azure 上托管 ClickOnce 的问题

postgresql - 无法删除 Terraform 中包含提供程序的模块实例