From 357b0a7e9aace0c3cfe6702dc204e483e024e9e4 Mon Sep 17 00:00:00 2001 From: Johan Dahlbom Date: Wed, 6 Dec 2023 13:08:35 +0100 Subject: [PATCH 1/7] Update tests.yml --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b6ddb478..0d666667 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -31,7 +31,7 @@ jobs: - name: "Checkout" uses: actions/checkout@v4 with: - ref: ${{github.event.pull_request.head.ref}} + ref: ${{github.event.pull_request.head.sha}} repository: ${{github.event.pull_request.head.repo.full_name}} fetch-depth: 0 @@ -146,4 +146,4 @@ jobs: - name: "Run Environment Cleanup" shell: pwsh run: | - ./src/tests/Pester.ps1 -CleanupEnvironment $true \ No newline at end of file + ./src/tests/Pester.ps1 -CleanupEnvironment $true From dc686e7979111893b62223a66deebabaf685c53f Mon Sep 17 00:00:00 2001 From: Johan Dahlbom Date: Wed, 6 Dec 2023 13:21:30 +0100 Subject: [PATCH 2/7] subonly --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0d666667..8f5b2d93 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -110,7 +110,7 @@ jobs: - name: "Checkout" uses: actions/checkout@v4 with: - ref: ${{github.event.pull_request.head.ref}} + ref: ${{github.event.pull_request.head.sha}} repository: ${{github.event.pull_request.head.repo.full_name}} fetch-depth: 0 From 3a23824f60014049232d214c85dd296b82ee837e Mon Sep 17 00:00:00 2001 From: Johan Dahlbom Date: Thu, 4 Jan 2024 15:50:01 +0000 Subject: [PATCH 3/7] initial commit --- src/internal/functions/ConvertTo-AzOpsState.ps1 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/internal/functions/ConvertTo-AzOpsState.ps1 b/src/internal/functions/ConvertTo-AzOpsState.ps1 index b8cf5cfe..fe4784a1 100644 --- a/src/internal/functions/ConvertTo-AzOpsState.ps1 +++ b/src/internal/functions/ConvertTo-AzOpsState.ps1 @@ -222,10 +222,20 @@ ($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] + $apiVersions = (($Script:AzOpsResourceProvider | Where-Object { $_.ProviderNamespace -eq $providerNamespace }).ResourceTypes | Where-Object { $_.ResourceTypeName -eq $resourceApiTypeName }).ApiVersions Write-PSFMessage -Level Verbose -String 'ConvertTo-AzOpsState.GenerateTemplate.ApiVersion' -StringValues $resourceType, $apiVersions -FunctionName 'ConvertTo-AzOpsState' + + # 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])$'} + $preApiVersion = $apiVersions | Where-Object {$_ -notmatch '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'} - $object.resources[0].apiVersion = $apiVersions + if ($null -eq $gaApiVersion) { + $apiVersion = $preApiVersion[0] + } else { + $apiVersion = $gaApiVersion[0] + } + + $object.resources[0].apiVersion = $apiVersion $object.resources[0].type = $resourceType } else { From e0e221d1557f1ee9516c718e3b94b61a94f98fd7 Mon Sep 17 00:00:00 2001 From: Johan Dahlbom Date: Fri, 5 Jan 2024 06:54:45 +0000 Subject: [PATCH 4/7] update apiversion test to validate non-preview version --- .../Microsoft.Authorization/policyAssignments/scenario.ps1 | 2 +- .../Microsoft.Authorization/roleAssignments/scenario.ps1 | 2 +- .../roleEligibilityScheduleRequests/scenario.ps1 | 2 +- .../functional/Microsoft.Compute/virtualMachines/scenario.ps1 | 2 +- .../Microsoft.Insights/activityLogAlerts/scenario.ps1 | 2 +- src/tests/functional/Microsoft.KeyVault/vaults/scenario.ps1 | 2 +- src/tests/functional/Microsoft.Logic/workflows/scenario.ps1 | 2 +- .../userAssignedIdentities/scenario.ps1 | 2 +- .../Microsoft.Management/managementGroups/scenario.ps1 | 2 +- .../functional/Microsoft.Network/azureFirewalls/scenario.ps1 | 2 +- .../functional/Microsoft.Network/bastionHosts/scenario.ps1 | 2 +- src/tests/functional/Microsoft.Network/connections/scenario.ps1 | 2 +- .../Microsoft.Network/localNetworkGateways/scenario.ps1 | 2 +- .../functional/Microsoft.Network/networkInterfaces/scenario.ps1 | 2 +- .../Microsoft.Network/networkSecurityGroups/scenario.ps1 | 2 +- .../functional/Microsoft.Network/privateDnsZones/scenario.ps1 | 2 +- .../functional/Microsoft.Network/privateEndpoints/scenario.ps1 | 2 +- .../functional/Microsoft.Network/publicIPAddresses/scenario.ps1 | 2 +- src/tests/functional/Microsoft.Network/routeTables/scenario.ps1 | 2 +- .../functional/Microsoft.Network/virtualNetworks/scenario.ps1 | 2 +- .../functional/Microsoft.Resources/resourceGroups/scenario.ps1 | 2 +- .../functional/Microsoft.Storage/storageAccounts/scenario.ps1 | 2 +- src/tests/functional/Microsoft.Web/serverfarms/scenario.ps1 | 2 +- src/tests/functional/Microsoft.Web/sites/scenario.ps1 | 2 +- 24 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/tests/functional/Microsoft.Authorization/policyAssignments/scenario.ps1 b/src/tests/functional/Microsoft.Authorization/policyAssignments/scenario.ps1 index 0b438c66..719b8889 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 28b1f9be..98ad53a8 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 e2b61095..2e466c97 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 99b83c90..1ea53a68 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 5fe0f97f..8179235b 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 b817af2c..86e487ff 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 ca576ee8..029703df 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 dcfa89ae..11482d50 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 7a12f97f..b69bfc11 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 c84aa053..67ca3d00 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 21dc7e17..f852f867 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 78270043..0ffce368 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 24f30a2d..bc79e250 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 17c9530b..9e2d7ec0 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 650421ef..9a49e850 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 8355713d..87c91099 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 e238d89b..4799ef13 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 4bc9c96d..19cd528c 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 49129d4c..3a174378 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 403f93f3..468d788e 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 5cf05c11..e6ed9e8f 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 e802d240..e559ff45 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 f0256984..43f16c4d 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 3c77ba8f..0ab572cc 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 From f23640e3c0b5c1b988e1df865aa39d037361ccd1 Mon Sep 17 00:00:00 2001 From: Johan Dahlbom Date: Fri, 5 Jan 2024 07:28:14 +0000 Subject: [PATCH 5/7] fat fingers --- src/internal/functions/ConvertTo-AzOpsState.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internal/functions/ConvertTo-AzOpsState.ps1 b/src/internal/functions/ConvertTo-AzOpsState.ps1 index fe4784a1..5e8a516f 100644 --- a/src/internal/functions/ConvertTo-AzOpsState.ps1 +++ b/src/internal/functions/ConvertTo-AzOpsState.ps1 @@ -224,7 +224,7 @@ ) { $apiVersions = (($Script:AzOpsResourceProvider | Where-Object { $_.ProviderNamespace -eq $providerNamespace }).ResourceTypes | Where-Object { $_.ResourceTypeName -eq $resourceApiTypeName }).ApiVersions Write-PSFMessage -Level Verbose -String 'ConvertTo-AzOpsState.GenerateTemplate.ApiVersion' -StringValues $resourceType, $apiVersions -FunctionName 'ConvertTo-AzOpsState' - + # 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])$'} $preApiVersion = $apiVersions | Where-Object {$_ -notmatch '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'} From cfef17571ac7b4a5c5102f3af8ce5aa0a1b98fa9 Mon Sep 17 00:00:00 2001 From: Johan Dahlbom Date: Fri, 5 Jan 2024 11:16:57 +0000 Subject: [PATCH 6/7] sort and handle resources with only one api version in the array --- src/internal/functions/ConvertTo-AzOpsState.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/internal/functions/ConvertTo-AzOpsState.ps1 b/src/internal/functions/ConvertTo-AzOpsState.ps1 index 5e8a516f..7c85f1af 100644 --- a/src/internal/functions/ConvertTo-AzOpsState.ps1 +++ b/src/internal/functions/ConvertTo-AzOpsState.ps1 @@ -226,13 +226,13 @@ Write-PSFMessage -Level Verbose -String 'ConvertTo-AzOpsState.GenerateTemplate.ApiVersion' -StringValues $resourceType, $apiVersions -FunctionName 'ConvertTo-AzOpsState' # 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])$'} - $preApiVersion = $apiVersions | Where-Object {$_ -notmatch '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'} + $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[0] + $apiVersion = $preApiVersion | Select-Object -First 1 } else { - $apiVersion = $gaApiVersion[0] + $apiVersion = $gaApiVersion | Select-Object -First 1 } $object.resources[0].apiVersion = $apiVersion From e07c4ca99c671cdd9022a7e1bd69f19706742099 Mon Sep 17 00:00:00 2001 From: Jesper Fajers Date: Tue, 9 Jan 2024 07:19:49 +0100 Subject: [PATCH 7/7] Update --- src/internal/functions/ConvertTo-AzOpsState.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/internal/functions/ConvertTo-AzOpsState.ps1 b/src/internal/functions/ConvertTo-AzOpsState.ps1 index 7c85f1af..dbb69572 100644 --- a/src/internal/functions/ConvertTo-AzOpsState.ps1 +++ b/src/internal/functions/ConvertTo-AzOpsState.ps1 @@ -223,7 +223,6 @@ (($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 - Write-PSFMessage -Level Verbose -String 'ConvertTo-AzOpsState.GenerateTemplate.ApiVersion' -StringValues $resourceType, $apiVersions -FunctionName 'ConvertTo-AzOpsState' # 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 @@ -234,7 +233,7 @@ } 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 }