I have an issue with a DSC config i'm trying to use to install and run a mongo service on an Azure VM.
When the DSC runs on the initial deployment of the VM, the secondary disk 'F' is attached and formatted successfully, however... i receive an error when trying to create directories on the new disk:
Error message: \"DSC Configuration 'Main' completed with error(s).
Cannot find drive. A drive with the name 'F' does not exist.
The PowerShell DSC resource '[Script]SetUpDataDisk' with SourceInfo 'C:\\Packages\\Plugins\\Microsoft.Powershell.DSC\\2.73.0.0\\DSCWork\\MongoDSC.0\\MongoDSC.ps1::51::2::Script' threw one or more non-terminating errors while running the Set-TargetResource functionality.
Here is my DSC script :
Configuration Main
{
Param ( [string] $nodeName )
Import-DscResource -ModuleName PSDesiredStateConfiguration
Import-DscResource -ModuleName xStorage
Node $nodeName
{
xWaitforDisk Disk2
{
DiskId = 2
RetryIntervalSec = 60
RetryCount = 60
}
xDisk FVolume
{
DiskId = 2
DriveLetter = 'F'
FSLabel = 'MongoData'
DependsOn = "[xWaitforDisk]Disk2"
}
Script SetUpDataDisk{
TestScript ={
return Test-Path "f:\mongoData\"
}
SetScript ={
#set up the directories for mongo
$retries = 0
Do{
$mountedDrive = Get-Volume | Where DriveLetter -eq 'F'
if($mountedDrive -eq $null)
{
Start-Sleep -Seconds 60
$retries = $retries + 1
}
}While(($mountedDrive -eq $null) -and ($retries -lt 60))
$dirName = "mongoData"
$dbDirName = "db"
$logDirName = "logs"
##! ERROR THROWN FROM THESE LINES
New-Item -Path "F:\$dirName" -ItemType Directory
New-Item -Path "F:\$dirName\$dbDirName" -ItemType Directory
New-Item -Path "F:\$dirName\$logDirName" -ItemType Directory
}
GetScript = {@{Result = "SetUpDataDisk"}}
DependsOn = "[xDisk]FVolume"
}
}
}
The annoying thing is that if i run the deployment again everything works with no errors, i have put a loop in to try and wait for the disk to be ready but this still throws the error. I'm very new to DSC so any pointers would be helpful.