Skip to content

Commit

Permalink
Fixed use of lower case Tags resource property #43 (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
BernieWhite committed Jan 1, 2021
1 parent 770bba5 commit e73071f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

What's changed since pre-release v0.1.0-B2012004:

- Bug fixes:
- Fixed use of lower case `Tags` resource property. [#43](https://github.com/microsoft/PSRule.Rules.CAF/issues/43)

## v0.1.0-B2012004 (pre-release)

What's changed since pre-release v0.1.0-B2009009:
Expand Down
13 changes: 8 additions & 5 deletions src/PSRule.Rules.CAF/rules/CAF.Tag.Rule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Rule 'CAF.Tag.Resource' -If { (CAF_SupportsTags) -and !(CAF_IsResourceGroup) -an
if ($required.Length -eq 0) {
return $Assert.Pass();
}
$Assert.HasField($TargetObject, 'Tags');
$Assert.HasField($TargetObject, 'tags');
if ($Null -ne $TargetObject.Tags) {
$Assert.HasFields($TargetObject.Tags, $required, $Configuration.CAF_MatchTagNameCase);
}
Expand All @@ -23,14 +23,17 @@ Rule 'CAF.Tag.ResourceGroup' -Type 'Microsoft.Resources/resourceGroups' -If { ($
if ($required.Length -eq 0) {
return $Assert.Pass();
}
$Assert.HasField($TargetObject, 'Tags');
$Assert.HasField($TargetObject, 'tags');
if ($Null -ne $TargetObject.Tags) {
$Assert.HasFields($TargetObject.Tags, $required, $Configuration.CAF_MatchTagNameCase);
}
}

# Synopsis: Tag resources and resource groups with a valid environment.
Rule 'CAF.Tag.Environment' -If { (CAF_SupportsTags) -and (Exists "Tags.$($Configuration.CAF_EnvironmentTag)") } {
$Assert.HasField($TargetObject, "Tags.$($Configuration.CAF_EnvironmentTag)", $Configuration.CAF_MatchTagNameCase);
$Assert.In($TargetObject, "Tags.$($Configuration.CAF_EnvironmentTag)", $Configuration.CAF_Environments, $Configuration.CAF_MatchTagValueCase)
Rule 'CAF.Tag.Environment' -If { (CAF_SupportsTags) -and (Exists "tags.$($Configuration.CAF_EnvironmentTag)") } {
$Assert.HasField($TargetObject, 'tags');
if ($Null -ne $TargetObject.Tags) {
$Assert.HasField($TargetObject.Tags, $Configuration.CAF_EnvironmentTag, $Configuration.CAF_MatchTagNameCase);
$Assert.In($TargetObject.Tags, $Configuration.CAF_EnvironmentTag, $Configuration.CAF_Environments, $Configuration.CAF_MatchTagValueCase);
}
}
2 changes: 1 addition & 1 deletion tests/PSRule.Rules.CAF.Tests/CAF.Tag.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Describe 'CAF.Tag' -Tag 'tag' {
@{
Name = 'vnet-A'
Type = 'Microsoft.Network/virtualNetworks'
Tags = @{
tags = @{
Env = 'Prod'
}
},
Expand Down

0 comments on commit e73071f

Please sign in to comment.