Azure Boot Diagnostics Configuration

I tried to create the Azure VM with boot diagnostics and still not successful and got this error. terraform validation and plan pass and only encounter this error when I run terraform apply. I can create VM successfully after remove the boot diagnostics part but that’s not what I want.

Any idea how to fix it?

compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="InvalidParameter" Message="The value of parameter bootDiagnostics.storageAccountUri is invalid." Target="bootDiagnostics.storageAccountUri"

Below are my configuration.

resource "azurerm_windows_virtual_machine" "vm-01" {
  name                = "${var.vmlist["0"]}"
  resource_group_name = var.azurerm_resource_group
  location            = var.location
  size                = var.vmsize["B2s"]
  admin_username      = var.wincred[0]
  admin_password      = var.wincred[1]
  network_interface_ids = [,

  source_image_reference {
    publisher = "MicrosoftWindowsServer"
    offer     = "WindowsServer"
    sku       = var.vmimgsku["2022-dc-aec"]
    version   = "latest"

  os_disk {
    storage_account_type = "Standard_LRS"
    caching              = "ReadWrite"

  patch_mode          = "AutomaticByPlatform"
  hotpatching_enabled = true

  tags = {
    environment = "iis"
  boot_diagnostics {
       storage_account_uri = "storageaccountname"

I don’t think you can just use the Storage Account name in your boot_diagnostics block. It needs to be the Primary/Secondary URI of your Storage Account. If you also create that in Terraform, you can refer to the resource directly instead of setting it as a string somewhere, might be easier :slight_smile:

Check out the docs here - azurerm_windows_virtual_machine | Resources | hashicorp/azurerm | Terraform Registry

Thanks let me try on that and will get back to you.

Thank you so much and it is working now.