diff --git a/src/internal/functions/ConvertTo-AzOpsState.ps1 b/src/internal/functions/ConvertTo-AzOpsState.ps1 index b8cf5cf..dbb6957 100644 --- a/src/internal/functions/ConvertTo-AzOpsState.ps1 +++ b/src/internal/functions/ConvertTo-AzOpsState.ps1 @@ -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 { diff --git a/src/tests/functional/Microsoft.Authorization/policyAssignments/scenario.ps1 b/src/tests/functional/Microsoft.Authorization/policyAssignments/scenario.ps1 index 78169c5..5e3458c 100644 --- a/src/tests/functional/Microsoft.Authorization/policyAssignments/scenario.ps1 +++ b/src/tests/functional/Microsoft.Authorization/policyAssignments/scenario.ps1 @@ -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 diff --git a/src/tests/functional/Microsoft.Authorization/roleAssignments/scenario.ps1 b/src/tests/functional/Microsoft.Authorization/roleAssignments/scenario.ps1 index faada35..a30d231 100644 --- a/src/tests/functional/Microsoft.Authorization/roleAssignments/scenario.ps1 +++ b/src/tests/functional/Microsoft.Authorization/roleAssignments/scenario.ps1 @@ -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 diff --git a/src/tests/functional/Microsoft.Authorization/roleEligibilityScheduleRequests/scenario.ps1 b/src/tests/functional/Microsoft.Authorization/roleEligibilityScheduleRequests/scenario.ps1 index e2b6109..2e466c9 100644 --- a/src/tests/functional/Microsoft.Authorization/roleEligibilityScheduleRequests/scenario.ps1 +++ b/src/tests/functional/Microsoft.Authorization/roleEligibilityScheduleRequests/scenario.ps1 @@ -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 diff --git a/src/tests/functional/Microsoft.Compute/virtualMachines/scenario.ps1 b/src/tests/functional/Microsoft.Compute/virtualMachines/scenario.ps1 index 9ec4b29..88c6bc0 100644 --- a/src/tests/functional/Microsoft.Compute/virtualMachines/scenario.ps1 +++ b/src/tests/functional/Microsoft.Compute/virtualMachines/scenario.ps1 @@ -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 diff --git a/src/tests/functional/Microsoft.Insights/activityLogAlerts/scenario.ps1 b/src/tests/functional/Microsoft.Insights/activityLogAlerts/scenario.ps1 index 5f7fe9e..5fcf822 100644 --- a/src/tests/functional/Microsoft.Insights/activityLogAlerts/scenario.ps1 +++ b/src/tests/functional/Microsoft.Insights/activityLogAlerts/scenario.ps1 @@ -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 diff --git a/src/tests/functional/Microsoft.KeyVault/vaults/scenario.ps1 b/src/tests/functional/Microsoft.KeyVault/vaults/scenario.ps1 index 90888ad..56fa622 100644 --- a/src/tests/functional/Microsoft.KeyVault/vaults/scenario.ps1 +++ b/src/tests/functional/Microsoft.KeyVault/vaults/scenario.ps1 @@ -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 diff --git a/src/tests/functional/Microsoft.Logic/workflows/scenario.ps1 b/src/tests/functional/Microsoft.Logic/workflows/scenario.ps1 index 5d86546..da07a14 100644 --- a/src/tests/functional/Microsoft.Logic/workflows/scenario.ps1 +++ b/src/tests/functional/Microsoft.Logic/workflows/scenario.ps1 @@ -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" diff --git a/src/tests/functional/Microsoft.ManagedIdentity/userAssignedIdentities/scenario.ps1 b/src/tests/functional/Microsoft.ManagedIdentity/userAssignedIdentities/scenario.ps1 index bb6fd93..8254f73 100644 --- a/src/tests/functional/Microsoft.ManagedIdentity/userAssignedIdentities/scenario.ps1 +++ b/src/tests/functional/Microsoft.ManagedIdentity/userAssignedIdentities/scenario.ps1 @@ -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 diff --git a/src/tests/functional/Microsoft.Management/managementGroups/scenario.ps1 b/src/tests/functional/Microsoft.Management/managementGroups/scenario.ps1 index f3409c9..8db4521 100644 --- a/src/tests/functional/Microsoft.Management/managementGroups/scenario.ps1 +++ b/src/tests/functional/Microsoft.Management/managementGroups/scenario.ps1 @@ -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 diff --git a/src/tests/functional/Microsoft.Network/azureFirewalls/scenario.ps1 b/src/tests/functional/Microsoft.Network/azureFirewalls/scenario.ps1 index e69ed1e..694ab5a 100644 --- a/src/tests/functional/Microsoft.Network/azureFirewalls/scenario.ps1 +++ b/src/tests/functional/Microsoft.Network/azureFirewalls/scenario.ps1 @@ -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 diff --git a/src/tests/functional/Microsoft.Network/bastionHosts/scenario.ps1 b/src/tests/functional/Microsoft.Network/bastionHosts/scenario.ps1 index 3628f3a..e2d1c65 100644 --- a/src/tests/functional/Microsoft.Network/bastionHosts/scenario.ps1 +++ b/src/tests/functional/Microsoft.Network/bastionHosts/scenario.ps1 @@ -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 diff --git a/src/tests/functional/Microsoft.Network/connections/scenario.ps1 b/src/tests/functional/Microsoft.Network/connections/scenario.ps1 index a3d7f88..9b6c201 100644 --- a/src/tests/functional/Microsoft.Network/connections/scenario.ps1 +++ b/src/tests/functional/Microsoft.Network/connections/scenario.ps1 @@ -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 diff --git a/src/tests/functional/Microsoft.Network/localNetworkGateways/scenario.ps1 b/src/tests/functional/Microsoft.Network/localNetworkGateways/scenario.ps1 index 969e0b8..f2e1c67 100644 --- a/src/tests/functional/Microsoft.Network/localNetworkGateways/scenario.ps1 +++ b/src/tests/functional/Microsoft.Network/localNetworkGateways/scenario.ps1 @@ -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 diff --git a/src/tests/functional/Microsoft.Network/networkInterfaces/scenario.ps1 b/src/tests/functional/Microsoft.Network/networkInterfaces/scenario.ps1 index 9a1c8a6..7a67078 100644 --- a/src/tests/functional/Microsoft.Network/networkInterfaces/scenario.ps1 +++ b/src/tests/functional/Microsoft.Network/networkInterfaces/scenario.ps1 @@ -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 diff --git a/src/tests/functional/Microsoft.Network/networkSecurityGroups/scenario.ps1 b/src/tests/functional/Microsoft.Network/networkSecurityGroups/scenario.ps1 index 747e7c6..8a84c74 100644 --- a/src/tests/functional/Microsoft.Network/networkSecurityGroups/scenario.ps1 +++ b/src/tests/functional/Microsoft.Network/networkSecurityGroups/scenario.ps1 @@ -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 diff --git a/src/tests/functional/Microsoft.Network/privateDnsZones/scenario.ps1 b/src/tests/functional/Microsoft.Network/privateDnsZones/scenario.ps1 index 256e715..5caae9a 100644 --- a/src/tests/functional/Microsoft.Network/privateDnsZones/scenario.ps1 +++ b/src/tests/functional/Microsoft.Network/privateDnsZones/scenario.ps1 @@ -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" diff --git a/src/tests/functional/Microsoft.Network/privateEndpoints/scenario.ps1 b/src/tests/functional/Microsoft.Network/privateEndpoints/scenario.ps1 index 2d1e681..abe3947 100644 --- a/src/tests/functional/Microsoft.Network/privateEndpoints/scenario.ps1 +++ b/src/tests/functional/Microsoft.Network/privateEndpoints/scenario.ps1 @@ -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" diff --git a/src/tests/functional/Microsoft.Network/publicIPAddresses/scenario.ps1 b/src/tests/functional/Microsoft.Network/publicIPAddresses/scenario.ps1 index 49ae497..2e9fdcf 100644 --- a/src/tests/functional/Microsoft.Network/publicIPAddresses/scenario.ps1 +++ b/src/tests/functional/Microsoft.Network/publicIPAddresses/scenario.ps1 @@ -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 diff --git a/src/tests/functional/Microsoft.Network/routeTables/scenario.ps1 b/src/tests/functional/Microsoft.Network/routeTables/scenario.ps1 index c9a81dc..0533661 100644 --- a/src/tests/functional/Microsoft.Network/routeTables/scenario.ps1 +++ b/src/tests/functional/Microsoft.Network/routeTables/scenario.ps1 @@ -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 diff --git a/src/tests/functional/Microsoft.Network/virtualNetworks/scenario.ps1 b/src/tests/functional/Microsoft.Network/virtualNetworks/scenario.ps1 index 1ba692b..b46bd5e 100644 --- a/src/tests/functional/Microsoft.Network/virtualNetworks/scenario.ps1 +++ b/src/tests/functional/Microsoft.Network/virtualNetworks/scenario.ps1 @@ -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 diff --git a/src/tests/functional/Microsoft.Resources/resourceGroups/scenario.ps1 b/src/tests/functional/Microsoft.Resources/resourceGroups/scenario.ps1 index b49e07d..d01f3fd 100644 --- a/src/tests/functional/Microsoft.Resources/resourceGroups/scenario.ps1 +++ b/src/tests/functional/Microsoft.Resources/resourceGroups/scenario.ps1 @@ -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 diff --git a/src/tests/functional/Microsoft.Storage/storageAccounts/scenario.ps1 b/src/tests/functional/Microsoft.Storage/storageAccounts/scenario.ps1 index f20811b..e5bd604 100644 --- a/src/tests/functional/Microsoft.Storage/storageAccounts/scenario.ps1 +++ b/src/tests/functional/Microsoft.Storage/storageAccounts/scenario.ps1 @@ -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 diff --git a/src/tests/functional/Microsoft.Web/serverfarms/scenario.ps1 b/src/tests/functional/Microsoft.Web/serverfarms/scenario.ps1 index a39da9f..62cd5d6 100644 --- a/src/tests/functional/Microsoft.Web/serverfarms/scenario.ps1 +++ b/src/tests/functional/Microsoft.Web/serverfarms/scenario.ps1 @@ -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 diff --git a/src/tests/functional/Microsoft.Web/sites/scenario.ps1 b/src/tests/functional/Microsoft.Web/sites/scenario.ps1 index 1df7dab..47bc266 100644 --- a/src/tests/functional/Microsoft.Web/sites/scenario.ps1 +++ b/src/tests/functional/Microsoft.Web/sites/scenario.ps1 @@ -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