DnsServerDsc
DnsServerDsc copied to clipboard
DnsServerDsc: Resources errors on test if DNS is not installed
xDNSServerForwarder (as well as other resource in the module) need error handling logic to gracefully return FALSE on the Test function when DNS is not installed. This is particularly needed when DSC is used to audit a server config without applying.
@GoateePFE I'd be willing to add this functionality. What do you believe the best way to do this would be?
I'm not sure how to best handle the error. I'm thinking to update the get function to return an empty IPAddresses array, test should then not throw an error.
@Persistent13 That should do it for now.
Long term we should probably add a function to the root of the resource module to check for the presence of the DNS server role and warn if it is not installed. Then all resources could reference that.
Function Test-DNSServerRole { [CmdletBinding()] Param() If ((Get-WindowsFeature DNS).Installed) { Write-Verbose "DNS server role installed." Return $true } Else { Write-Verbose "DNS server role NOT installed." Return $false } }
Easy enough.
I'm sure there's an Assert-Module function in the xActiveDirectory module that you can copy/duplicate!
Label this as help wanted to that someone in the community can run with this.
https://github.com/PowerShell/xDnsServer/blob/dev/DSCResources/Helper.psm1
This Helper Module includes Internal function to assert if the role specific module is installed or not function Assert-Module
So just need to ensure that the others include and use it
Assert-Module will still error out on Get if the module isn't installed. I think Assert-Module still needs to be added to all of the resources in xDnsServer.
For not erroring out on Get we could do a try catch:
try
{
Assert-Module -ModuleName 'DNS'
}
catch
{
Write-Warning -Message 'DNS module is not installed and this resource will not work properly.'
return @{
Ensure = 'Absent'
Prop = $null
}
}
Actually since Get nor Set use any cmdlets from the DNS module we can just remove Assert-Module
?
https://github.com/dsccommunity/xDnsServer/blob/2a8ea7f52c1a29637a5fc895105b8defeddbe4d8/source/DSCResources/MSFT_xDnsServerSetting/MSFT_xDnsServerSetting.psm1#L22
and
https://github.com/dsccommunity/xDnsServer/blob/2a8ea7f52c1a29637a5fc895105b8defeddbe4d8/source/DSCResources/MSFT_xDnsServerSetting/MSFT_xDnsServerSetting.psm1#L225
Most of the resources in XDnsServer do require it. So I was thinking it needed to be added to those.
This was specifically opened to not error out in Get, is that something we can support?
Yes to both. For all the resource; Get-TargetResource should be able to return the result without throwing an error. It should always return the correct hashtable (all the properties in the schema), either with the actual current values or with null values for those properties it cannot fetch. Key properties should always be set to the configuration values and if there is an Ensure property it should be set to Absent if the Key values does not exist in the current state.
Awesome. I will look at doing that.