diff --git a/.changes/next-release/Breaking Change-164328cf-e5ba-44d0-9133-9e00214d1af9.json b/.changes/next-release/Breaking Change-164328cf-e5ba-44d0-9133-9e00214d1af9.json new file mode 100644 index 00000000..34a6f744 --- /dev/null +++ b/.changes/next-release/Breaking Change-164328cf-e5ba-44d0-9133-9e00214d1af9.json @@ -0,0 +1,4 @@ +{ + "type": "Breaking Change", + "description": "Use AWS.Tools.* Powershell Modules for AWSPowershellModuleScript if available" +} \ No newline at end of file diff --git a/src/tasks/AWSPowerShellModuleScript/RunAWSPowerShellModuleScript.ps1 b/src/tasks/AWSPowerShellModuleScript/RunAWSPowerShellModuleScript.ps1 index 764df925..af3acbb0 100644 --- a/src/tasks/AWSPowerShellModuleScript/RunAWSPowerShellModuleScript.ps1 +++ b/src/tasks/AWSPowerShellModuleScript/RunAWSPowerShellModuleScript.ps1 @@ -33,31 +33,43 @@ try { Assert-VstsPath -LiteralPath $tempDirectory -PathType 'Container' - # install the module if not present (we assume if present it is an an autoload-capable - # location) + # Check for modular AWS powershell module first Write-Host (Get-VstsLocString -Key 'TestingAWSModuleInstalled') - if (!(Get-Module -Name AWSPowerShell -ListAvailable)) { - Write-Host (Get-VstsLocString -Key 'AWSModuleNotFound') - - # AllowClobber is not available in Install-Module in the Hosted agent (but is in the - # Hosted 2017 agent). We always install/update the latest NuGet package - # provider to work around Install-Module on the Hosted agent also not having -Force and - # producing the error - # - # 'Exception calling “ShouldContinue” with “2” argument(s): “Windows PowerShell is in NonInteractive mode.' - # - Write-Host (Get-VstsLocString -Key 'InstallingAWSModule') - Install-PackageProvider -Name NuGet -Scope CurrentUser -Verbose -Force - $installModuleCmd = Get-Command Install-Module - if ($installModuleCmd.Parameters.ContainsKey("AllowClobber")) { - Install-Module -Name AWSPowerShell -Scope CurrentUser -Verbose -AllowClobber -Force + if (Get-Module -Name AWS.Tools.Common -ListAvailable) { + Write-Host (Get-VstsLocString -Key 'ModularAWSModuleFound') + if(Get-Module -Name AWS.Tools.SecurityToken -ListAvailable) { + Import-Module -Name AWS.Tools.SecurityToken } else { - Install-Module -Name AWSPowerShell -Scope CurrentUser -Verbose -Force + Write-Host (Get-VstsLocString -Key 'SecurityTokenModuleNotFound') } } - - Import-Module -Name AWSPowerShell + else { + # install the module if not present (we assume if present it is an an autoload-capable + # location) + if (!(Get-Module -Name AWSPowerShell -ListAvailable)) { + Write-Host (Get-VstsLocString -Key 'AWSModuleNotFound') + + # AllowClobber is not available in Install-Module in the Hosted agent (but is in the + # Hosted 2017 agent). We always install/update the latest NuGet package + # provider to work around Install-Module on the Hosted agent also not having -Force and + # producing the error + # + # 'Exception calling “ShouldContinue” with “2” argument(s): “Windows PowerShell is in NonInteractive mode.' + # + Write-Host (Get-VstsLocString -Key 'InstallingAWSModule') + Install-PackageProvider -Name NuGet -Scope CurrentUser -Verbose -Force + $installModuleCmd = Get-Command Install-Module + if ($installModuleCmd.Parameters.ContainsKey("AllowClobber")) { + Install-Module -Name AWSPowerShell -Scope CurrentUser -Verbose -AllowClobber -Force + } + else { + Install-Module -Name AWSPowerShell -Scope CurrentUser -Verbose -Force + } + } + + Import-Module -Name AWSPowerShell + } ############################################################################### # If credentials and/or region are not defined on the task we assume them to be diff --git a/src/tasks/AWSPowerShellModuleScript/task.json b/src/tasks/AWSPowerShellModuleScript/task.json index 143e879f..6eedee4c 100644 --- a/src/tasks/AWSPowerShellModuleScript/task.json +++ b/src/tasks/AWSPowerShellModuleScript/task.json @@ -132,6 +132,8 @@ "messages": { "GeneratingScript": "Generating script.", "TestingAWSModuleInstalled": "Checking install status for AWS Tools for Windows PowerShell module.", + "ModularAWSModuleFound": "AWS.Tools.Common found. Assuming all needed AWS.Tools modules are already installed.", + "SecurityTokenModuleNotFound": "AWS.Tools.SecurityToken module not found. You will not be able to use a service connection specifying a role ARN.", "AWSModuleNotFound": "AWS Tools for Windows PowerShell module not found.", "InstallingAWSModule": "Installing AWS Tools for Windows PowerShell module to current user scope", "ConfiguringRegionFromTaskConfiguration": "Region discovered from task configuration",