today i will be sharing a bit on my experience dealing with terraform on deploying resource on azure.
My problem on building these terraform is to enable boot diagnostic for azure vm .
i try to dig into terraform documentation but seem like it just appear on description without any sample, so i think i would share the way to do that here. Lets start
1. Create a storage account for vm/boot diagnostic purposes
resource "azurerm_storage_account" "hub-core-vmdiag" {
name = "azusgcorestrdiagnostic01"
location = azurerm_resource_group.azusg-core-vnet-rg.location
resource_group_name = azurerm_resource_group.azusg-core-vnet-rg.name
account_tier = "Standard"
account_replication_type = "LRS"
}
2. Create a VM
resource "azurerm_network_interface" "AD01-nic" {
name = "AD01-nic"
location = azurerm_resource_group.azusg-core-vnet-rg.location
resource_group_name = azurerm_resource_group.azusg-core-vnet-rg.name
enable_ip_forwarding = true
ip_configuration {
name = "AD01-ipconfig"
subnet_id = azurerm_subnet.core-share-subnet.id
private_ip_address_allocation = "Static"
private_ip_address = "172.30.0.197"
}
// tags {
// environment = local.prefix-core
//}
}
resource "azurerm_virtual_machine" "AD01-vm" {
name = "AD01"
location = azurerm_resource_group.azusg-core-vnet-rg.location
resource_group_name = azurerm_resource_group.azusg-core-vnet-rg.name
network_interface_ids = [azurerm_network_interface.AD01-nic.id]
vm_size = "Standard_F4s"
storage_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2019-Datacenter"
version = "latest"
}
storage_os_disk {
name = "AD01-osdisk"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
os_profile {
computer_name = "AD01"
admin_username = "xxxxxxx"
admin_password = "xxxxxx"
}
os_profile_windows_config{}
}
3. Add boot diagnostic option into your code (after the os profile)
os_profile_windows_config{}
boot_diagnostics{
enabled = true
storage_uri = "Https://${azurerm_storage_account.hub-core-vmdiag.name}
.blob.core.windows.net"
}
you are done, now after you run terraform apply, this vm will be created, boot diagnostic will be enable with this storage account.
Happy testing and see you all again.
updated version is here on part 2 - Click here