Azure Virtual Machine Packet Capture – Terraform

Bir Network Watcher kullanarak bir Sanal Makineye karşı Ağ Paketi Yakalamayı terraform ile yapılandırmak için aşağıdaki kodu kullanabilirsiniz.

resource "azurerm_resource_group" "mazureturkey" {
  name     = "mazureturkey-resources"
  location = "North Europe"
}

resource "azurerm_network_watcher" "mazureturkey" {
  name                = "mazureturkey-nw"
  location            = azurerm_resource_group.mazureturkey.location
  resource_group_name = azurerm_resource_group.mazureturkey.name
}

resource "azurerm_virtual_network" "mazureturkey" {
  name                = "mazureturkey-network"
  address_space       = ["10.0.0.0/16"]
  location            = azurerm_resource_group.mazureturkey.location
  resource_group_name = azurerm_resource_group.mazureturkey.name
}

resource "azurerm_subnet" "mazureturkey" {
  name                 = "internal"
  resource_group_name  = azurerm_resource_group.mazureturkey.name
  virtual_network_name = azurerm_virtual_network.mazureturkey.name
  address_prefixes     = ["10.0.2.0/24"]
}

resource "azurerm_network_interface" "mazureturkey" {
  name                = "mazureturkey-nic"
  location            = azurerm_resource_group.mazureturkey.location
  resource_group_name = azurerm_resource_group.mazureturkey.name

  ip_configuration {
    name                          = "mazureturkeyconfiguration1"
    subnet_id                     = azurerm_subnet.mazureturkey.id
    private_ip_address_allocation = "Dynamic"
  }
}

resource "azurerm_virtual_machine" "mazureturkey" {
  name                  = "mazureturkey-vm"
  location              = azurerm_resource_group.mazureturkey.location
  resource_group_name   = azurerm_resource_group.mazureturkey.name
  network_interface_ids = [azurerm_network_interface.mazureturkey.id]
  vm_size               = "Standard_F2"

  storage_image_reference {
    publisher = "Canonical"
    offer     = "UbuntuServer"
    sku       = "16.04-LTS"
    version   = "latest"
  }

  storage_os_disk {
    name              = "osdisk"
    caching           = "ReadWrite"
    create_option     = "FromImage"
    managed_disk_type = "Standard_LRS"
  }

  os_profile {
    computer_name  = "pcmazureturkey-vm"
    admin_username = "mazureturkeyadmin"
    admin_password = "Password1234!"
  }

  os_profile_linux_config {
    disable_password_authentication = false
  }
}

resource "azurerm_virtual_machine_extension" "mazureturkey" {
  name                       = "network-watcher"
  virtual_machine_id         = azurerm_virtual_machine.mazureturkey.id
  publisher                  = "Microsoft.Azure.NetworkWatcher"
  type                       = "NetworkWatcherAgentLinux"
  type_handler_version       = "1.4"
  auto_upgrade_minor_version = true
}

resource "azurerm_storage_account" "mazureturkey" {
  name                     = "mazureturkeysa"
  resource_group_name      = azurerm_resource_group.mazureturkey.name
  location                 = azurerm_resource_group.mazureturkey.location
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

resource "azurerm_virtual_machine_packet_capture" "mazureturkey" {
  name               = "mazureturkey-pc"
  network_watcher_id = azurerm_network_watcher.mazureturkey.id
  virtual_machine_id = azurerm_virtual_machine.mazureturkey.id

  storage_location {
    storage_account_id = azurerm_storage_account.mazureturkey.id
  }

  depends_on = [azurerm_virtual_machine_extension.mazureturkey]
}

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

This site uses Akismet to reduce spam. Learn how your comment data is processed.