Skip to content

Commit

Permalink
Update API Version Handling (#844)
Browse files Browse the repository at this point in the history
  • Loading branch information
daltondhcp authored Jan 9, 2024
1 parent 5ffd9f3 commit 3a77d8c
Show file tree
Hide file tree
Showing 25 changed files with 36 additions and 27 deletions.
15 changes: 12 additions & 3 deletions src/internal/functions/ConvertTo-AzOpsState.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,19 @@
($Script:AzOpsResourceProvider | Where-Object { $_.ProviderNamespace -eq $providerNamespace }) -and
(($Script:AzOpsResourceProvider | Where-Object { $_.ProviderNamespace -eq $providerNamespace }).ResourceTypes | Where-Object { $_.ResourceTypeName -eq $resourceApiTypeName })
) {
$apiVersions = (($Script:AzOpsResourceProvider | Where-Object { $_.ProviderNamespace -eq $providerNamespace }).ResourceTypes | Where-Object { $_.ResourceTypeName -eq $resourceApiTypeName }).ApiVersions[0]
Write-PSFMessage -Level Verbose -String 'ConvertTo-AzOpsState.GenerateTemplate.ApiVersion' -StringValues $resourceType, $apiVersions -FunctionName 'ConvertTo-AzOpsState'
$apiVersions = (($Script:AzOpsResourceProvider | Where-Object { $_.ProviderNamespace -eq $providerNamespace }).ResourceTypes | Where-Object { $_.ResourceTypeName -eq $resourceApiTypeName }).ApiVersions

$object.resources[0].apiVersion = $apiVersions
# Handle GA/Preview API versions
$gaApiVersion = $apiVersions | Where-Object {$_ -match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'} | Sort-Object -Descending
$preApiVersion = $apiVersions | Where-Object {$_ -notmatch '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'} | Sort-Object -Descending

if ($null -eq $gaApiVersion) {
$apiVersion = $preApiVersion | Select-Object -First 1
} else {
$apiVersion = $gaApiVersion | Select-Object -First 1
}
Write-PSFMessage -Level Verbose -String 'ConvertTo-AzOpsState.GenerateTemplate.ApiVersion' -StringValues $resourceType, $apiVersion -FunctionName 'ConvertTo-AzOpsState'
$object.resources[0].apiVersion = $apiVersion
$object.resources[0].type = $resourceType
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Describe "Scenario - policyAssignments" {
$script:fileContents.resources[0].name | Should -BeTrue
}
It "Resource apiVersion should exist" {
$script:fileContents.resources[0].apiVersion | Should -BeTrue
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
}
It "Resource properties should exist" {
$script:fileContents.resources[0].properties | Should -BeTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Describe "Scenario - roleAssignments" {
$script:fileContents.resources[0].name | Should -BeTrue
}
It "Resource apiVersion should exist" {
$script:fileContents.resources[0].apiVersion | Should -BeTrue
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
}
It "Resource properties should exist" {
$script:fileContents.resources[0].properties | Should -BeTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Describe "Scenario - roleEligibilityScheduleRequests" {
$script:fileContents.resources[0].name | Should -BeTrue
}
It "Resource apiVersion should exist" {
$script:fileContents.resources[0].apiVersion | Should -BeTrue
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
}
It "Resource properties should exist" {
$script:fileContents.resources[0].properties | Should -BeTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Describe "Scenario - virtualMachines" {
$script:fileContents.resources[0].location | Should -BeTrue
}
It "Resource apiVersion should exist" {
$script:fileContents.resources[0].apiVersion | Should -BeTrue
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
}
It "Resource zones should exist" {
$script:fileContents.resources[0].zones | Should -BeTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Describe "Scenario - activityLogAlerts" {
$script:fileContents.resources[0].name | Should -BeTrue
}
It "Resource apiVersion should exist" {
$script:fileContents.resources[0].apiVersion | Should -BeTrue
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
}
It "Resource action group Id should exist" {
$script:fileContents.resources[0].properties.actions.actionGroups.actionGroupId | Should -BeTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Describe "Scenario - vaults" {
$script:fileContents.resources[0].name | Should -BeTrue
}
It "Resource apiVersion should exist" {
$script:fileContents.resources[0].apiVersion | Should -BeTrue
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
}
It "Resource properties should exist" {
$script:fileContents.resources[0].properties | Should -BeTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Describe "Scenario - workflows" {
$script:fileContents.resources[0].name | Should -BeTrue
}
It "Resource apiVersion should exist" {
$script:fileContents.resources[0].apiVersion | Should -BeTrue
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
}
It "Resource type should match" {
$script:fileContents.resources[0].type | Should -Be "$script:resourceProvider/$script:resourceType"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Describe "Scenario - userAssignedIdentities" {
$script:fileContents.resources[0].name | Should -BeTrue
}
It "Resource apiVersion should exist" {
$script:fileContents.resources[0].apiVersion | Should -BeTrue
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
}
It "Resource location should exist" {
$script:fileContents.resources[0].location | Should -BeTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Describe "Scenario - managementGroups" {
$script:fileContents.resources[0].name | Should -BeTrue
}
It "Resource apiVersion should exist" {
$script:fileContents.resources[0].apiVersion | Should -BeTrue
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
}
It "Resource properties should exist" {
$script:fileContents.resources[0].properties | Should -BeTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Describe "Scenario - azureFirewalls" {
$script:fileContents.resources[0].name | Should -BeTrue
}
It "Resource apiVersion should exist" {
$script:fileContents.resources[0].apiVersion | Should -BeTrue
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
}
It "Resource zones should exist" {
$script:fileContents.resources[0].zones | Should -BeTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Describe "Scenario - bastionHosts" {
$script:fileContents.resources[0].name | Should -BeTrue
}
It "Resource apiVersion should exist" {
$script:fileContents.resources[0].apiVersion | Should -BeTrue
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
}
It "Resource properties should exist" {
$script:fileContents.resources[0].properties | Should -BeTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Describe "Scenario - connections" {
$script:fileContents.resources[0].name | Should -BeTrue
}
It "Resource apiVersion should exist" {
$script:fileContents.resources[0].apiVersion | Should -BeTrue
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
}
It "Resource properties should exist" {
$script:fileContents.resources[0].properties | Should -BeTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Describe "Scenario - localNetworkGateways" {
$script:fileContents.resources[0].name | Should -BeTrue
}
It "Resource apiVersion should exist" {
$script:fileContents.resources[0].apiVersion | Should -BeTrue
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
}
It "Resource properties should exist" {
$script:fileContents.resources[0].properties | Should -BeTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Describe "Scenario - networkInterfaces" {
$script:fileContents.resources[0].name | Should -BeTrue
}
It "Resource apiVersion should exist" {
$script:fileContents.resources[0].apiVersion | Should -BeTrue
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
}
It "Resource properties should exist" {
$script:fileContents.resources[0].properties | Should -BeTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Describe "Scenario - networkSecurityGroups" {
$script:fileContents.resources[0].name | Should -BeTrue
}
It "Resource apiVersion should exist" {
$script:fileContents.resources[0].apiVersion | Should -BeTrue
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
}
It "Resource properties should exist" {
$script:fileContents.resources[0].properties | Should -BeTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Describe "Scenario - privateDnsZones" {
$script:fileContents.resources[0].name | Should -BeTrue
}
It "Resource apiVersion should exist" {
$script:fileContents.resources[0].apiVersion | Should -BeTrue
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
}
It "Resource type should match" {
$script:fileContents.resources[0].type | Should -Be "$script:resourceProvider/$script:resourceType"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Describe "Scenario - privateEndpoints" {
$script:fileContents.resources[0].name | Should -BeTrue
}
It "Resource apiVersion should exist" {
$script:fileContents.resources[0].apiVersion | Should -BeTrue
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
}
It "Resource type should match" {
$script:fileContents.resources[0].type | Should -Be "$script:resourceProvider/$script:resourceType"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Describe "Scenario - publicIPAddresses" {
$script:fileContents.resources[0].name | Should -BeTrue
}
It "Resource apiVersion should exist" {
$script:fileContents.resources[0].apiVersion | Should -BeTrue
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
}
It "Resource properties should exist" {
$script:fileContents.resources[0].properties | Should -BeTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Describe "Scenario - routeTables" {
$script:fileContents.resources[0].name | Should -BeTrue
}
It "Resource apiVersion should exist" {
$script:fileContents.resources[0].apiVersion | Should -BeTrue
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
}
It "Resource properties should exist" {
$script:fileContents.resources[0].properties | Should -BeTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Describe "Scenario - virtualNetworks" {
$script:fileContents.resources[0].name | Should -BeTrue
}
It "Resource apiVersion should exist" {
$script:fileContents.resources[0].apiVersion | Should -BeTrue
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
}
It "Resource properties should exist" {
$script:fileContents.resources[0].properties | Should -BeTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Describe "Scenario - resourceGroups" {
$script:fileContents.resources[0].name | Should -BeTrue
}
It "Resource apiVersion should exist" {
$script:fileContents.resources[0].apiVersion | Should -BeTrue
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
}
It "Resource properties should exist" {
$script:fileContents.resources[0].properties | Should -BeTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Describe "Scenario - storageAccounts" {
$script:fileContents.resources[0].name | Should -BeTrue
}
It "Resource apiVersion should exist" {
$script:fileContents.resources[0].apiVersion | Should -BeTrue
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
}
It "Resource properties should exist" {
$script:fileContents.resources[0].properties | Should -BeTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Describe "Scenario - serverfarms" {
$script:fileContents.resources[0].name | Should -BeTrue
}
It "Resource apiVersion should exist" {
$script:fileContents.resources[0].apiVersion | Should -BeTrue
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
}
It "Resource properties should exist" {
$script:fileContents.resources[0].properties | Should -BeTrue
Expand Down
2 changes: 1 addition & 1 deletion src/tests/functional/Microsoft.Web/sites/scenario.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Describe "Scenario - sites" {
$script:fileContents.resources[0].name | Should -BeTrue
}
It "Resource apiVersion should exist" {
$script:fileContents.resources[0].apiVersion | Should -BeTrue
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
}
It "Resource properties should exist" {
$script:fileContents.resources[0].properties | Should -BeTrue
Expand Down

0 comments on commit 3a77d8c

Please sign in to comment.