microsoft / PSRule

Validate infrastructure as code (IaC) and objects using PowerShell rules.
https://microsoft.github.io/PSRule/v2/
MIT License
376 stars 49 forks source link

'Rule' keyword : the 'DependsOn' can define circular dependencies #190

Closed LaurentDardenne closed 5 years ago

LaurentDardenne commented 5 years ago

Description of the issue I can declare rules that depend on each other, which causes a StackOverflowException :

$Path='C:\temp'
$File='Test.Rule.ps1'
@'
Rule Main -DependsOn 'Dependency1' {
    $True
} 

Rule Dependency1  -DependsOn 'Dependency2'  {
    $true
}

Rule Dependency2  -DependsOn 'Main' { 
    $true
}
'@ >"$Path\$File"

cd $path
'object'|Invoke-psrule -path "$path\$File"

#Process is terminated due to StackOverflowException.

Expected behaviour If possible, notify the user of the presence of this type of design error.

BernieWhite commented 5 years ago

@LaurentDardenne Agree. Ideally a circular dependency check would occur and flag the issue.

This shouldn't be to hard to add as a pre-check.