Home > Enterprise >  How can I set up a boolean to call my log analytics workspace?
How can I set up a boolean to call my log analytics workspace?

Time:11-22

I am using Terraform with Azure and I have created a NSG and a log_analytics_workspace.

I want to create a boolean, that when true will create a log_analytics_workspace, the workspace should be placed within the same resource group as the 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

    }

Variable.tf

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

Any advice towards what I am missing will be appreciated.

CodePudding user response:

I miss the point of your design. Nevertheless if you want to collect the logs of the nsg in the log analytics workspace, you must create an azurerm_monitor_diagnostic_setting and insert the ids of the nsg and workspace in the resource.

  • Related