Rule not finding field in JSON Configuration #2786
-
Hi, I'm just starting to work with PSRule in an effort to migrate from an internally built infrastructure testing platform that uses Pester. Our infrastructure is defined in JSON configuration files with a custom schema. Our configurations will remain as they are I'll just be moving to PSRule rule modules for configuration validation and eventually configuration drift detection. My problem that I'm struggling to work out and I'm sure it's just me understanding at this stage, I do read the docs (thank you for excellent documentation), is that if I collect a configuration file using a
But when running supplying the config file as the value to the Can I please get any guidance on what I may be doing wrong, collecting files will be key as part of the effort and building out the validation pipeline in jenkins. Config schema example: {
"Type": {
"datacenter": {
"Name": [
"DEV_LAB"
]
}
}
} Rule: # Synopsis: Name array contains at least one member.
apiVersion: github.com/microsoft/PSRule/v1
kind: Rule
metadata:
name: datacenter.name.member.count
ref: VAF-011
spec:
condition:
field: Type.datacenter.Name
greaterOrEquals: 1 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Apologies wrong error message:
|
Beta Was this translation helpful? Give feedback.
If you're using PSRule v2.9.0, then try adding
-Format Json
to the end of yourAssert-PSRule
command line.The reason is because you are piping a file object to
Assert-PSRule
, and by default it's going to look at and analyze the file object instead of the content of the file. Since the file object doesn't have that property the rule failed as expected.Also, you can simplify this if you want by removing the
Get-ChildItem
part.e.g.
Also noting there is changes to how this works in v3 which is preview, so if you are developing something new, be aware of these changes so you can avoid re…