Hello @八重樫 剛史 Takeshi Yaegashi ,
Thanks for the detailed description of the problem statement.
Went through the setup.ps1 script, basically the problem is with $LUN variable which is passed as a parameter which will always have the value of 0. That variable value needs to be incremented by 1 every time when you try to attach a new data disk. Since it is trying to use the same number hence it is complaining about the conflict.
Example Repro:
When we run the command:
Add-AzvmssVMDataDisk -VirtualMachineScaleSetVM $vm -ManagedDiskId $disk.Id -Caching "ReadOnly" -CreateOption Attach -Lun 0 | Update-AzvmssVM
It will add and attach the data disk with LUN 0
Now If i run the same command for the second disk
Add-AzvmssVMDataDisk -VirtualMachineScaleSetVM $vm -ManagedDiskId $disk.Id -Caching "ReadOnly" -CreateOption Attach -Lun 0 | Update-AzvmssVM
Update-AzvmssVM : A disk named 'testdisk1' already uses the same LUN: 0.
ErrorCode: InvalidParameter
ErrorMessage: A disk named 'testdisk1' already uses the same LUN: 0.
ErrorTarget: dataDisk.lun
StatusCode: 400
ReasonPhrase: Bad Request
OperationID : 831f1bcf-7fcb-4922-9d6f-00eef6d15fb5
At line:1 char:130
- ... -Caching "ReadOnly" -CreateOption Attach -Lun 0 | Update-AzvmssVM
- ~~~~~~~~~~~~~~~
- CategoryInfo : CloseError: (:) [Update-AzVmssVM], ComputeCloudException
- FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.Automation.UpdateAzureRmVmssVM
///////////////////////////////////
Now If i change the last command to use LUN 1
Add-AzvmssVMDataDisk -VirtualMachineScaleSetVM $vm -ManagedDiskId $disk.Id -Caching "ReadOnly" -CreateOption Attach -Lun 1 | Update-AzvmssVM
Mitigation:
So the fix for your script should be to increment the value of LUN every time when a new data disk gets added before adding the next disk.
All the very best !!
If the above details help out in resolving your issue , please make sure to "Upvote & Accept the answer"
Regards,
Shiva.