Skip to content

Commit 77b01bd

Browse files
authored
Add Start-AzPolicyComplianceScan cmdlet (#11478)
1 parent edc8728 commit 77b01bd

File tree

56 files changed

+5426
-544
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+5426
-544
lines changed

src/PolicyInsights/PolicyInsights.Test/PolicyInsights.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.Azure.Management.PolicyInsights" Version="3.0.0" />
14+
<PackageReference Include="Microsoft.Azure.Management.PolicyInsights" Version="3.1.0" />
1515
</ItemGroup>
1616

1717
</Project>

src/PolicyInsights/PolicyInsights.Test/ScenarioTests/Common.ps1

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Gets test resource group group name
2727
#>
2828
function Get-TestResourceGroupName
2929
{
30-
"cleanupservice"
30+
"cheggpolicy"
3131
}
3232

3333
<#
@@ -36,7 +36,7 @@ Gets test resource id
3636
#>
3737
function Get-TestResourceId
3838
{
39-
"/subscriptions/0b40be06-04e8-4f70-abde-a502b2646fe8/resourcegroups/cleanupservice/providers/Microsoft.KeyVault/vaults/kv12-cleanupservice"
39+
"/subscriptions/e78961ba-36fe-4739-9212-e3031b4c8db7/resourcegroups/cheggpolicy/providers/microsoft.keyvault/vaults/cheggkv"
4040
}
4141

4242
<#
@@ -45,7 +45,7 @@ Gets test policy set definition name
4545
#>
4646
function Get-TestPolicySetDefinitionName
4747
{
48-
"716ef2c9-4404-4673-8609-f984d58c417d"
48+
"81811175-958c-478d-936a-d96e158a8c66"
4949
}
5050

5151
<#
@@ -54,7 +54,7 @@ Gets test policy definition name
5454
#>
5555
function Get-TestPolicyDefinitionName
5656
{
57-
"policy2"
57+
"3520924f-7a65-4cbf-83e6-e2ed67bbf0da"
5858
}
5959

6060
<#
@@ -63,7 +63,7 @@ Gets test policy assignment name
6363
#>
6464
function Get-TestPolicyAssignmentName
6565
{
66-
"SecurityCenterBuiltIn"
66+
"1e4e70f9cd4846268b6998ee"
6767
}
6868

6969
<#
@@ -72,7 +72,7 @@ Gets test resource group group name for resource group level policy assignment (
7272
#>
7373
function Get-TestResourceGroupNameForPolicyAssignmentEvents
7474
{
75-
"cleanupservice"
75+
"cheggpolicy"
7676
}
7777

7878
<#
@@ -81,7 +81,7 @@ Gets test policy assignment name (resource group level) (for event tests)
8181
#>
8282
function Get-TestPolicyAssignmentNameResourceGroupLevelEvents
8383
{
84-
"568e500984414fbe8a4f10d0"
84+
"8a4555d353ed46bb856e9890"
8585
}
8686

8787
<#
@@ -90,7 +90,7 @@ Gets test policy definition name for events
9090
#>
9191
function Get-TestPolicyDefinitionNameForEvents
9292
{
93-
"d994a92a-7669-4735-9950-bdcc326f32e4"
93+
"926d9eb2-ac1e-4408-b27a-9c61a70f8ff8"
9494
}
9595

9696
<#
@@ -99,7 +99,7 @@ Gets test resource group group name for resource group level policy assignment (
9999
#>
100100
function Get-TestResourceGroupNameForPolicyAssignmentStates
101101
{
102-
"cleanupservice"
102+
"cheggpolicy"
103103
}
104104

105105
<#
@@ -108,7 +108,7 @@ Gets test policy assignment name (resource group level) (for state tests)
108108
#>
109109
function Get-TestPolicyAssignmentNameResourceGroupLevelStates
110110
{
111-
"147b065f2a0f409ca31325c7"
111+
"8a4555d353ed46bb856e9890"
112112
}
113113

114114
<#
@@ -117,7 +117,7 @@ Gets test query interval start
117117
#>
118118
function Get-TestQueryIntervalStart
119119
{
120-
"2019-12-01 00:00:00Z"
120+
"2020-03-24 00:00:00Z"
121121
}
122122

123123
<#
@@ -126,7 +126,7 @@ Gets test query interval end
126126
#>
127127
function Get-TestQueryIntervalEnd
128128
{
129-
"2019-12-06 00:00:00Z"
129+
"2020-03-30 00:00:00Z"
130130
}
131131

132132
<#

src/PolicyInsights/PolicyInsights.Test/ScenarioTests/PolicyStateTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,30 @@ public void AllResourceGroupLevelPolicyAssignmentScope()
149149
}
150150

151151
#endregion
152+
153+
#region Trigger Evaluation
154+
155+
[Fact]
156+
[Trait(Category.AcceptanceType, Category.CheckIn)]
157+
public void TriggerEvaluationSubscriptionScope()
158+
{
159+
TestController.NewInstance.RunPowerShellTest(_logger, "Start-AzPolicyComplianceScan-SubscriptionScope");
160+
}
161+
162+
[Fact]
163+
[Trait(Category.AcceptanceType, Category.CheckIn)]
164+
public void TriggerEvaluationResourceGroupScope()
165+
{
166+
TestController.NewInstance.RunPowerShellTest(_logger, "Start-AzPolicyComplianceScan-ResourceGroupScope");
167+
}
168+
169+
[Fact]
170+
[Trait(Category.AcceptanceType, Category.CheckIn)]
171+
public void TriggerEvaluationSubscriptionScope_AsJob()
172+
{
173+
TestController.NewInstance.RunPowerShellTest(_logger, "Start-AzPolicyComplianceScan-SubscriptionScope-AsJob");
174+
}
175+
176+
#endregion
152177
}
153178
}

src/PolicyInsights/PolicyInsights.Test/ScenarioTests/PolicyStateTests.ps1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,34 @@ function Get-AzureRmPolicyState-AllResourceGroupLevelPolicyAssignmentScope
211211
$policyStates = Get-AzPolicyState -All -ResourceGroupName $resourceGroupName -PolicyAssignmentName $policyAssignmentName -Top 10
212212
Validate-PolicyStates $policyStates 10
213213
}
214+
215+
<#
216+
.SYNOPSIS
217+
Trigger a policy compliance scan at subscription scope
218+
#>
219+
function Start-AzPolicyComplianceScan-SubscriptionScope
220+
{
221+
Assert-True { Start-AzPolicyComplianceScan -PassThru }
222+
}
223+
224+
<#
225+
.SYNOPSIS
226+
Trigger a policy compliance scan at subscription scope
227+
#>
228+
function Start-AzPolicyComplianceScan-SubscriptionScope-AsJob
229+
{
230+
$job = Start-AzPolicyComplianceScan -PassThru -AsJob
231+
$job | Wait-Job
232+
Assert-AreEqual "Completed" $job.State
233+
Assert-True { $job | Receive-Job }
234+
}
235+
236+
<#
237+
.SYNOPSIS
238+
Trigger a policy compliance scan at resource group scope
239+
#>
240+
function Start-AzPolicyComplianceScan-ResourceGroupScope
241+
{
242+
$resourceGroupName = Get-TestResourceGroupNameForPolicyAssignmentStates
243+
Assert-True { Start-AzPolicyComplianceScan -ResourceGroupName $resourceGroupName -PassThru }
244+
}

src/PolicyInsights/PolicyInsights.Test/SessionRecords/Microsoft.Azure.Commands.PolicyInsights.Test.ScenarioTests.PolicyEventTests/ManagementGroupScope.json

Lines changed: 13 additions & 13 deletions
Large diffs are not rendered by default.

src/PolicyInsights/PolicyInsights.Test/SessionRecords/Microsoft.Azure.Commands.PolicyInsights.Test.ScenarioTests.PolicyEventTests/PolicyDefinitionScope.json

Lines changed: 14 additions & 14 deletions
Large diffs are not rendered by default.

src/PolicyInsights/PolicyInsights.Test/SessionRecords/Microsoft.Azure.Commands.PolicyInsights.Test.ScenarioTests.PolicyEventTests/PolicySetDefinitionScope.json

Lines changed: 12 additions & 12 deletions
Large diffs are not rendered by default.

src/PolicyInsights/PolicyInsights.Test/SessionRecords/Microsoft.Azure.Commands.PolicyInsights.Test.ScenarioTests.PolicyEventTests/ResourceGroupLevelPolicyAssignmentScope.json

Lines changed: 13 additions & 13 deletions
Large diffs are not rendered by default.

src/PolicyInsights/PolicyInsights.Test/SessionRecords/Microsoft.Azure.Commands.PolicyInsights.Test.ScenarioTests.PolicyEventTests/ResourceGroupScope.json

Lines changed: 13 additions & 13 deletions
Large diffs are not rendered by default.

src/PolicyInsights/PolicyInsights.Test/SessionRecords/Microsoft.Azure.Commands.PolicyInsights.Test.ScenarioTests.PolicyEventTests/ResourceScope.json

Lines changed: 12 additions & 12 deletions
Large diffs are not rendered by default.

src/PolicyInsights/PolicyInsights.Test/SessionRecords/Microsoft.Azure.Commands.PolicyInsights.Test.ScenarioTests.PolicyEventTests/SubscriptionLevelPolicyAssignmentScope.json

Lines changed: 13 additions & 13 deletions
Large diffs are not rendered by default.

src/PolicyInsights/PolicyInsights.Test/SessionRecords/Microsoft.Azure.Commands.PolicyInsights.Test.ScenarioTests.PolicyEventTests/SubscriptionScope.json

Lines changed: 12 additions & 12 deletions
Large diffs are not rendered by default.

src/PolicyInsights/PolicyInsights.Test/SessionRecords/Microsoft.Azure.Commands.PolicyInsights.Test.ScenarioTests.PolicyStateSummaryTests/ManagementGroupScope.json

Lines changed: 12 additions & 12 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)