Skip to content

Commit

Permalink
Merge branch 'main' into 1052-deploy_diagnostics_for_mg
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-FFFFFF authored Aug 29, 2024
2 parents fe4066b + 5d87ff9 commit c14d583
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 89 deletions.
4 changes: 2 additions & 2 deletions docs/wiki/_Sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@
[wiki_deploy_management_resources]: %5BExamples%5D-Deploy-Management-Resources "Wiki - Deploy management resources"
[wiki_deploy_management_resources_custom]: %5BExamples%5D-Deploy-Management-Resources-With-Custom-Settings "Wiki - Deploy management resources with custom settings"
[wiki_deploy_connectivity_resources]: %5BExamples%5D-Deploy-Connectivity-Resources "Wiki - Deploy connectivity resources (Hub and Spoke)"
[wiki_deploy_connectivity_resources_custom]: %5BExamples%5D-Deploy-Connectivity-Resources-With-Custom-Settings "Wiki - Deploy connectivity resources with custom settings (Hub and Spoke)"
[wiki_deploy_connectivity_resources_custom]: %5BExamples%5D-Deploy-Multi-Region-Networking-With-Custom-Settings "Wiki - Deploy multi region networking with custom settings (Hub and Spoke)"
[wiki_deploy_virtual_wan_resources]: %5BExamples%5D-Deploy-Virtual-WAN-Resources "Wiki - Deploy connectivity resources (Virtual WAN)"
[wiki_deploy_virtual_wan_resources_custom]: %5BExamples%5D-Deploy-Virtual-WAN-Resources-With-Custom-Settings "Wiki - Deploy connectivity resources with custom settings (Virtual WAN)"
[wiki_deploy_virtual_wan_resources_custom]: %5BExamples%5D-Deploy-Virtual-WAN-Multi-Region-With-Custom-Settings "Wiki - Deploy multi region networking with custom settings (Virtual WAN)"
[wiki_deploy_identity_resources]: %5BExamples%5D-Deploy-Identity-Resources "Wiki - Deploy identity resources"
[wiki_deploy_identity_resources_custom]: %5BExamples%5D-Deploy-Identity-Resources-With-Custom-Settings "Wiki - Deploy identity resources with custom settings"
[wiki_deploy_using_module_nesting]: %5BExamples%5D-Deploy-Using-Module-Nesting "Wiki - Deploy using module nesting"
Expand Down
173 changes: 86 additions & 87 deletions tests/scripts/azp-strategy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ Write-Information "==> Generating Azure Pipelines Strategy Matrix..." -Informati

$jsonDepth = 4
$terraformUrl = "https://api.github.com/repos/hashicorp/terraform/tags"
$azurermProviderUrl = "https://registry.terraform.io/v1/providers/hashicorp/azurerm"

function Get-RandomId {
[CmdletBinding()]
[OutputType([String])]
param (
[Int]$Length = 8
)
return -join ((48..57) + (97..122) | Get-Random -Count $Length | ForEach-Object { [char]$_ })
[CmdletBinding()]
[OutputType([String])]
param (
[Int]$Length = 8
)
return -join ((48..57) + (97..122) | Get-Random -Count $Length | ForEach-Object { [char]$_ })
}

########################################
Expand All @@ -56,88 +55,88 @@ $terraformVersionsCount = $terraformVersions.Count
#######################################

$azurermProviderVersionBase = "3.107.0"
$azurermProviderVersionLatest = (Invoke-RestMethod -Method Get -Uri $azurermProviderUrl).version
$azurermProviderVersionLatest = "3.116.0"

#######################################
# Generate Subscription Aliases
#######################################

Write-Information "==> Checking for `"Az.Accounts`" PowerShell module..." -InformationAction Continue
if ((Get-Module -ListAvailable "Az.Accounts").Count -eq 0) {
Install-Module -Name "Az.Accounts" -Force
Install-Module -Name "Az.Accounts" -Force
}
Import-Module -Name "Az.Accounts" -Force

Write-Information "==> Getting Subscription Aliases..." -InformationAction Continue

Write-Verbose "Switching Azure Context using Client ID [$($env:ARM_CLIENT_ID)]."
$Credential = New-Object System.Management.Automation.PSCredential (
$($env:ARM_CLIENT_ID),
$($env:ARM_CLIENT_SECRET | ConvertTo-SecureString -AsPlainText -Force)
$($env:ARM_CLIENT_ID),
$($env:ARM_CLIENT_SECRET | ConvertTo-SecureString -AsPlainText -Force)
)
$ctx = Connect-AzAccount `
-ServicePrincipal `
-Tenant $($env:ARM_TENANT_ID) `
-SubscriptionId $($env:ARM_SUBSCRIPTION_ID) `
-Credential $Credential `
-WarningAction SilentlyContinue
-ServicePrincipal `
-Tenant $($env:ARM_TENANT_ID) `
-SubscriptionId $($env:ARM_SUBSCRIPTION_ID) `
-Credential $Credential `
-WarningAction SilentlyContinue

Write-Information " Successfully authenticated account ($($ctx.Context.Account.Id))." -InformationAction Continue

Write-Verbose "Checking for Management Subscription Aliases."
$subscriptionAliasesManagement = [PSCustomObject]@{}
for ($i = 1; $i -lt (($terraformVersionsCount * 2) + 1); $i++) {
$alias = "csu-tf-management-$i"
$aliasesApiVersion = "2020-09-01"
$requestPath = "/providers/Microsoft.Subscription/aliases/$($alias)?api-version=$($aliasesApiVersion)"
$requestMethod = "PUT"
$requestBody = @{
properties = @{
displayName = $alias
billingScope = $($env:BILLING_SCOPE)
workload = "Production"
}
} | ConvertTo-Json -Depth 10
$aliasResponse = Invoke-AzRestMethod -Method $requestMethod -Path $requestPath -Payload $requestBody
if ($aliasResponse.StatusCode -eq "200") {
$subscriptionId = ($aliasResponse.Content | ConvertFrom-Json).properties.subscriptionId
Write-Information " Found Subscription Alias ($($alias)) ($($subscriptionId))." -InformationAction Continue
$alias = "csu-tf-management-$i"
$aliasesApiVersion = "2020-09-01"
$requestPath = "/providers/Microsoft.Subscription/aliases/$($alias)?api-version=$($aliasesApiVersion)"
$requestMethod = "PUT"
$requestBody = @{
properties = @{
displayName = $alias
billingScope = $($env:BILLING_SCOPE)
workload = "Production"
}
else {
Write-Warning "Unable to find Subscription Alias ($($alias)). Failing back to current Subscription context ($($env:ARM_SUBSCRIPTION_ID))."
$subscriptionId = $env:ARM_SUBSCRIPTION_ID
}
$subscriptionAliasesManagement | Add-Member `
-NotePropertyName "$alias" `
-NotePropertyValue "$subscriptionId"
} | ConvertTo-Json -Depth 10
$aliasResponse = Invoke-AzRestMethod -Method $requestMethod -Path $requestPath -Payload $requestBody
if ($aliasResponse.StatusCode -eq "200") {
$subscriptionId = ($aliasResponse.Content | ConvertFrom-Json).properties.subscriptionId
Write-Information " Found Subscription Alias ($($alias)) ($($subscriptionId))." -InformationAction Continue
}
else {
Write-Warning "Unable to find Subscription Alias ($($alias)). Failing back to current Subscription context ($($env:ARM_SUBSCRIPTION_ID))."
$subscriptionId = $env:ARM_SUBSCRIPTION_ID
}
$subscriptionAliasesManagement | Add-Member `
-NotePropertyName "$alias" `
-NotePropertyValue "$subscriptionId"
}

Write-Verbose "Checking for Connectivity Subscription Aliases."
$subscriptionAliasesConnectivity = [PSCustomObject]@{}
for ($i = 1; $i -lt (($terraformVersionsCount * 2) + 1); $i++) {
$alias = "csu-tf-connectivity-$i"
$aliasesApiVersion = "2020-09-01"
$requestPath = "/providers/Microsoft.Subscription/aliases/$($alias)?api-version=$($aliasesApiVersion)"
$requestMethod = "PUT"
$requestBody = @{
properties = @{
displayName = $alias
billingScope = $($env:BILLING_SCOPE)
workload = "Production"
}
} | ConvertTo-Json -Depth 10
$aliasResponse = Invoke-AzRestMethod -Method $requestMethod -Path $requestPath -Payload $requestBody
if ($aliasResponse.StatusCode -eq "200") {
$subscriptionId = ($aliasResponse.Content | ConvertFrom-Json).properties.subscriptionId
Write-Information " Found Subscription Alias ($($alias)) ($($subscriptionId))." -InformationAction Continue
}
else {
Write-Warning "Unable to find Subscription Alias ($($alias)). Failing back to current Subscription context ($($env:ARM_SUBSCRIPTION_ID))."
$subscriptionId = $env:ARM_SUBSCRIPTION_ID
$alias = "csu-tf-connectivity-$i"
$aliasesApiVersion = "2020-09-01"
$requestPath = "/providers/Microsoft.Subscription/aliases/$($alias)?api-version=$($aliasesApiVersion)"
$requestMethod = "PUT"
$requestBody = @{
properties = @{
displayName = $alias
billingScope = $($env:BILLING_SCOPE)
workload = "Production"
}
$subscriptionAliasesConnectivity | Add-Member `
-NotePropertyName "$alias" `
-NotePropertyValue "$subscriptionId"
} | ConvertTo-Json -Depth 10
$aliasResponse = Invoke-AzRestMethod -Method $requestMethod -Path $requestPath -Payload $requestBody
if ($aliasResponse.StatusCode -eq "200") {
$subscriptionId = ($aliasResponse.Content | ConvertFrom-Json).properties.subscriptionId
Write-Information " Found Subscription Alias ($($alias)) ($($subscriptionId))." -InformationAction Continue
}
else {
Write-Warning "Unable to find Subscription Alias ($($alias)). Failing back to current Subscription context ($($env:ARM_SUBSCRIPTION_ID))."
$subscriptionId = $env:ARM_SUBSCRIPTION_ID
}
$subscriptionAliasesConnectivity | Add-Member `
-NotePropertyName "$alias" `
-NotePropertyValue "$subscriptionId"
}

#############################################################################
Expand All @@ -148,33 +147,33 @@ Write-Information "==> Building Strategy Matrix..." -InformationAction Continue

$matrixObject = [PSCustomObject]@{}
for ($i = 0; $i -lt $terraformVersionsCount; $i++) {
$terraformVersion = $terraformVersions[$i]
$jobId1 = ($i * 2) + 1
$jobId2 = ($i * 2) + 2
$jobName1 = "$jobId1. (TF: $terraformVersion, AZ: $azurermProviderVersionBase)"
$jobName2 = "$jobId2. (TF: $terraformVersion, AZ: $azurermProviderVersionLatest)"
$matrixObject | Add-Member `
-NotePropertyName $jobName1 `
-NotePropertyValue @{
TF_ROOT_ID = Get-RandomId
TF_VERSION = $terraformVersion
TF_AZ_VERSION = $azurermProviderVersionBase
TF_JOB_ID = $jobId1
TF_SUBSCRIPTION_ID_MANAGEMENT = ($subscriptionAliasesManagement."csu-tf-management-$jobId1")
TF_SUBSCRIPTION_ID_CONNECTIVITY = ($subscriptionAliasesConnectivity."csu-tf-connectivity-$jobId1")
}
Write-Information " Added job to matrix ($($jobName1))." -InformationAction Continue
$matrixObject | Add-Member `
-NotePropertyName $jobName2 `
-NotePropertyValue @{
TF_ROOT_ID = Get-RandomId
TF_VERSION = $terraformVersion
TF_AZ_VERSION = $azurermProviderVersionLatest
TF_JOB_ID = $jobId2
TF_SUBSCRIPTION_ID_MANAGEMENT = ($subscriptionAliasesManagement."csu-tf-management-$jobId2")
TF_SUBSCRIPTION_ID_CONNECTIVITY = ($subscriptionAliasesConnectivity."csu-tf-connectivity-$jobId2")
}
Write-Information " Added job to matrix ($($jobName2))." -InformationAction Continue
$terraformVersion = $terraformVersions[$i]
$jobId1 = ($i * 2) + 1
$jobId2 = ($i * 2) + 2
$jobName1 = "$jobId1. (TF: $terraformVersion, AZ: $azurermProviderVersionBase)"
$jobName2 = "$jobId2. (TF: $terraformVersion, AZ: $azurermProviderVersionLatest)"
$matrixObject | Add-Member `
-NotePropertyName $jobName1 `
-NotePropertyValue @{
TF_ROOT_ID = Get-RandomId
TF_VERSION = $terraformVersion
TF_AZ_VERSION = $azurermProviderVersionBase
TF_JOB_ID = $jobId1
TF_SUBSCRIPTION_ID_MANAGEMENT = ($subscriptionAliasesManagement."csu-tf-management-$jobId1")
TF_SUBSCRIPTION_ID_CONNECTIVITY = ($subscriptionAliasesConnectivity."csu-tf-connectivity-$jobId1")
}
Write-Information " Added job to matrix ($($jobName1))." -InformationAction Continue
$matrixObject | Add-Member `
-NotePropertyName $jobName2 `
-NotePropertyValue @{
TF_ROOT_ID = Get-RandomId
TF_VERSION = $terraformVersion
TF_AZ_VERSION = $azurermProviderVersionLatest
TF_JOB_ID = $jobId2
TF_SUBSCRIPTION_ID_MANAGEMENT = ($subscriptionAliasesManagement."csu-tf-management-$jobId2")
TF_SUBSCRIPTION_ID_CONNECTIVITY = ($subscriptionAliasesConnectivity."csu-tf-connectivity-$jobId2")
}
Write-Information " Added job to matrix ($($jobName2))." -InformationAction Continue
}

# Convert PSCustomObject to JSON.
Expand Down

0 comments on commit c14d583

Please sign in to comment.