Skip to content

Commit

Permalink
sort and handle resources with only one api version in the array
Browse files Browse the repository at this point in the history
  • Loading branch information
daltondhcp committed Jan 5, 2024
1 parent f23640e commit cfef175
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/internal/functions/ConvertTo-AzOpsState.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cfef175

Please sign in to comment.