title: How to enable diagnostic logs on Virtual Machine Scale Set or Load Balancer created by AKS cluster resource in terraform?
body: <p>The following terraform resource creates an AKS cluster with a Virtual Machine Scale Set (VMSS) and a Load Balancer (LB) resource. Currently, diagnostic logs are enabled on the cluster resource by adding <code>oms_agent</code> section under <code>addon_profile</code>.</p>
  <p>However, the documentation does not mention if there is a way to enable diagnostics on the VMSS created by <code>default_node_pool</code> and LB created by <code>network_profile</code>. Is this possible via terraform?</p>
  <p>Alternatively, is there a fixed naming scheme for the VMSS and LB created by the cluster? If there is a fixed naming scheme, one solution to this problem would be to simply look for resources with these predefined names in the correct resource group to create log analytics solution.</p>
  <p>Terraform Documentation: <br>
  <a href="https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_cluster" rel="nofollow noreferrer">https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_cluster</a>
  <a href="https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_cluster#default_node_pool" rel="nofollow noreferrer">https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_cluster#default_node_pool</a>
  <a href="https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_cluster#load_balancer_profile" rel="nofollow noreferrer">https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_cluster#load_balancer_profile</a></p>
  <pre><code>    resource &quot;azurerm_kubernetes_cluster&quot; &quot;aks-cluster&quot; {
        resource_group_name             = azurerm_resource_group.aks-rg.name
        location                        = azurerm_resource_group.aks-rg.location
        name                            = &quot;my-cluster&quot;
        dns_prefix                      = &quot;my-cluster-aks&quot;
        kubernetes_version              = &quot;1.18.8&quot;
        private_cluster_enabled         = false
        node_resource_group             = &quot;MC_my-cluster-aks&quot;
        api_server_authorized_ip_ranges = [var.authorized_ip]
        service_principal {
          client_id     = var.sp_client_id
          client_secret = var.client_secret
        }
        default_node_pool {
          name                = &quot;default&quot;
          type                = &quot;VirtualMachineScaleSets&quot;
          vm_size             = &quot;Standard_D2_v2&quot;
          node_count          = 4
          enable_auto_scaling = true
          min_count           = 4
          max_count           = 6
          vnet_subnet_id      = azurerm_subnet.aks-vnet-subnet.id
        }
        network_profile {
          network_plugin     = &quot;azure&quot;
          network_policy     = &quot;azure&quot;
          docker_bridge_cidr = var.aks_docker_bridge_cidr
          dns_service_ip     = var.aks_dns_service_ip
          load_balancer_sku  = &quot;standard&quot;
          service_cidr       = var.aks_service_cidr
        }
        addon_profile {
          oms_agent {
            enabled                    = true
            log_analytics_workspace_id = azurerm_log_analytics_workspace.aks_log_ws.id
          }
        }
      }
  </code></pre>