Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.21k stars 3.81k forks source link

Role Definition - InputFile Error #13023

Closed ljtill closed 3 years ago

ljtill commented 3 years ago

Description

When using the New-AzRoleDefinition cmdlet, I'm unable to provide a Role Definition (.json) via the -InputFile parameter, every time it throws an error. The error doesn't indicate if it's an issue with the Cmdlet itself or with the JSON structure.

Error: Object reference not set to an instance of an object.

Steps to reproduce

New-AzRoleDefinition -InputFile "./definition.json"

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.3
PSEdition                      Core
GitCommitId                    7.0.3
OS                             Darwin 19.6.0 Darwin Kernel Version 19.6.0: Thu Jun 18 20:49:00 PDT 2020; root:xnu-6153.141.1~1/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

Version Name
------- ----
4.6.1   Az
1.9.3   Az.Accounts
1.1.1   Az.Advisor
1.2.0   Az.Aks
1.1.4   Az.AnalysisServices
2.1.0   Az.ApiManagement
1.1.0   Az.ApplicationInsights
1.4.0   Az.Automation
3.1.0   Az.Batch
1.0.3   Az.Billing
1.4.3   Az.Cdn
1.5.1   Az.CognitiveServices
4.3.1   Az.Compute
1.0.3   Az.ContainerInstance
1.1.1   Az.ContainerRegistry
1.1.0   Az.DataBoxEdge
1.10.0  Az.DataFactory
1.0.2   Az.DataLakeAnalytics
1.2.8   Az.DataLakeStore
1.0.0   Az.DataShare
1.1.0   Az.DeploymentManager
1.0.0   Az.DesktopVirtualization
1.0.2   Az.DevTestLabs
1.1.2   Az.Dns
1.3.0   Az.EventGrid
1.5.0   Az.EventHub
1.6.1   Az.FrontDoor
1.0.1   Az.Functions
3.5.0   Az.HDInsight
1.1.0   Az.HealthcareApis
2.5.0   Az.IotHub
2.1.0   Az.KeyVault
1.3.2   Az.LogicApp
1.1.3   Az.MachineLearning
1.1.0   Az.Maintenance
1.1.0   Az.ManagedServices
1.0.2   Az.MarketplaceOrdering
1.1.1   Az.Media
2.1.0   Az.Monitor
3.3.0   Az.Network
1.1.1   Az.NotificationHubs
2.3.0   Az.OperationalInsights
1.3.1   Az.PolicyInsights
1.1.2   Az.PowerBIEmbedded
1.0.3   Az.PrivateDns
2.11.1  Az.RecoveryServices
1.2.1   Az.RedisCache
1.0.3   Az.Relay
2.5.0   Az.Resources
1.4.1   Az.ServiceBus
2.1.0   Az.ServiceFabric
1.2.0   Az.SignalR
2.9.1   Az.Sql
1.1.0   Az.SqlVirtualMachine
2.5.0   Az.Storage
1.3.0   Az.StorageSync
1.0.1   Az.StreamAnalytics
1.0.0   Az.Support
1.0.4   Az.TrafficManager
1.11.0  Az.Websites

Debug output

DEBUG: 15:21:14 - NewAzureRoleDefinitionCommand begin processing with ParameterSet 'InputFileParameterSet'.
DEBUG: 15:21:14 - using account id '[Redacted]'...
New-AzRoleDefinition: Object reference not set to an instance of an object.
DEBUG: AzureQoSEvent: CommandName - New-AzRoleDefinition; IsSuccess - False; Duration - 00:00:00.0220864;; Exception - System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Azure.Commands.Resources.NewAzureRoleDefinitionCommand.ExecuteCmdlet()
   at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.<>c__3`1.<ExecuteSynchronouslyOrAsJob>b__3_0(T c)
   at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet, Action`1 executor)
   at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet)
   at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord();
DEBUG: Finish sending metric.
DEBUG: 15:21:15 - NewAzureRoleDefinitionCommand end processing.

Error output

WARNING: Breaking changes in the cmdlet 'Resolve-AzError' :
WARNING:  - The `Resolve-Error` alias will be removed in a future release.  Please change any scripts that use this alias to use `Resolve-AzError` instead.

WARNING: NOTE : Go to https://aka.ms/azps-changewarnings for steps to suppress this breaking change warning, and other information on breaking changes in Azure PowerShell.

   HistoryId: 2

Message        : Object reference not set to an instance of an object.
StackTrace     :    at Microsoft.Azure.Commands.Resources.NewAzureRoleDefinitionCommand.ExecuteCmdlet()
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.<>c__3`1.<ExecuteSynchronouslyOrAsJob>b__3_0(T c)
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet, Action`1 executor)
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet)
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception      : System.NullReferenceException
InvocationInfo : {New-AzRoleDefinition}
Line           : New-AzRoleDefinition -InputFile "./definition.json"
Position       : At line:1 char:1
                 + New-AzRoleDefinition -InputFile "./definition.json"
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 2

The Azure PowerShell team is listening, please let us know how we are doing: https://aka.ms/azpssurvey?Q_CHL=ERROR.
ljtill commented 3 years ago

After making a few minor changes to the .json structure, it seems that the definition is now working, the error message is quite confusing though and could be improved to help the user locate the issue.