craigbtg
craigbtg

Reputation: 21

Azure InvalidParameter: StorageProfile.dataDisks.lun does not have required value(s) for image in storage profile

I have a script to create VMs on Azure using DS Series storage. I am trying to create a VM using one of the SQL Server optimized images. When I change the Publisher, Offer, and SKU to match the SQL Server image I keep getting an error:

InvalidParameter: StorageProfile.dataDisks.lun does not have required value(s) for image in storage profile

Does anyone know how I should modify the following script so that I can use one of the pre-defined image templates for SQL Server?

Switch-AzureMode AzureResourceManager

Add-AzureAccount

$subscr="subscription"
Select-AzureSubscription -SubscriptionName $subscr

$rgName="test-resource-group"
$locName="East US 2"
New-AzureResourceGroup -Name $rgName -Location $locName

$saName="testpremiumstorage"
$saType="Premium_LRS"
New-AzureStorageAccount -Name $saName -ResourceGroupName $rgName –Type $saType -Location $locName

$frontendSubnet=New-AzureVirtualNetworkSubnetConfig -Name "testfrontendSubnet" -AddressPrefix 10.3.3.0/24
$backendSubnet=New-AzureVirtualNetworkSubnetConfig -Name "testbackendSubnet" -AddressPrefix 10.3.2.0/24
New-AzurevirtualNetwork -Name "testVNet" -ResourceGroupName $rgName -Location $locName -AddressPrefix 10.3.0.0/16 -Subnet $frontendSubnet,$backendSubnet

$publicIP = New-AzurePublicIpAddress -Name "testPublicIp" -ResourceGroupName $rgName -Location $locName –AllocationMethod Static -DomainNameLabel "test-public-ip"
$frontendIP = New-AzureLoadBalancerFrontendIpConfig -Name "test-LB-Frontend" -PublicIpAddress $publicIP 
$beaddresspool= New-AzureLoadBalancerBackendAddressPoolConfig -Name "test-LB-backend"
$inboundNATRule1= New-AzureLoadBalancerInboundNatRuleConfig -Name "RDP1" -FrontendIpConfiguration $frontendIP -Protocol TCP -FrontendPort 3441 -BackendPort 3389
$inboundNATRule2= New-AzureLoadBalancerInboundNatRuleConfig -Name "RDP2" -FrontendIpConfiguration $frontendIP -Protocol TCP -FrontendPort 3442 -BackendPort 3389
$healthProbe = New-AzureLoadBalancerProbeConfig -Name "HealthProbe" -RequestPath "HealthProbe.aspx" -Protocol http -Port 80 -IntervalInSeconds 15 -ProbeCount 2
$lbrule = New-AzureLoadBalancerRuleConfig -Name "HTTP" -FrontendIpConfiguration $frontendIP -BackendAddressPool $beAddressPool -Protocol Tcp -FrontendPort 80 -BackendPort 80
$NRPLB = New-AzureLoadBalancer -ResourceGroupName $rgName -Name "test-LB" -Location $locName -FrontendIpConfiguration $frontendIP -InboundNatRule $inboundNATRule1,$inboundNatRule2 -LoadBalancingRule $lbrule -BackendAddressPool $beAddressPool -Probe $healthProbe

$nicName="test-NIC"
$lbName="test-LB"
$bePoolIndex=0
$vnetName="testVNet"
$subnetIndex=0
$natRuleIndex=0
$vnet=Get-AzurevirtualNetwork -Name $vnetName -ResourceGroupName $rgName
$lb=Get-AzureLoadBalancer -Name $lbName -ResourceGroupName $rgName 

$backendSubnet = Get-AzureVirtualNetworkSubnetConfig -Name "testbackendSubnet" -VirtualNetwork $vnet
$nic=New-AzureNetworkInterface -Name $nicName -ResourceGroupName $rgName -Location $locName -Subnet $backendSubnet -LoadBalancerBackendAddressPool $lb.BackendAddressPools[$bePoolIndex] -LoadBalancerInboundNatRule $lb.InboundNatRules[$natRuleIndex]

$vmName="test"
$vmSize="Standard_DS2"
$vm=New-AzureVMConfig -VMName $vmName -VMSize $vmSize

#This is where the error occurs.  If it is switched to the commented image everything will work fine but not when
#   trying to create the SQL Server based image
#$pubName="MicrosoftWindowsServer"
#$offerName="WindowsServer"
#$skuName="2012-R2-Datacenter"
$pubName="MicrosoftSQLServer"
$offerName="SQL2014SP1-WS2012R2"
$skuName="Enterprise-Optimized-for-OLTP"
$cred=Get-Credential -Message "Type the name and password of the local administrator account."
$vm=Set-AzureVMOperatingSystem -VM $vm -Windows -ComputerName $vmName -Credential $cred -ProvisionVMAgent -EnableAutoUpdate
$vm=Set-AzureVMSourceImage -VM $vm -PublisherName $pubName -Offer $offerName -Skus $skuName -Version "latest"
$vm=Add-AzureVMNetworkInterface -VM $vm -Id $nic.Id

$diskName="test-OSDisk"
$storageAcc=Get-AzureStorageAccount -ResourceGroupName $rgName -Name $saName
$osDiskUri=$storageAcc.PrimaryEndpoints.Blob.ToString() + "vhds/" + $diskName  + ".vhd"
$vm=Set-AzureVMOSDisk -VM $vm -Name $diskName -VhdUri $osDiskUri -CreateOption fromImage
New-AzureVM -ResourceGroupName $rgName -Location $locName -VM $vm

As noted in the script there is a section where the Publisher, Offer, and SKU are defined. When those are switched to the SQL Server related items the script fails with the error but if they use the basic Windows Server 2012 items the script will run fine. Could the item names be different if using premium storage or is there a different way to create the VM?

Upvotes: 1

Views: 2517

Answers (1)

Roelant
Roelant

Reputation: 5119

Some steps that helped me to solve similar issues:

  • Check if you indeed have the right name - see @theadriangreen's link link and the listing commands behind az vm image --help
  • Check if you added plan information to the spin-up
  • Check if you have accepted the terms with az vm image accept-terms --help

Upvotes: 1

Related Questions