Skip to content

Commit 1e28104

Browse files
feat(new): Added Azure.Azure.VMSS.AutoInstanceRepairs (Azure#2897)
* feat(new): Added Azure.Azure.VMSS.AutoInstanceRepairs * fix: Fixed wrong issue reference --------- Co-authored-by: Bernie White <[email protected]>
1 parent 0e8ad12 commit 1e28104

File tree

5 files changed

+164
-0
lines changed

5 files changed

+164
-0
lines changed

docs/CHANGELOG-v1.md

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ See [upgrade notes][1] for helpful information when upgrading from previous vers
3333
- Log Analytics:
3434
- Check that workspaces have workspace replication enabled by @BenjaminEngeset.
3535
[#2893](https://github.com/Azure/PSRule.Rules.Azure/issues/2893)
36+
- Virtual Machine Scale Sets:
37+
- Check that automatic instance repairs are enabled by @BenjaminEngeset.
38+
[#2895](https://github.com/Azure/PSRule.Rules.Azure/issues/2895)
3639

3740
## v1.37.0-B0034 (pre-release)
3841

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
severity: Important
3+
pillar: Reliability
4+
category: RE:07 Self-preservation
5+
resource: Virtual Machine Scale Sets
6+
online version: https://azure.github.io/PSRule.Rules.Azure/en/rules/Azure.VMSS.AutoInstanceRepairs/
7+
---
8+
9+
# Automatic instance repairs
10+
11+
## SYNOPSIS
12+
13+
Automatic instance repairs are enabled.
14+
15+
## DESCRIPTION
16+
17+
Enabling automatic instance repairs helps to achieve high application availability by automatically detecting and recovering unhealthy VM instances at runtime.
18+
19+
The automatic instance repair feature relies on health monitoring of individual VM instances in a scale set.
20+
VM Instances in a scale set can be configured to emit application health status using either the Application Health extension or Load balancer health probes.
21+
If an VM instance is found to be unhealthy, the scale set will perform a preconfigured repair action on the unhealthy VM instance.
22+
Automatic instance repairs can be enabled in the Virtual Machine Scale Set model by using the `automaticRepairsPolicy` object.
23+
24+
See documentation references below for additional limitations and important information.
25+
26+
## RECOMMENDATION
27+
28+
Consider enabling automatic instance repairs to achieve high application availability by maintaining a set of healthy VM instances.
29+
30+
## EXAMPLES
31+
32+
### Configure with Azure template
33+
34+
To deploy virtual machine scale sets that pass this rule:
35+
36+
- Set the `properties.automaticRepairsPolicy.enabled` property to `true`.
37+
38+
For example:
39+
40+
```json
41+
{
42+
"type": "Microsoft.Compute/virtualMachineScaleSets",
43+
"apiVersion": "2023-09-01",
44+
"name": "[parameters('name')]",
45+
"location": "[parameters('location')]",
46+
"sku": {
47+
"name": "b2ms",
48+
"tier": "Standard",
49+
"capacity": 1
50+
},
51+
"properties": {
52+
"automaticRepairsPolicy": {
53+
"enabled": true
54+
}
55+
}
56+
}
57+
```
58+
59+
### Configure with Bicep
60+
61+
To deploy virtual machine scale sets that pass this rule:
62+
63+
- Set the `properties.automaticRepairsPolicy.enabled` property to `true`.
64+
65+
For example:
66+
67+
```bicep
68+
resource vmss 'Microsoft.Compute/virtualMachineScaleSets@2023-09-01' = {
69+
name: name
70+
location: location
71+
sku: {
72+
name: 'b2ms'
73+
tier: 'Standard'
74+
capacity: 1
75+
}
76+
properties: {
77+
automaticRepairsPolicy: {
78+
enabled: true
79+
}
80+
}
81+
}
82+
```
83+
84+
## NOTES
85+
86+
This feature for virtual machine scale sets is currently in preview.
87+
88+
In order for automatic repairs policy to work properly, ensure that all the requirements for opting in to this feature are met.
89+
90+
## LINKS
91+
92+
- [RE:07 Self-preservation](https://learn.microsoft.com/azure/well-architected/reliability/self-preservation)
93+
- [Automatic instance repairs](https://learn.microsoft.com/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-automatic-instance-repairs)
94+
- [Azure resource deployment](https://learn.microsoft.com/azure/templates/microsoft.compute/virtualmachinescalesets#automaticrepairspolicy)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
#
5+
# Validation rules for Azure Virtual Machine Scale Sets
6+
#
7+
8+
#region Rules
9+
10+
---
11+
# Synopsis: Automatic instance repairs are enabled.
12+
apiVersion: github.com/microsoft/PSRule/v1
13+
kind: Rule
14+
metadata:
15+
name: Azure.VMSS.AutoInstanceRepairs
16+
ref: AZR-000426
17+
tags:
18+
release: preview
19+
ruleSet: 2024_06
20+
Azure.WAF/pillar: Reliability
21+
spec:
22+
type:
23+
- Microsoft.Compute/virtualMachineScaleSets
24+
condition:
25+
field: properties.automaticRepairsPolicy.enabled
26+
equals: true
27+
28+
#endregion Rules

tests/PSRule.Rules.Azure.Tests/Azure.VMSS.Tests.ps1

+19
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,25 @@ Describe 'Azure.VMSS' -Tag 'VMSS' {
130130
$ruleResult.Length | Should -Be 2;
131131
$ruleResult.TargetName | Should -BeIn 'vmss-001', 'vmss-003';
132132
}
133+
134+
It 'Azure.VMSS.AutoInstanceRepairs' {
135+
$dataPath = Join-Path -Path $here -ChildPath 'Resources.VMSS.json';
136+
$result = Invoke-PSRule @invokeParams -InputPath $dataPath;
137+
$filteredResult = $result | Where-Object { $_.RuleName -eq 'Azure.VMSS.AutoInstanceRepairs' };
138+
139+
# Fail
140+
$ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Fail' });
141+
$ruleResult.Length | Should -Be 2;
142+
$ruleResult.TargetName | Should -BeIn 'vmss-001', 'vmss-002';
143+
144+
$ruleResult[0].Reason | Should -BeExactly "Path properties.automaticRepairsPolicy.enabled: The field 'properties.automaticRepairsPolicy.enabled' does not exist.";
145+
$ruleResult[1].Reason | Should -BeExactly "Path properties.automaticRepairsPolicy.enabled: Is set to 'False'.";
146+
147+
# Pass
148+
$ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Pass' });
149+
$ruleResult.Length | Should -Be 3;
150+
$ruleResult.TargetName | Should -BeIn 'vmss-003', 'vmss-004', 'vmss-005';
151+
}
133152
}
134153

135154
Context 'Resource name - Azure.VMSS.Name' {

tests/PSRule.Rules.Azure.Tests/Resources.VMSS.json

+20
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@
191191
"upgradePolicy": {
192192
"mode": "Manual"
193193
},
194+
"automaticRepairsPolicy": {
195+
"enabled": false,
196+
"gracePeriod": "PT10M",
197+
"repairAction": "Replace"
198+
},
194199
"virtualMachineProfile": {
195200
"osProfile": {
196201
"computerNamePrefix": "vmss-002",
@@ -366,6 +371,11 @@
366371
"upgradePolicy": {
367372
"mode": "Manual"
368373
},
374+
"automaticRepairsPolicy": {
375+
"enabled": true,
376+
"gracePeriod": "PT10M",
377+
"repairAction": "Replace"
378+
},
369379
"virtualMachineProfile": {
370380
"osProfile": {
371381
"computerNamePrefix": "vmss-003",
@@ -524,6 +534,11 @@
524534
"upgradePolicy": {
525535
"mode": "Manual"
526536
},
537+
"automaticRepairsPolicy": {
538+
"enabled": true,
539+
"gracePeriod": "PT10M",
540+
"repairAction": "Replace"
541+
},
527542
"virtualMachineProfile": {
528543
"osProfile": {
529544
"computerNamePrefix": "vmss-004",
@@ -683,6 +698,11 @@
683698
"upgradePolicy": {
684699
"mode": "Manual"
685700
},
701+
"automaticRepairsPolicy": {
702+
"enabled": true,
703+
"gracePeriod": "PT10M",
704+
"repairAction": "Replace"
705+
},
686706
"virtualMachineProfile": {
687707
"osProfile": {
688708
"computerNamePrefix": "vmss-005",

0 commit comments

Comments
 (0)