Skip to content

Commit 39dcbab

Browse files
authored
upgrade az version to 10, remove fixed version number in extension, breaking changes in cmdlet API (#118)
* upgrade to Az 10.X * fix more * fix test * polish version * polish changelog * fix vscode extension * polish how-to * resolve path ro absolute * update package-lock * polish changelog * psd1 as well * better error handling * add comments for version compare function * bump major version * delete preview announcement since module is already GAed
1 parent 887a099 commit 39dcbab

File tree

108 files changed

+38492
-11087
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+38492
-11087
lines changed

docs/how-to-update-az-module-spec.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ Have the following installed on your system:
5151
.\powershell-module\Scripts\New-AzCmdletSpec.ps1 -AzVersion $azModuleVersion -OutputDirectory (Join-Path -Path (Get-Location) -ChildPath 'powershell-module\Az.Tools.Migration\Resources\ModuleSpecs\Az\'$azModuleVersion)
5252
```
5353

54-
1. Update the Az PowerShell module version listed in documentation, function help, function
55-
parameter validation, and unit tests. The easiest way to do this is to perform a search to find
56-
and replace the previous version. The previous version can be found under `\powershell-module\Az.Tools.Migration\Resources\ModuleSpecs\Az`. For example, search for '5.2.0' and replace with '5.6.0'. Please do not replace all because some files containing previous version, such as changelog, should not be replaced.
57-
5854
1. Remove the old module spec files from module resources:
5955
`powershell-module\Az.Tools.Migration\Resources\ModuleSpecs\Az\{old-version}`.
6056

docs/quickstart-migrate-azurerm-to-az-automatically.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ ms.date: 09/11/2020
1414
In this article, you'll learn how to use the Az.Tools.Migration PowerShell module to automatically
1515
upgrade your PowerShell scripts and script modules from AzureRM to the Az PowerShell module.
1616

17-
> [!IMPORTANT]
18-
> The Az.Tools.Migration PowerShell module is currently in public preview. This preview version is
19-
> provided without a service level agreement. It's not recommended for production workloads. Certain
20-
> features might not be supported or might have constrained capabilities. For more information, see
21-
> [Supplemental Terms of Use for Microsoft Azure Previews](https://azure.microsoft.com/support/legal/preview-supplemental-terms/).
22-
2317
Report feedback and issues about the Az.Tools.Migration PowerShell module via
2418
[a GitHub issue](https://github.com/Azure/azure-powershell-migration/issues) in the
2519
`azure-powershell-migration` repository.
@@ -44,12 +38,12 @@ points that require changes when moving from AzureRM to the Az PowerShell cmdlet
4438
4539
```powershell
4640
# Generate an upgrade plan for the specified PowerShell script and save it to a variable.
47-
$Plan = New-AzUpgradeModulePlan -FromAzureRmVersion 6.13.1 -ToAzVersion 9.3.0 -FilePath 'C:\Scripts\my-azure-script.ps1'
41+
$Plan = New-AzUpgradeModulePlan -FromAzureRmVersion 6.13.1 -ToAzVersion latest -FilePath 'C:\Scripts\my-azure-script.ps1'
4842
```
4943

5044
```powershell
5145
# Generate an upgrade plan for all the scripts and module files in the specified folder and save it to a variable.
52-
$Plan = New-AzUpgradeModulePlan -FromAzureRmVersion 6.13.1 -ToAzVersion 9.3.0 -DirectoryPath 'C:\Scripts'
46+
$Plan = New-AzUpgradeModulePlan -FromAzureRmVersion 6.13.1 -ToAzVersion latest -DirectoryPath 'C:\Scripts'
5347
```
5448

5549
Review the results of the upgrade plan.
@@ -106,7 +100,7 @@ $Results | Where-Object UpgradeResult -ne UpgradeCompleted | Format-List
106100

107101
* File I/O operations use default encoding. Unusual file encoding situations may cause problems.
108102
* AzureRM cmdlets passed as arguments to Pester unit test mock statements aren't detected.
109-
* Currently, only Az PowerShell module version 9.3.0 is supported as a target.
103+
* Currently, only Az PowerShell module version 10.3 is supported as a target.
110104

111105
## Next steps
112106

powershell-module/Az.Tools.Migration/Az.Tools.Migration.psd1

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
RootModule = 'Az.Tools.Migration.psm1'
44

55
# Version number of this module.
6-
ModuleVersion = '1.1.4'
6+
ModuleVersion = '2.0.0'
77

88
# Supported PSEditions
99
CompatiblePSEditions = 'Core', 'Desktop'
@@ -108,7 +108,16 @@
108108
# IconUri = ''
109109

110110
# ReleaseNotes of this module
111-
ReleaseNotes = '* Upgrade Az version to 9.3.0'
111+
ReleaseNotes = "* Supported AzureRM to Az 10.3 migration
112+
* `Get-AzUpgradeAliasSpec`
113+
* Parameter `ModuleVersion` now accept value 'latest' only [BreakingChange]
114+
* `Get-AzUpgradeCmdletSpec`
115+
* Parameter `ModuleName` removed` [BreakingChange]
116+
* Added switch parameters `AzureRM` and `Az`
117+
* Parameter `ModuleVersion` now accept value 'latest' only and has to be used with `Az` [BreakingChange]
118+
* `New-AzUpgradeModulePlan`
119+
* Parameter `ToAzVersion` now accept value 'latest' only [BreakingChange]
120+
* Parameter `FilePath` now accept relative file path"
112121
}
113122
}
114123

powershell-module/Az.Tools.Migration/Functions/Public/Find-AzUpgradeCommandReference.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function Find-AzUpgradeCommandReference
3434
The following example finds AzureRM PowerShell command references in the specified directory and subfolders but with a pre-loaded module specification.
3535
This is helpful to avoid reloading the module specification if the Find-AzUpgradeCommandReference command needs to be executed several times.
3636
37-
$moduleSpec = Get-AzUpgradeCmdletSpec -ModuleName "AzureRM" -ModuleVersion "6.13.1"
37+
$moduleSpec = Get-AzUpgradeCmdletSpec -AzureRM
3838
Find-AzUpgradeCommandReference -DirectoryPath 'C:\Scripts1' -AzureRmModuleSpec $moduleSpec
3939
Find-AzUpgradeCommandReference -DirectoryPath 'C:\Scripts2' -AzureRmModuleSpec $moduleSpec
4040
Find-AzUpgradeCommandReference -DirectoryPath 'C:\Scripts3' -AzureRmModuleSpec $moduleSpec
@@ -92,12 +92,13 @@ function Find-AzUpgradeCommandReference
9292
Process
9393
{
9494
$cmdStarted = Get-Date
95+
$FilePath = (Resolve-Path $FilePath).Path
9596

9697
if ($PSBoundParameters.ContainsKey('AzureRmModuleSpec') -eq $false)
9798
{
9899
# load the command specs
99100
Write-Verbose -Message "Loading cmdlet spec for AzureRM $AzureRmVersion"
100-
$AzureRmModuleSpec = Get-AzUpgradeCmdletSpec -ModuleName "AzureRM" -ModuleVersion $AzureRmVersion
101+
$AzureRmModuleSpec = Get-AzUpgradeCmdletSpec -AzureRM
101102
}
102103
else
103104
{

powershell-module/Az.Tools.Migration/Functions/Public/Get-AzUpgradeAliasSpec.ps1

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ function Get-AzUpgradeAliasSpec
1111
Specify the version of the module to import command aliases from.
1212
1313
.EXAMPLE
14-
PS C:\> Get-AzUpgradeAliasSpec -ModuleVersion "9.3.0"
15-
Returns the cmdlet alias mappings table for Az 9.3.0.
14+
PS C:\> Get-AzUpgradeAliasSpec -ModuleVersion latest
15+
Returns the cmdlet alias mappings table for latest Az version
1616
#>
1717
[CmdletBinding()]
1818
Param
@@ -22,12 +22,16 @@ function Get-AzUpgradeAliasSpec
2222
HelpMessage="Specify the version of the module to import command definitions from.")]
2323
[System.String]
2424
[ValidateNotNullOrEmpty()]
25+
[ValidateSet('latest')]
2526
$ModuleVersion
2627
)
2728
Process
2829
{
29-
$aliasSpecFile = Join-Path -Path $MyInvocation.MyCommand.Module.ModuleBase `
30-
-ChildPath "Resources\ModuleSpecs\Az\$ModuleVersion\CmdletAliases\Aliases.json"
30+
$path = Join-Path -Path $MyInvocation.MyCommand.Module.ModuleBase -ChildPath "\Resources\ModuleSpecs\Az\$ModuleVersion"
31+
$version = Get-ChildItem -Path $path -Name
32+
33+
$aliasSpecFile = Join-Path -Path $path `
34+
-ChildPath "$version\CmdletAliases\Aliases.json"
3135

3236
if ((Test-Path -Path $aliasSpecFile) -eq $false)
3337
{

powershell-module/Az.Tools.Migration/Functions/Public/Get-AzUpgradeCmdletSpec.ps1

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,56 @@ function Get-AzUpgradeCmdletSpec
1414
Specify the version of the module to load command definitions from.
1515
1616
.EXAMPLE
17-
PS C:\> Get-AzUpgradeCmdletSpec -ModuleName "AzureRM" -ModuleVersion "6.13.1"
17+
PS C:\> Get-AzUpgradeCmdletSpec -AzureRM
1818
Returns the dictionary containing cmdlet specification objects for AzureRM 6.13.1.
1919
#>
2020
[CmdletBinding()]
2121
Param
2222
(
2323
[Parameter(
2424
Mandatory=$true,
25-
HelpMessage="Specify the name of the module to import command definitions from.")]
26-
[System.String]
27-
[ValidateNotNullOrEmpty()]
28-
$ModuleName,
25+
ParameterSetName = "AzureRM",
26+
HelpMessage="Import command definitions from AzureRM modules.")]
27+
[System.Management.Automation.SwitchParameter]
28+
$AzureRM,
29+
30+
[Parameter(
31+
Mandatory=$true,
32+
ParameterSetName = "Az",
33+
HelpMessage="Import command definitions from Az modules.")]
34+
[System.Management.Automation.SwitchParameter]
35+
$Az,
2936

3037
[Parameter(
3138
Mandatory=$true,
39+
ParameterSetName = "Az",
3240
HelpMessage="Specify the version of the module to import command definitions from.")]
3341
[System.String]
42+
[ValidateSet('latest')]
3443
[ValidateNotNullOrEmpty()]
3544
$ModuleVersion
3645
)
3746
Process
3847
{
3948
$ModuleSpecFolder = Join-Path -Path $MyInvocation.MyCommand.Module.ModuleBase `
40-
-ChildPath "Resources\ModuleSpecs\$ModuleName\$ModuleVersion"
49+
-ChildPath "Resources\ModuleSpecs"
50+
if ($PSBoundParameters.ContainsKey('AzureRM')) {
51+
$ModuleSpecFolder = Join-Path -Path $ModuleSpecFolder -ChildPath "AzureRM\6.13.1"
52+
} else {
53+
$version = Get-ChildItem -Path "$ModuleSpecFolder/Az/$ModuleVersion" -Name
54+
$ModuleSpecFolder = Join-Path -Path $ModuleSpecFolder -ChildPath "Az\$ModuleVersion\$version"
55+
}
4156

4257
if ((Test-Path -Path $ModuleSpecFolder) -eq $false)
4358
{
44-
throw "No module spec files found for module: $ModuleName $ModuleVersion"
59+
throw "No module spec files found for module: $ModuleName $version under $ModuleSpecFolder"
4560
}
4661

4762
$ModuleSpecFiles = Get-ChildItem -Path $ModuleSpecFolder -File
4863

4964
if ($ModuleSpecFiles -eq $null)
5065
{
51-
throw "No module spec files found for module: $ModuleName $ModuleVersion"
66+
throw "No module spec files found for module: $ModuleName $version under $ModuleSpecFolder"
5267
}
5368

5469
$results = New-Object -TypeName 'System.Collections.Generic.Dictionary[System.String,CommandDefinition]' -ArgumentList (, [System.StringComparer]::OrdinalIgnoreCase)

powershell-module/Az.Tools.Migration/Functions/Public/Invoke-AzUpgradeModulePlan.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function Invoke-AzUpgradeModulePlan
2323
The following example invokes the upgrade plan for a PowerShell module named "myModule" and saves the updated file contents into new files (leaving original files unmodified).
2424
2525
# step 1: generate a plan and save it to a variable.
26-
$plan = New-AzUpgradeModulePlan -FromAzureRmVersion 6.13.1 -ToAzVersion 9.3.0 -DirectoryPath 'C:\Scripts\myModule'
26+
$plan = New-AzUpgradeModulePlan -FromAzureRmVersion 6.13.1 -ToAzVersion latest -DirectoryPath 'C:\Scripts\myModule'
2727
2828
# step 2: write the plan to the console to review the upgrade steps, warnings, and errors.
2929
$plan
@@ -38,7 +38,7 @@ function Invoke-AzUpgradeModulePlan
3838
The following example invokes the upgrade plan for a PowerShell module named "myModule" and modifies the existing files in place.
3939
4040
# step 1: generate a plan and save it to a variable.
41-
$plan = New-AzUpgradeModulePlan -FromAzureRmVersion 6.13.1 -ToAzVersion 9.3.0 -DirectoryPath 'C:\Scripts\myModule'
41+
$plan = New-AzUpgradeModulePlan -FromAzureRmVersion 6.13.1 -ToAzVersion latest -DirectoryPath 'C:\Scripts\myModule'
4242
4343
# step 2: write the plan to the console to review the upgrade steps, warnings, and errors.
4444
$plan

powershell-module/Az.Tools.Migration/Functions/Public/New-AzUpgradeModulePlan.ps1

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function New-AzUpgradeModulePlan
1111
Specifies the AzureRM module version used in your existing PowerShell scripts(s) or modules.
1212
1313
.PARAMETER ToAzVersion
14-
Specifies the Az module version to upgrade to. Currently, only Az version 9.3.0 is supported.
14+
Specifies the Az module version to upgrade to. Currently, only Az version 10.3 is supported.
1515
1616
.PARAMETER FilePath
1717
Specifies the path to a single PowerShell file.
@@ -34,32 +34,32 @@ function New-AzUpgradeModulePlan
3434
.EXAMPLE
3535
The following example generates a new Az module upgrade plan for the script file 'C:\Scripts\my-azure-script.ps1'.
3636
37-
New-AzUpgradeModulePlan -FromAzureRmVersion 6.13.1 -ToAzVersion 9.3.0 -FilePath 'C:\Scripts\my-azure-script.ps1'
37+
New-AzUpgradeModulePlan -FromAzureRmVersion 6.13.1 -ToAzVersion latest -FilePath 'C:\Scripts\my-azure-script.ps1'
3838
3939
.EXAMPLE
4040
The following example generates a new Az module upgrade plan for the script and module files located under C:\Scripts.
4141
42-
New-AzUpgradeModulePlan -FromAzureRmVersion 6.13.1 -ToAzVersion 9.3.0 -DirectoryPath 'C:\Scripts'
42+
New-AzUpgradeModulePlan -FromAzureRmVersion 6.13.1 -ToAzVersion latest -DirectoryPath 'C:\Scripts'
4343
4444
.EXAMPLE
4545
The following example generates a new Az module upgrade plan for the script and module files under C:\Scripts.
4646
4747
$references = Find-AzUpgradeCommandReference -DirectoryPath 'C:\Scripts' -AzureRmVersion '6.13.1'
48-
New-AzUpgradeModulePlan -ToAzVersion 9.3.0 -AzureRmCmdReference $references
48+
New-AzUpgradeModulePlan -ToAzVersion latest -AzureRmCmdReference $references
4949
5050
.EXAMPLE
5151
The following example generates a new Az module upgrade plan for the script and module files under several directories.
5252
Module specs are pre-loaded here to avoid re-loading the spec each time a plan is generated.
5353
5454
# pre-load specifications
55-
$armSpec = Get-AzUpgradeCmdletSpec -ModuleName "AzureRM" -ModuleVersion "6.13.1"
56-
$azSpec = Get-AzUpgradeCmdletSpec -ModuleName "Az" -ModuleVersion "9.3.0"
57-
$azAliases = Get-AzUpgradeAliasSpec -ModuleVersion "9.3.0"
55+
$armSpec = Get-AzUpgradeCmdletSpec -AzureRM
56+
$azSpec = Get-AzUpgradeCmdletSpec -Az -ModuleVersion latest
57+
$azAliases = Get-AzUpgradeAliasSpec -ModuleVersion latest
5858
5959
# execute a batch of module upgrades
60-
$plan1 = New-AzUpgradeModulePlan -DirectoryPath 'C:\Scripts1' -FromAzureRmVersion '6.13.1' -ToAzVersion '9.3.0' -AzureRmModuleSpec $armSpec -AzModuleSpec $azSpec -AzAliasMappingSpec $azAliases
61-
$plan2 = New-AzUpgradeModulePlan -DirectoryPath 'C:\Scripts2' -FromAzureRmVersion '6.13.1' -ToAzVersion '9.3.0' -AzureRmModuleSpec $armSpec -AzModuleSpec $azSpec -AzAliasMappingSpec $azAliases
62-
$plan3 = New-AzUpgradeModulePlan -DirectoryPath 'C:\Scripts3' -FromAzureRmVersion '6.13.1' -ToAzVersion '9.3.0' -AzureRmModuleSpec $armSpec -AzModuleSpec $azSpec -AzAliasMappingSpec $azAliases
60+
$plan1 = New-AzUpgradeModulePlan -DirectoryPath 'C:\Scripts1' -FromAzureRmVersion '6.13.1' -ToAzVersion latest -AzureRmModuleSpec $armSpec -AzModuleSpec $azSpec -AzAliasMappingSpec $azAliases
61+
$plan2 = New-AzUpgradeModulePlan -DirectoryPath 'C:\Scripts2' -FromAzureRmVersion '6.13.1' -ToAzVersion latest -AzureRmModuleSpec $armSpec -AzModuleSpec $azSpec -AzAliasMappingSpec $azAliases
62+
$plan3 = New-AzUpgradeModulePlan -DirectoryPath 'C:\Scripts3' -FromAzureRmVersion '6.13.1' -ToAzVersion latest -AzureRmModuleSpec $armSpec -AzModuleSpec $azSpec -AzAliasMappingSpec $azAliases
6363
#>
6464
[CmdletBinding()]
6565
Param
@@ -103,7 +103,7 @@ function New-AzUpgradeModulePlan
103103
Mandatory=$true,
104104
HelpMessage='Specify the Az module version to upgrade to.')]
105105
[System.String]
106-
[ValidateSet('9.3.0')]
106+
[ValidateSet('latest')]
107107
$ToAzVersion,
108108

109109
[Parameter(Mandatory=$false)]
@@ -122,6 +122,10 @@ function New-AzUpgradeModulePlan
122122
{
123123
$cmdStarted = Get-Date
124124

125+
$FilePath = (Resolve-Path $FilePath).Path
126+
$versionPath = Join-Path -Path $MyInvocation.MyCommand.Module.ModuleBase -ChildPath "\Resources\ModuleSpecs\Az\$ToAzVersion"
127+
$version = Get-ChildItem -Path $versionPath -Name
128+
125129
# if an existing set of command references was not provided
126130
# then call the Find cmdlet to search for those references.
127131

@@ -166,8 +170,9 @@ function New-AzUpgradeModulePlan
166170

167171
if ($PSBoundParameters.ContainsKey('AzModuleSpec') -eq $false)
168172
{
169-
Write-Verbose -Message "Importing cmdlet spec for Az $ToAzVersion"
170-
$AzModuleSpec = Get-AzUpgradeCmdletSpec -ModuleName "Az" -ModuleVersion $ToAzVersion
173+
174+
Write-Verbose -Message "Importing cmdlet spec for Az $version"
175+
$AzModuleSpec = Get-AzUpgradeCmdletSpec -Az -ModuleVersion $ToAzVersion
171176
}
172177
else
173178
{
@@ -176,7 +181,7 @@ function New-AzUpgradeModulePlan
176181

177182
if ($PSBoundParameters.ContainsKey('AzAliasMappingSpec') -eq $false)
178183
{
179-
Write-Verbose -Message "Importing alias mapping spec for Az $ToAzVersion"
184+
Write-Verbose -Message "Importing alias mapping spec for Az $version"
180185
$AzAliasMappingSpec = Get-AzUpgradeAliasSpec -ModuleVersion $ToAzVersion
181186
}
182187
else
@@ -344,7 +349,7 @@ function New-AzUpgradeModulePlan
344349
-Duration ((Get-Date) - $cmdStarted) `
345350
-Properties ([PSCustomObject]@{
346351
ToAzureModuleName = "Az"
347-
ToAzureModuleVersion = $ToAzVersion
352+
ToAzureModuleVersion = $version
348353
UpgradeStepsCount = $planSteps.Count
349354
PlanWarnings = $planWarningSteps
350355
PlanErrors = $planErrorSteps

0 commit comments

Comments
 (0)