Skip to content

Commit 3a77d8c

Browse files
authored
Update API Version Handling (#844)
1 parent 5ffd9f3 commit 3a77d8c

File tree

25 files changed

+36
-27
lines changed

25 files changed

+36
-27
lines changed

src/internal/functions/ConvertTo-AzOpsState.ps1

+12-3
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,19 @@
222222
($Script:AzOpsResourceProvider | Where-Object { $_.ProviderNamespace -eq $providerNamespace }) -and
223223
(($Script:AzOpsResourceProvider | Where-Object { $_.ProviderNamespace -eq $providerNamespace }).ResourceTypes | Where-Object { $_.ResourceTypeName -eq $resourceApiTypeName })
224224
) {
225-
$apiVersions = (($Script:AzOpsResourceProvider | Where-Object { $_.ProviderNamespace -eq $providerNamespace }).ResourceTypes | Where-Object { $_.ResourceTypeName -eq $resourceApiTypeName }).ApiVersions[0]
226-
Write-PSFMessage -Level Verbose -String 'ConvertTo-AzOpsState.GenerateTemplate.ApiVersion' -StringValues $resourceType, $apiVersions -FunctionName 'ConvertTo-AzOpsState'
225+
$apiVersions = (($Script:AzOpsResourceProvider | Where-Object { $_.ProviderNamespace -eq $providerNamespace }).ResourceTypes | Where-Object { $_.ResourceTypeName -eq $resourceApiTypeName }).ApiVersions
227226

228-
$object.resources[0].apiVersion = $apiVersions
227+
# Handle GA/Preview API versions
228+
$gaApiVersion = $apiVersions | Where-Object {$_ -match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'} | Sort-Object -Descending
229+
$preApiVersion = $apiVersions | Where-Object {$_ -notmatch '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'} | Sort-Object -Descending
230+
231+
if ($null -eq $gaApiVersion) {
232+
$apiVersion = $preApiVersion | Select-Object -First 1
233+
} else {
234+
$apiVersion = $gaApiVersion | Select-Object -First 1
235+
}
236+
Write-PSFMessage -Level Verbose -String 'ConvertTo-AzOpsState.GenerateTemplate.ApiVersion' -StringValues $resourceType, $apiVersion -FunctionName 'ConvertTo-AzOpsState'
237+
$object.resources[0].apiVersion = $apiVersion
229238
$object.resources[0].type = $resourceType
230239
}
231240
else {

src/tests/functional/Microsoft.Authorization/policyAssignments/scenario.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Describe "Scenario - policyAssignments" {
6767
$script:fileContents.resources[0].name | Should -BeTrue
6868
}
6969
It "Resource apiVersion should exist" {
70-
$script:fileContents.resources[0].apiVersion | Should -BeTrue
70+
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
7171
}
7272
It "Resource properties should exist" {
7373
$script:fileContents.resources[0].properties | Should -BeTrue

src/tests/functional/Microsoft.Authorization/roleAssignments/scenario.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Describe "Scenario - roleAssignments" {
6767
$script:fileContents.resources[0].name | Should -BeTrue
6868
}
6969
It "Resource apiVersion should exist" {
70-
$script:fileContents.resources[0].apiVersion | Should -BeTrue
70+
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
7171
}
7272
It "Resource properties should exist" {
7373
$script:fileContents.resources[0].properties | Should -BeTrue

src/tests/functional/Microsoft.Authorization/roleEligibilityScheduleRequests/scenario.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Describe "Scenario - roleEligibilityScheduleRequests" {
5757
$script:fileContents.resources[0].name | Should -BeTrue
5858
}
5959
It "Resource apiVersion should exist" {
60-
$script:fileContents.resources[0].apiVersion | Should -BeTrue
60+
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
6161
}
6262
It "Resource properties should exist" {
6363
$script:fileContents.resources[0].properties | Should -BeTrue

src/tests/functional/Microsoft.Compute/virtualMachines/scenario.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Describe "Scenario - virtualMachines" {
5555
$script:fileContents.resources[0].location | Should -BeTrue
5656
}
5757
It "Resource apiVersion should exist" {
58-
$script:fileContents.resources[0].apiVersion | Should -BeTrue
58+
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
5959
}
6060
It "Resource zones should exist" {
6161
$script:fileContents.resources[0].zones | Should -BeTrue

src/tests/functional/Microsoft.Insights/activityLogAlerts/scenario.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Describe "Scenario - activityLogAlerts" {
5252
$script:fileContents.resources[0].name | Should -BeTrue
5353
}
5454
It "Resource apiVersion should exist" {
55-
$script:fileContents.resources[0].apiVersion | Should -BeTrue
55+
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
5656
}
5757
It "Resource action group Id should exist" {
5858
$script:fileContents.resources[0].properties.actions.actionGroups.actionGroupId | Should -BeTrue

src/tests/functional/Microsoft.KeyVault/vaults/scenario.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Describe "Scenario - vaults" {
5252
$script:fileContents.resources[0].name | Should -BeTrue
5353
}
5454
It "Resource apiVersion should exist" {
55-
$script:fileContents.resources[0].apiVersion | Should -BeTrue
55+
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
5656
}
5757
It "Resource properties should exist" {
5858
$script:fileContents.resources[0].properties | Should -BeTrue

src/tests/functional/Microsoft.Logic/workflows/scenario.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Describe "Scenario - workflows" {
5252
$script:fileContents.resources[0].name | Should -BeTrue
5353
}
5454
It "Resource apiVersion should exist" {
55-
$script:fileContents.resources[0].apiVersion | Should -BeTrue
55+
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
5656
}
5757
It "Resource type should match" {
5858
$script:fileContents.resources[0].type | Should -Be "$script:resourceProvider/$script:resourceType"

src/tests/functional/Microsoft.ManagedIdentity/userAssignedIdentities/scenario.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Describe "Scenario - userAssignedIdentities" {
5252
$script:fileContents.resources[0].name | Should -BeTrue
5353
}
5454
It "Resource apiVersion should exist" {
55-
$script:fileContents.resources[0].apiVersion | Should -BeTrue
55+
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
5656
}
5757
It "Resource location should exist" {
5858
$script:fileContents.resources[0].location | Should -BeTrue

src/tests/functional/Microsoft.Management/managementGroups/scenario.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Describe "Scenario - managementGroups" {
5252
$script:fileContents.resources[0].name | Should -BeTrue
5353
}
5454
It "Resource apiVersion should exist" {
55-
$script:fileContents.resources[0].apiVersion | Should -BeTrue
55+
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
5656
}
5757
It "Resource properties should exist" {
5858
$script:fileContents.resources[0].properties | Should -BeTrue

src/tests/functional/Microsoft.Network/azureFirewalls/scenario.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Describe "Scenario - azureFirewalls" {
5252
$script:fileContents.resources[0].name | Should -BeTrue
5353
}
5454
It "Resource apiVersion should exist" {
55-
$script:fileContents.resources[0].apiVersion | Should -BeTrue
55+
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
5656
}
5757
It "Resource zones should exist" {
5858
$script:fileContents.resources[0].zones | Should -BeTrue

src/tests/functional/Microsoft.Network/bastionHosts/scenario.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Describe "Scenario - bastionHosts" {
5252
$script:fileContents.resources[0].name | Should -BeTrue
5353
}
5454
It "Resource apiVersion should exist" {
55-
$script:fileContents.resources[0].apiVersion | Should -BeTrue
55+
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
5656
}
5757
It "Resource properties should exist" {
5858
$script:fileContents.resources[0].properties | Should -BeTrue

src/tests/functional/Microsoft.Network/connections/scenario.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Describe "Scenario - connections" {
5252
$script:fileContents.resources[0].name | Should -BeTrue
5353
}
5454
It "Resource apiVersion should exist" {
55-
$script:fileContents.resources[0].apiVersion | Should -BeTrue
55+
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
5656
}
5757
It "Resource properties should exist" {
5858
$script:fileContents.resources[0].properties | Should -BeTrue

src/tests/functional/Microsoft.Network/localNetworkGateways/scenario.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Describe "Scenario - localNetworkGateways" {
5252
$script:fileContents.resources[0].name | Should -BeTrue
5353
}
5454
It "Resource apiVersion should exist" {
55-
$script:fileContents.resources[0].apiVersion | Should -BeTrue
55+
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
5656
}
5757
It "Resource properties should exist" {
5858
$script:fileContents.resources[0].properties | Should -BeTrue

src/tests/functional/Microsoft.Network/networkInterfaces/scenario.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Describe "Scenario - networkInterfaces" {
5252
$script:fileContents.resources[0].name | Should -BeTrue
5353
}
5454
It "Resource apiVersion should exist" {
55-
$script:fileContents.resources[0].apiVersion | Should -BeTrue
55+
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
5656
}
5757
It "Resource properties should exist" {
5858
$script:fileContents.resources[0].properties | Should -BeTrue

src/tests/functional/Microsoft.Network/networkSecurityGroups/scenario.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Describe "Scenario - networkSecurityGroups" {
5252
$script:fileContents.resources[0].name | Should -BeTrue
5353
}
5454
It "Resource apiVersion should exist" {
55-
$script:fileContents.resources[0].apiVersion | Should -BeTrue
55+
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
5656
}
5757
It "Resource properties should exist" {
5858
$script:fileContents.resources[0].properties | Should -BeTrue

src/tests/functional/Microsoft.Network/privateDnsZones/scenario.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Describe "Scenario - privateDnsZones" {
5252
$script:fileContents.resources[0].name | Should -BeTrue
5353
}
5454
It "Resource apiVersion should exist" {
55-
$script:fileContents.resources[0].apiVersion | Should -BeTrue
55+
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
5656
}
5757
It "Resource type should match" {
5858
$script:fileContents.resources[0].type | Should -Be "$script:resourceProvider/$script:resourceType"

src/tests/functional/Microsoft.Network/privateEndpoints/scenario.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Describe "Scenario - privateEndpoints" {
5252
$script:fileContents.resources[0].name | Should -BeTrue
5353
}
5454
It "Resource apiVersion should exist" {
55-
$script:fileContents.resources[0].apiVersion | Should -BeTrue
55+
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
5656
}
5757
It "Resource type should match" {
5858
$script:fileContents.resources[0].type | Should -Be "$script:resourceProvider/$script:resourceType"

src/tests/functional/Microsoft.Network/publicIPAddresses/scenario.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Describe "Scenario - publicIPAddresses" {
5252
$script:fileContents.resources[0].name | Should -BeTrue
5353
}
5454
It "Resource apiVersion should exist" {
55-
$script:fileContents.resources[0].apiVersion | Should -BeTrue
55+
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
5656
}
5757
It "Resource properties should exist" {
5858
$script:fileContents.resources[0].properties | Should -BeTrue

src/tests/functional/Microsoft.Network/routeTables/scenario.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Describe "Scenario - routeTables" {
5252
$script:fileContents.resources[0].name | Should -BeTrue
5353
}
5454
It "Resource apiVersion should exist" {
55-
$script:fileContents.resources[0].apiVersion | Should -BeTrue
55+
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
5656
}
5757
It "Resource properties should exist" {
5858
$script:fileContents.resources[0].properties | Should -BeTrue

src/tests/functional/Microsoft.Network/virtualNetworks/scenario.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Describe "Scenario - virtualNetworks" {
5252
$script:fileContents.resources[0].name | Should -BeTrue
5353
}
5454
It "Resource apiVersion should exist" {
55-
$script:fileContents.resources[0].apiVersion | Should -BeTrue
55+
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
5656
}
5757
It "Resource properties should exist" {
5858
$script:fileContents.resources[0].properties | Should -BeTrue

src/tests/functional/Microsoft.Resources/resourceGroups/scenario.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Describe "Scenario - resourceGroups" {
5252
$script:fileContents.resources[0].name | Should -BeTrue
5353
}
5454
It "Resource apiVersion should exist" {
55-
$script:fileContents.resources[0].apiVersion | Should -BeTrue
55+
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
5656
}
5757
It "Resource properties should exist" {
5858
$script:fileContents.resources[0].properties | Should -BeTrue

src/tests/functional/Microsoft.Storage/storageAccounts/scenario.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Describe "Scenario - storageAccounts" {
5252
$script:fileContents.resources[0].name | Should -BeTrue
5353
}
5454
It "Resource apiVersion should exist" {
55-
$script:fileContents.resources[0].apiVersion | Should -BeTrue
55+
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
5656
}
5757
It "Resource properties should exist" {
5858
$script:fileContents.resources[0].properties | Should -BeTrue

src/tests/functional/Microsoft.Web/serverfarms/scenario.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Describe "Scenario - serverfarms" {
5252
$script:fileContents.resources[0].name | Should -BeTrue
5353
}
5454
It "Resource apiVersion should exist" {
55-
$script:fileContents.resources[0].apiVersion | Should -BeTrue
55+
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
5656
}
5757
It "Resource properties should exist" {
5858
$script:fileContents.resources[0].properties | Should -BeTrue

src/tests/functional/Microsoft.Web/sites/scenario.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Describe "Scenario - sites" {
5252
$script:fileContents.resources[0].name | Should -BeTrue
5353
}
5454
It "Resource apiVersion should exist" {
55-
$script:fileContents.resources[0].apiVersion | Should -BeTrue
55+
$script:fileContents.resources[0].apiVersion | Should -Match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'
5656
}
5757
It "Resource properties should exist" {
5858
$script:fileContents.resources[0].properties | Should -BeTrue

0 commit comments

Comments
 (0)