Asked by:
Getting Error in Using Azure Management Libraries to create a VM

Question
-
I have tried to create VM Using Azure Management Libraries. Used the following c# code:
var creds = new AzureCredentialsFactory().FromServicePrincipal(clientId, clientSecret, tenantId, AzureEnvironment.AzureGlobalCloud); var azure = Azure.Authenticate(creds).WithSubscription(subscriptionId); IVirtualMachine windowsVM = azure.VirtualMachines.Define("MyVirtualAPI") .WithRegion(Region.USEast) .WithExistingResourceGroup("Test") .WithNewPrimaryNetwork("10.0.0.0/28") .WithPrimaryPrivateIPAddressDynamic() .WithNewPrimaryPublicIPAddress("MyIPAddressLabel") .WithPopularWindowsImage(KnownWindowsVirtualMachineImage.WindowsServer2012R2Datacenter) .WithAdminUsername("Admin") .WithAdminPassword("WindowsServer2012") .WithSize(VirtualMachineSizeTypes.StandardB1ms) .Create();
I have provided Correct credentials for AzureCredentialsFactory and also tried role-based access control. Provided Azure Resource Graph to my resource group (Test) in Access control (IAM).
Error Log I am getting:
Microsoft.Rest.Azure.CloudException HResult=0x80131500 Message=The client '**' with object id '**' does not have authorization to perform action 'Microsoft.Network/virtualNetworks/write' over scope '/subscriptions/**/resourceGroups/Test/providers/Microsoft.Network/virtualNetworks/vnetfae964378591' or the scope is invalid. If access was recently granted, please refresh your credentials. Source=Microsoft.Azure.Management.Network.Fluent StackTrace:...
Thanks in Advance
- Edited by Mohit Kumawat Monday, September 9, 2019 11:50 AM Description Update
All replies
-
From the error message, it looks like your Service Principle has no permissions to perform a write on the Microsoft.Network/virtualNetworks. So ensure that you have the permissions required. Or the other option is an invalid scope, so that means that potentially you are using an invalid subscription id for the given tenant.
-
From the error message, it looks like your Service Principle has no permissions to perform a write on the Microsoft.Network/virtualNetworks. So ensure that you have the permissions required. Or the other option is an invalid scope, so that means that potentially you are using an invalid subscription id for the given tenant.
- Edited by Mohit Kumawat Tuesday, September 10, 2019 4:56 AM Correction
-
To continue troubleshooting this issue, your best bet is to create a support request. If you do not have a support plan, please let me know!
- Proposed as answer by TravisCragg_MSFTMicrosoft employee Tuesday, September 17, 2019 12:00 AM