BassievanAdriaan
BassievanAdriaan

Reputation: 41

Extend disk SQL Server virtual machine by using Terraform

I'm trying to extend the SQL Server "data"/ "log" disk by using Terraform.

We currently use Terraform to deploy the following (some snippets for a test deployment) which is working perfect and deploys the machine perfectly:

resource "azurerm_windows_virtual_machine" "vm_sql" {
  name                = "vm-...mssql01"
  computer_name       = "vm-mssql01"
  resource_group_name = REDACTED
  location            = REDACTED
  size                = "Standard_D4as_v4"
  admin_username      = REDACTED
  admin_password      = REDACTED
  license_type        = "Windows_Server"
  network_interface_ids = [
etc ...
}

resource "azurerm_managed_disk" "data_disk" {
  name                 = "dsk-${azurerm_windows_virtual_machine.vm_sql.name}-data"
  location             = REDACTED
  resource_group_name  = REDACTED
  storage_account_type = "StandardSSD_LRS"
  create_option        = "Empty"
  disk_size_gb         = "512"
}

resource "azurerm_virtual_machine_data_disk_attachment" "data-disk" {
  managed_disk_id    = azurerm_managed_disk.data_disk.id
  virtual_machine_id = azurerm_windows_virtual_machine.vm_sql.id
  lun                = "2"
  caching            = "ReadWrite"
}

resource "azurerm_mssql_virtual_machine" "sql_setup" {
 *all other parameters, shorted for readability*
   storage_configuration {
    disk_type             = "NEW"
    storage_workload_type = "GENERAL"
    data_settings {
      default_file_path = "F:\\data"
      luns              = [2]
    }
    log_settings {
      default_file_path = "F:\\log"
      luns              = [2]
    } 

     temp_db_settings {
      default_file_path = "D:\\tempdb"
      luns              = []
    }

Of course, we can use the Portal to extend the disk, this will add an additional disk, and add it to the storage pool within the VM but of course, my Terraform code cannot be used again.

I tried the following:

  1. Add and attach an extra managed disk (lun 3) After that, I tried the following with the following errors from the API.
   storage_configuration {
    disk_type             = "EXTEND"
    storage_workload_type = "GENERAL"
    data_settings {
      default_file_path = "F:\\data"
      luns              = [2,3]
    }
    log_settings {
      default_file_path = "F:\\log"
      luns              = [2,3]
    } 

     temp_db_settings {
      default_file_path = "D:\\tempdb"
      luns              = []
    }

Error InvalidExtendPayload" Message="Invalid Sql Storage Settings Extend Payload. Only support extend one drive at a time.

    storage_configuration {
    disk_type             = "EXTEND"
    storage_workload_type = "GENERAL"
    data_settings {
      default_file_path = "F:\\data"
      luns              = [3]

    }
    } 

Error creating Sql Virtual Machine (Sql Virtual Machine Name "vm-iss-sand-mssql01" / Resource Group "rg-iss-sand-database"): sqlvirtualmachine.SQLVirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: Code="InvalidArgument" Message="Invalid argument 'DefaultFilePath'."

I tried many options and combinations but all ending up in not extending the VM and the SQL config. I'm starting to think that this is not possible with Terraform. I use the latest azurerm provider etc.

Upvotes: 4

Views: 1434

Answers (1)

eissko
eissko

Reputation: 1

I think the problem is api services\preview\sqlvirtualmachine\mgmt\2021-11-01-preview. I described issue on github (https://github.com/Azure/azure-sdk-for-go/issues/18434) - please if you can vote there and put this to attention so.

Upvotes: 0

Related Questions