Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap individual policy assignments to alzDefaultPolicyAssignments module in E2E tests #183

Merged
merged 22 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f6dc1d9
Update file to new path
jfaurskov Mar 11, 2022
0b1cfa0
Update tests/pipelines/bicep-build-to-validate.yml
jfaurskov Mar 11, 2022
53f2c04
Update tests/pipelines/bicep-build-to-validate.yml
jfaurskov Mar 11, 2022
be69552
Add script to loop retries
jfaurskov Mar 22, 2022
d0e9568
Merge branch 'alzdefaultpolassignunittest' of https://github.com/jfau…
jfaurskov Mar 22, 2022
ecc2390
Merge branch 'main' into alzdefaultpolassignunittest
jfaurskov Mar 22, 2022
7e82b5a
decrease wait time for script
jfaurskov Mar 22, 2022
3a2de45
add throw on threshold met
jfaurskov Mar 22, 2022
fc7bc39
fix unused param
jfaurskov Mar 22, 2022
64b220b
Update .github/scripts/Set-AlzDefaultPolicyAssignment.ps1
jfaurskov Mar 23, 2022
44ce4f9
Update .github/scripts/Set-AlzDefaultPolicyAssignment.ps1
jfaurskov Mar 23, 2022
f8cf8dd
Update tests/pipelines/bicep-build-to-validate.yml
jfaurskov Mar 23, 2022
215d162
Include policyAssignmentManagementGroup.bicep
jfaurskov Mar 23, 2022
ac36be0
Merge branch 'alzdefaultpolassignunittest' of https://github.com/jfau…
jfaurskov Mar 23, 2022
d74a540
fix displayname on pwsh task
jfaurskov Mar 23, 2022
4740620
trigger pipeline
jfaurskov Mar 23, 2022
61a2253
handle string
jfaurskov Mar 23, 2022
53878f7
remove quotes around subscriptionId
jfaurskov Mar 23, 2022
844e0dd
Include quotes in array
jfaurskov Mar 23, 2022
3db58ac
remove E2E trigger
jfaurskov Mar 23, 2022
c6ec7d5
re-include trigger
jfaurskov Mar 23, 2022
0e4eaff
Remove trigger again
jfaurskov Mar 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/scripts/Set-AlzDefaultPolicyAssignment.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

param (
#Added this back into parameters as error occurs if multiple tenants are found when using Get-AzTenant
[Parameter(Mandatory = $true)] [string] $ManagementGroupId,
[Parameter(Mandatory = $true)] [string] $parLocation,
[Parameter(Mandatory = $true)] [string] $templateFile,
[Parameter(Mandatory = $true)] [string] $parameterFile,
[Parameter(Mandatory = $true)] [string] $parTopLevelManagementGroupPrefix,
[Parameter(Mandatory = $true)] [string] $parLogAnalyticsWorkSpaceAndAutomationAccountLocation,
[Parameter(Mandatory = $true)] [string] $parLogAnalyticsWorkspaceResourceID,
[Parameter(Mandatory = $true)] [string] $parDdosProtectionPlanId
)
$state = 'fail'
$i = 0
$err.clear
while ($i -lt 4 -and $state -eq 'fail') {
$ErrorActionPreference = "Stop"
Try {
New-AzManagementGroupDeployment -Managementgroupid $ManagementGroupId -Location $parLocation -TemplateFile $templateFile -TemplateParameterFile $parameterFile -parTopLevelManagementGroupPrefix $parTopLevelManagementGroupPrefix -parLogAnalyticsWorkSpaceAndAutomationAccountLocation $parLogAnalyticsWorkSpaceAndAutomationAccountLocation -parLogAnalyticsWorkspaceResourceID $parLogAnalyticsWorkspaceResourceID -parDdosProtectionPlanId $parDdosProtectionPlanId
$state = 'success'
}
Catch {
$i++
Write-Output "Default policy assignment failed with $error"
jfaurskov marked this conversation as resolved.
Show resolved Hide resolved
Write-Output "Iteration number $i"
Write-Output "Will retry in 30 seconds"
Start-Sleep -Seconds 30
}
}
If ($state -eq 'fail') {
Throw "Default policy assignment failed"
jfaurskov marked this conversation as resolved.
Show resolved Hide resolved
}
23 changes: 13 additions & 10 deletions tests/pipelines/bicep-build-to-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
git_diff1=$(git diff --name-only HEAD^ HEAD infra-as-code/bicep/modules/managementGroups/managementGroups.bicep)
git_diff2=$(git diff --name-only HEAD^ HEAD infra-as-code/bicep/modules/customRoleDefinitions/customRoleDefinitions.bicep)
git_diff3=$(git diff --name-only HEAD^ HEAD infra-as-code/bicep/modules/policy/definitions/custom-policy-definitions.bicep)
git_diff4=$(git diff --name-only HEAD^ HEAD infra-as-code/bicep/modules/policy/assignments/policyAssignmentManagementGroup.bicep)
git_diff4=$(git diff --name-only HEAD^ HEAD infra-as-code/bicep/modules/policy/assignments/alzDefaults/alzDefaultPolicyAssignments.bicep)
jfaurskov marked this conversation as resolved.
Show resolved Hide resolved
git_diff5=$(git diff --name-only HEAD^ HEAD infra-as-code/bicep/modules/subscriptionPlacement/subscriptionPlacement.bicep)
git_diff6=$(git diff --name-only HEAD^ HEAD infra-as-code/bicep/modules/roleAssignments/roleAssignmentManagementGroup.bicep)
if [[ $git_diff1 != '' ]] || [[ $git_diff2 != '' ]] || [[ $git_diff3 != '' ]] || [[ $git_diff4 != '' ]] || [[ $git_diff5 != '' ]] || [[ $git_diff6 != '' ]]
Expand Down Expand Up @@ -151,15 +151,6 @@ jobs:
script: |
az deployment group create --resource-group $(ResourceGroupName) --template-file infra-as-code/bicep/modules/logging/logging.bicep --parameters @infra-as-code/bicep/modules/logging/logging.parameters.example.json

- task: Bash@3
displayName: Az CLI Policy Assignment DINE for PR
name: create_policy_assignment_dine
condition: and(ne(variables['gitManagementOUTPUT'], ''), ne(variables['subscriptionId'], ''))
inputs:
targetType: 'inline'
script: |
az deployment mg create --template-file infra-as-code/bicep/modules/policy/assignments/alzDefaults/alzDefaultPolicyAssignments.bicep --parameters @infra-as-code/bicep/modules/policy/assignments/alzDefaults/alzDefaultPolicyAssignments.parameters.example.json parTopLevelManagementGroupPrefix=$(ManagementGroupPrefix) parLogAnalyticsWorkSpaceAndAutomationAccountLocation=$(Location) parLogAnalyticsWorkspaceResourceID="/subscriptions/$(subscriptionId)/resourceGroups/$(ResourceGroupName)/providers/Microsoft.OperationalInsights/workspaces/alz-log-analytics" parDdosProtectionPlanId="/subscriptions/$(subscriptionId)/resourceGroups/$(ResourceGroupName)/providers/Microsoft.Network/ddosProtectionPlans/alz-Ddos-Plan" --location $(Location) --management-group-id "$(ManagementGroupPrefix)-platform"

- task: Bash@3
displayName: Az CLI Subscription Placement for PR
name: move_sub
Expand All @@ -169,6 +160,18 @@ jobs:
script: |
az deployment mg create --template-file infra-as-code/bicep/modules/subscriptionPlacement/subscriptionPlacement.bicep --parameters @infra-as-code/bicep/modules/subscriptionPlacement/subscriptionPlacement.parameters.example.json parTargetManagementGroupId=$(ManagementGroupPrefix)-platform-connectivity parSubscriptionIds='[$(subscriptionId)]' --location $(Location) --management-group-id $(ManagementGroupPrefix)

- task: AzurePowerShell@5
displayName: Az CLI Policy Assignment DINE for PR
jfaurskov marked this conversation as resolved.
Show resolved Hide resolved
jfaurskov marked this conversation as resolved.
Show resolved Hide resolved
name: alz_default_policy_assignments
condition: and(ne(variables['gitManagementOUTPUT'], ''), ne(variables['subscriptionId'], ''))
inputs:
azureSubscription: 'azserviceconnection'
ScriptType: 'FilePath'
ScriptPath: '.github/scripts/Set-AlzDefaultPolicyAssignment.ps1'
ScriptArguments: '-ManagementGroupId "$(ManagementGroupPrefix)-platform" -parLocation $(Location) -templateFile ./infra-as-code/bicep/modules/policy/assignments/alzDefaults/alzDefaultPolicyAssignments.bicep -parameterFile .\infra-as-code\bicep\modules\policy\assignments\alzDefaults\alzDefaultPolicyAssignments.parameters.example.json -parTopLevelManagementGroupPrefix $(ManagementGroupPrefix) -parLogAnalyticsWorkSpaceAndAutomationAccountLocation $(Location) -parLogAnalyticsWorkspaceResourceID "/subscriptions/$(subscriptionId)/resourceGroups/$(ResourceGroupName)/providers/Microsoft.OperationalInsights/workspaces/alz-log-analytics" -parDdosProtectionPlanId "/subscriptions/$(subscriptionId)/resourceGroups/$(ResourceGroupName)/providers/Microsoft.Network/ddosProtectionPlans/alz-Ddos-Plan"'
azurePowerShellVersion: 'LatestVersion'
pwsh: true

- task: Bash@3
displayName: Az CLI Deploy Hub Networking for PR
name: create_hub_network
Expand Down