Linux diagnostic settings in Azure Cloud through Terraform

 



Linux diagnostic settings in Azure Cloud through Terraform

Create a resource group, a virtual machine, and a storage account first before using Terraform to activate Linux diagnostic settings in Azure Cloud.

The "azurerm virtual machine extension" resource in Terraform can be used to enable the Linux Diagnostics extension on the virtual machine once it has been constructed.

Below is the terraform code for the same :

#######################################################################

resource "azurerm_resource_group" "example" {

  name     = "example-resources"

  location = "eastus"

}


resource "azurerm_virtual_machine" "example" {

  name                  = "example-vm"

  location              = azurerm_resource_group.example.location

  resource_group_name   = azurerm_resource_group.example.name

  ...

}

resource "azurerm_storage_account" "example" {

  name                     = "examplestorage"

  resource_group_name      = azurerm_resource_group.example.name

  location                 = azurerm_resource_group.example.location

  account_tier             = "Standard"

  account_replication_type = "LRS"

}


resource "azurerm_virtual_machine_extension" "example" {

  name                       = "example-vm-ext"

  location                   = azurerm_resource_group.example.location

  resource_group_name        = azurerm_resource_group.example.name

  virtual_machine_name       = azurerm_virtual_machine.example.name

  publisher                  = "Microsoft.Azure.Diagnostics"

  type                       = "IaaSDiagnostics"

  type_handler_version       = "1.5"

  settings = <<SETTINGS

    {

        "StorageAccount": "${azurerm_storage_account.example.name}"

    }

SETTINGS

  protected_settings = <<PROTECTED_SETTINGS

    {

        "storageAccountName": "${azurerm_storage_account.example.name}",

        "storageAccountKey": "${azurerm_storage_account.example.primary_access_key}",

        "storageAccountEndPoint": "https://core.windows.net"

    }

PROTECTED_SETTINGS

}


###############################################################

Post a Comment

Previous Post Next Post

Contact Form