-
Can anyone help me? I'm trying to learn how this works. I'm trying to create a custom rule to validate if an ARM template has resource property minimumTlsVersion and if so, that it is set to Unfortunately, I can not get it to work. This is what I have come up with thus far: # Synopsis: TESTING - should reject TLS versions older than 1.2.
Rule 'Azure.Template.MinTLS' -Type '.json' -If { (IsTemplateFile) } -Tag @{ release = 'TST'; ruleSet = '2022_03' } {
# $TargetObject.Properties.minimumTlsVersion -eq '^\[.*\]$'
$jsonObject = $PSRule.GetContent($TargetObject)[0].resources;
return $Assert.HasField($jsonObject, 'properties.minimumTlsVersion').Result;
} Outcome of the test: The ARM template does have property minimumTlsVersion. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
I managed to solve my challenge. However, I do wonder if this is the best solution. # Synopsis: TESTING - should reject TLS versions older than 1.2.
Rule 'Azure.Template.MinTLS' -Type '.json' -If { (IsTemplateFile) } -Tag @{ release = 'TST'; ruleSet = '2022_03' } {
$jsonObject = $PSRule.GetContent($TargetObject)[0].resources[0];
AnyOf {
$Assert.NotHasField($jsonObject, 'properties.minimumTlsVersion');
$Assert.Match($jsonObject, 'properties.minimumTlsVersion', 'TLS1_2');
$Assert.Match($jsonObject, 'properties.minimumTlsVersion', '1\.2');
$Assert.Match($jsonObject, 'properties.minimumTlsVersion', '^\[.*\]$');
}
} |
Beta Was this translation helpful? Give feedback.
I managed to solve my challenge.
Property resources of
$TargetObject
is an array. By specifying the first array entry in that object I got access to the properties of the ARM template.However, I do wonder if this is the best solution.
Any feedback is much appreciated.