microsoft / PSRule-pipelines

Validate infrastructure as code (IaC) and DevOps repositories using Azure Pipelines.
https://marketplace.visualstudio.com/items?itemName=bewhite.ps-rule
MIT License
89 stars 23 forks source link

Custom rule always fails #345

Closed majorku5anagi closed 2 years ago

majorku5anagi commented 2 years ago

Hi, I have an issue or maybe my own understanding is wrong on how to make custom rule. Namely, I wanted to make simple check of existence of Tags within Bicep file. I've setup ps-rule.yaml file in which I set cofnfiguration for expansion because of the Bicep code and I've created .ps-rule folder with countryTag.Rule.ps1 with custom rule. Whichever approach I make in creating the rule it always fails. Built-in PSRule works great and it actually sees which resources I'm trying to deploy and therefore pulls out all related Azure Well Architecture Framework rules and compare it with PASS/FAIL flags correctly. My custom rule is being run as I can see it on the beginning of the report but it is always in FAIL status no matter what I do and in the setup that I currently have I expect it to PASS. Screenshots of all mentioned PSRules files are below alongside with portion of the Bicep code that shows the tag existence.

.ps-rule/countryTag.Rule.ps1:

image

ps-rule.yaml:

image

Bicep code:

image

When I tried different approach by fulfilling the countryTag.Rule.ps1 with this code I received again FAIL status. This time I deliberately made correction on the bicep file so that all builtin checks to pass. Only custom rule didn't :

image

image

BernieWhite commented 2 years ago

@majorku5anagi Closing because this question is answered over here: https://github.com/Azure/PSRule.Rules.Azure/discussions/1332