I am trying to create a VM and an SQLVM. I get this error when I run terraform apply:
│ Error: waiting for creation of Sql Virtual Machine (Sql Virtual Machine Name “mymachine” / Resource Group “sql-test”): Code=“Ext_StorageConfigurationSettings_ArgumentError” Message=“Error: ‘Failed to get valid physical disks within given device ID range.’”
│
│ with azurerm_mssql_virtual_machine.sqlvm,
│ on main.tf line 136, in resource “azurerm_mssql_virtual_machine” “sqlvm”:
│ 136: resource “azurerm_mssql_virtual_machine” “sqlvm” {
This is my code: terraform {
required_providers {
azurerm = {
source = “hashicorp/azurerm”
version = “=3.0.0”
}
}
}
Configure the Microsoft Azure Provider
provider “azurerm” {
skip_provider_registration = true # This is only required when the User, Service Principal, or Identity running Terraform lacks the permissions to register Azure Resource Providers.
features {}
}
Create a resource group
resource “azurerm_resource_group” “myrg” {
name = var.res_grp_name
location = var.res_grp_location
}
Create a virtual network within the resource group
resource “azurerm_virtual_network” “myvnet” {
name = “sql-vnet”
resource_group_name = azurerm_resource_group.myrg.name
location = azurerm_resource_group.myrg.location
address_space = var.address_space
tags = {
environment = “Test”
}
}
#Create two subnets
resource “azurerm_subnet” “subnet” {
name = var.subnet_name
resource_group_name = azurerm_resource_group.myrg.name
virtual_network_name = azurerm_virtual_network.myvnet.name
address_prefixes = var.address_prefix
}
resource “azurerm_network_interface” “nic” {
name = var.nic_name
location = azurerm_resource_group.myrg.location
resource_group_name = azurerm_resource_group.myrg.name
ip_configuration {
name = “internal”
subnet_id = azurerm_subnet.subnet.id
private_ip_address_allocation = “Dynamic”
}
}
#Create a VM
resource “azurerm_windows_virtual_machine” “myvm” {
name = var.vm_name
resource_group_name = azurerm_resource_group.myrg.name
location = azurerm_resource_group.myrg.location
size = var.vm_size
admin_username = var.admin_username
admin_password = var.admin_password
network_interface_ids = [
azurerm_network_interface.nic.id,
]
os_disk {
caching = “ReadWrite”
storage_account_type = “Standard_LRS”
}
source_image_reference {
publisher = “MicrosoftSQLServer”
offer = “SQL2019-WS2019”
sku = “SQLDEV”
version = “latest”
}
}
resource “azurerm_mssql_virtual_machine” “sqlvm” {
virtual_machine_id = azurerm_windows_virtual_machine.myvm.id
sql_license_type = “PAYG”
r_services_enabled = true
sql_connectivity_port = 1433
sql_connectivity_type = “PRIVATE”
sql_connectivity_update_password = “Password1234!”
sql_connectivity_update_username = “sqllogin”
storage_configuration {
disk_type = “NEW”
storage_workload_type = “GENERAL”
data_settings {
default_file_path = "F:\\data"
luns = [0]
}
log_settings {
default_file_path = "L:\\log"
luns = [1]
}
temp_db_settings {
default_file_path = "T:\\tempDb"
luns = [2]
}
}
auto_patching {
day_of_week = “Sunday”
maintenance_window_duration_in_minutes = 60
maintenance_window_starting_hour = 2
}
}