Azure / deployment-stacks

Contains Deployment Stacks CLI scripts and releases
MIT License
87 stars 7 forks source link

PowerShell cmdlets fail with "Object reference not set to an instance of an object" #38

Closed andrew-kelleher closed 2 years ago

andrew-kelleher commented 2 years ago

Describe the bug After installing the deployments stack PS modules, running any of the cmdlets returns an Object reference not set to an instance of an object error.

To Reproduce Steps to reproduce the behaviour:

  1. Download and unzip the deployment stack package (v0.1.1)
  2. Create a new PowerShell terminal session within VSCode with administrator privileges
  3. Confirm the PowerShell version as 7.2 using $PSVersionTable.PSVersion
  4. Login to Azure using Connect-AzAccount
  5. Set the Azure subscription using Set-AzContext
  6. Run Set-ExecutionPolicy Bypass -Scope Process
  7. Install the module using ./AzDeploymentStacksPrivatePreview.ps1
  8. Select Option 1 (Option 2 also works)

The installation appears to complete successfully and returns -

Which operation (1, 2, or 3)?: 1
This action will install the Deployment Stack cmdlet(s) to the current 
Powershell Session (prompt) so they can be previewed/tested.

Continue with install? (Y/N): Y
Verifying Azure Powershell module availability...
Azure Powershell module verified!

Verifying you're logged into Azure...
Login verified!

Installing demo module 'Az.Resources'... (current session only)
Module installed!

Issue When running any of the new cmdlets i.e. Get-AzSubscriptionDeploymentStack the following error is returned -

Object reference not set to an instance of an object

Repro Environment Host OS: Windows 10 Powershell Version: 7.2

The output from get-module az.resources -ListAvailable returns -

irectory: C:\Users\andrew.kelleher\OneDrive\Documents\PowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     4.2.0                 Az.Resources                        Core,Desk {Get-AzProviderOperation, Remove…

    Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Manifest   9.0.0                 Az.Resources                        Core,Desk {Get-AzProviderOperation, Remove…

Server Debugging Information Timestamp of issue (please include time zone): 16/11/2021 @ 10:00 GMT Data Center (eg, West Central US, West Europe): UK South

maciejporebski commented 2 years ago

If you run Get-AzSubscriptionDeploymentStack with -Debug do you get a "No HTTP resource was found that matches the request URI" response for the https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Resources/deploymentStacks?api-version=2021-05-01-preview request?

If so I seem to be facing the same issue. I've let @bmoore-msft know via email and the dev team may already be looking at it.

andrew-kelleher commented 2 years ago

Hi @maciejporebski, thanks for tip on the -debug switch.

Yes, I'm getting exactly the same response in the body -

Body:
{
  "message": "No HTTP resource was found that matches the request URI 'https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Resources/deploymentStacks?api-version=2021-05-01-preview'."
}
bmoore-msft commented 2 years ago

Can you run:

Get-AzProviderFeature -ProviderNamespace Microsoft.Resources

And paste the output and your subId?

snarkywolverine commented 2 years ago

Before you do what Brian suggested, you should also check that you are working in the correct subscription context by using:

Select-AzSubscription <>
maciejporebski commented 2 years ago

Just tried using the module again and I no longer get this issue!

In case it helps in any way this is my output for 9cc55246-7157-4ef7-a375-ce22fb559f66

FeatureName             ProviderName        RegistrationState
-----------             ------------        -----------------
DeploymentStacksPreview Microsoft.Resources Registered
bmoore-msft commented 2 years ago

@maciejporebski - thanks for confirming... @andrew-kelleher let us know what you find out...

andrew-kelleher commented 2 years ago

@bmoore-msft when running Get-AzProviderFeature -ProviderNamespace Microsoft.Resources nothing's returned.

So possibly this particular subscription hasn't been onboarded onto to the preview?

bmoore-msft commented 2 years ago

Certainly possible - this is the a82f... subscription?

andrew-kelleher commented 2 years ago

Yes, that's the subscription 👍

rbnmk commented 2 years ago

I seem to have the same with my MSDN subscription(s). Could that be a reason that they are not onboarded? I don't get any output running: Get-AzProviderFeature -ProviderNamespace Microsoft.Resources

I get the error for both the SubscriptionStack and ResourceGroupStack cmdlet New-AzSubscriptionDeploymentStack: Object reference not set to an instance of an object. New-AzResourceGroupDeploymentStack: Object reference not set to an instance of an object.

andrew-kelleher commented 2 years ago

Hi @rbnmk. Yes, the issue for us was that our subscription needed to be onboarded. It's all working for us now.

bmoore-msft commented 2 years ago

if there's no provider feature registered, that's the first step to fix - you can send my your subId and we can onboard it.