Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐞 The 'Get-AzKeyVaultAccessPolicies' module could not be loaded. #445

Open
JoLanckriet opened this issue Jan 15, 2025 · 1 comment
Open
Labels
area:key-vault All issues related to Azure Key Vault bug Something isn't working dependencies Pull requests that update a dependency file
Milestone

Comments

@JoLanckriet
Copy link

JoLanckriet commented Jan 15, 2025

Hi,

Since a month ago retrieving keyvault access policies with arcus does not work anymore.

Using this step in the pipeline:

- task: AzurePowerShell@5
  displayName: 'Retrieve KeyVault Access Policies'
  inputs:
    azureSubscription: ${{parameters.azureSubscription}}
    scriptType: 'InlineScript'
    azurePowerShellVersion: 'LatestVersion'
    Inline: |
        Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
        Install-Module -Name Arcus.Scripting.KeyVault -Repository PSGallery -AllowClobber
        $accessPolicies = Get-AzKeyVaultAccessPolicies -KeyVaultName $(InstallerApp.KeyVault.Name) -ResourceGroupName $(InstallerApp.ResourceGroup.Name)
        $accessPoliciesjson = $accessPolicies | ConvertTo-Json -Depth 5 -Compress
        Write-Host ("##vso[task.setvariable variable=InstallerApp.KeyVault.AccessPolicies;]$accessPoliciesjson")

This used to work like expected and the policies where retrieved however the following error started appearing since the middle of december 2024 (to my knowledge).

##[error]The 'Get-AzKeyVaultAccessPolicies' command was found in the module 'Arcus.Scripting.KeyVault', but the module could not be loaded. For more information, run 'Import-Module Arcus.Scripting.KeyVault'.
##[error]PowerShell exited with code '1'.

I was able to resolve this by installing the Az.Accounts module seperately in the pipeline before executing the step mentioned above. This results in the following steps:

- task: AzurePowerShell@5
  displayName: 'Install Az.Accounts'
  inputs:
    azureSubscription: ${{parameters.azureSubscription}}
    scriptType: 'InlineScript'
    azurePowerShellVersion: 'LatestVersion'
    Inline: |    
        Get-InstalledModule -Name Az.Accounts -AllVersions -ErrorAction SilentlyContinue | Uninstall-Module -Force -ErrorAction SilentlyContinue
        Install-Module -Name Az.Accounts -Force -AllowClobber

- task: AzurePowerShell@5
  displayName: 'Retrieve KeyVault Access Policies'
  inputs:
    azureSubscription: ${{parameters.azureSubscription}}
    scriptType: 'InlineScript'
    azurePowerShellVersion: 'LatestVersion'
    Inline: |
        Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
        Install-Module -Name Arcus.Scripting.KeyVault -Repository PSGallery -AllowClobber
        $accessPolicies = Get-AzKeyVaultAccessPolicies -KeyVaultName $(InstallerApp.KeyVault.Name) -ResourceGroupName $(InstallerApp.ResourceGroup.Name)
        $accessPoliciesjson = $accessPolicies | ConvertTo-Json -Depth 5 -Compress
        Write-Host ("##vso[task.setvariable variable=InstallerApp.KeyVault.AccessPolicies;]$accessPoliciesjson")

Doing this returns the expected behaviour.

@stijnmoreels
Copy link
Member

stijnmoreels commented Jan 16, 2025

Thx for letting us know!

@pim-simons , did we released yet the global Azure packages update for Scripting? I would guess this is related to older package versions?

@stijnmoreels stijnmoreels added this to the v1.5.0 milestone Jan 16, 2025
@github-project-automation github-project-automation bot moved this to To do in Roadmap Jan 16, 2025
@stijnmoreels stijnmoreels added bug Something isn't working area:key-vault All issues related to Azure Key Vault dependencies Pull requests that update a dependency file labels Jan 16, 2025
@stijnmoreels stijnmoreels changed the title The 'Get-AzKeyVaultAccessPolicies' module could not be loaded. 🐞 The 'Get-AzKeyVaultAccessPolicies' module could not be loaded. Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:key-vault All issues related to Azure Key Vault bug Something isn't working dependencies Pull requests that update a dependency file
Projects
Status: To do
Development

No branches or pull requests

2 participants