Azure – Resource Providers with PowerShell and CLI
Hello Everybody,
Today we will continue with our last post Azure – Resource and Resource group and discuss about one more useful component of Microsoft Azure before proceed with Azure Resource Manager(ARM).
The resources in our resource groups are created and managed by Resource Providers. Each resource provider knows, how to manage and configure their resource.
Architecturally, this is a big change in Azure, because it means that new resource types can be developed, Deploy and exposed through a single management pane (ie: ARM) rather than having resource specific API’s which is the case for the old service management API’s.
There are different approaches available to deals with Azure Resource provider. Lets go through one by one. Today in this blog we will go with PowerShell and Azure CLI .In our next article, we will describe, how to work with Azure Resource Provider through Azure Portal.
- Power Shell:
- View all resource providers in Azure :
Using the following command we can get all resource providers in Azure for my subscription.Get-AzureRmResourceProvider -ListAvailable | Select-Object
Figure 1: Azure – Get all information of Resource ProvidersUsing the following command we can get all resource providers in Azure with specific information for my subscription like registration status.
Get-AzureRmResourceProvider -ListAvailable | Select-Object ProviderNamespace, RegistrationState
- Register a resource provider:
Using the above command, we can check, if our required Resource Provider is registered or it required a registration. If our required Resource Provider not registered yet we can register it using following command. But we must have sufficient rights to register resource provider. The scope for registration is always the subscription. Our subscription must have permission to register the Resource Provider.We can see in the above figure, resource provider Microsoft.Batch has not registered yet. We can register that using the following command and the respected result can be seen in the following figure.Register-AzureRmResourceProvider -ProviderNamespace Microsoft.Batch
Figure 3: Azure – Registering a Resource ProviderAfter successfully register the provider, lets check the status of the resource provider using following powershell.
Get-AzureRmResourceProvider -ProviderNamespace Microsoft.Batch
- Get API versions of resource type:
In this way we can use powershell to interact with resource provider. we can get much more required information like, resource types for a resource provider , API versions of resource type. following are few powershell command for the above requirement.(Get-AzureRmResourceProvider -ProviderNamespace Microsoft.Batch).ResourceTypes.ResourceTypeName
((Get-AzureRmResourceProvider -ProviderNamespace Microsoft.Batch).ResourceTypes | Where-Object ResourceTypeName -eq batchAccounts).ApiVersions
- Get all supported locations for a resource type:One more important point to note is, resource manager is supported in all regions, but the resources we want to deploy might not be supported in all regions. Addition to this, there may be limitations on our subscription that prevent us from using some regions that support the resource. So we can check the supported location for a resource type using following powershell command.
((Get-AzureRmResourceProvider -ProviderNamespace Microsoft.Batch).ResourceTypes | Where-Object ResourceTypeName -eq batchAccounts).Locations
- View all resource providers in Azure :
- Azure CLI:
As we said earlier in this blog, there are different way to work with Azure Resource Provider as we did with powershell. Now we will use Azure CLI to achieve same goal. In our one of last blog we have discussed how to start Working with Azure CLI.- View all resource providers in Azure :
az provider list --query "[].{Provider:namespace, Status:registrationState}" --out table
As we can see in the following figure, we have registered teh Microsoft.Batch resource provider in our last demo with powershell.
Figure 6: Azure – Get all Resource Provider using Azure CLI - Register a resource provider:
az provider register --namespace Microsoft.AlertsManagement
az provider show --namespace Microsoft.AlertsManagement
As we can see in the above figure, we have Microsoft.AlertsManagement resource provider, which is not registered yet. So lets proceed with this provider and register it, as in shown in the above CLI command and the result in the following figure.
- Get API versions of resource type:
az provider show --namespace Microsoft.AlertsManagement --query "resourceTypes[?resourceType=='alertsSummary'].apiVersions | [0]" --out table
- Get Supported locations information for a resource:
az provider show --namespace Microsoft.AlertsManagement
With the above CLI command, we have tried to find, if “Microsoft.AlertsManagement” have any locations for its any resource type. But unfortunatly, we don’t find any value there, as we can see in the following image. So here we are, using “Microsoft.Batch” provider for our demo purpose .
Figure 9: Azure – No locations for the resource typeaz provider show --namespace Microsoft.Batch --query "resourceTypes[?resourceType=='batchAccounts'].locations | [0]" --out table
- View all resource providers in Azure :
We will come with one new blog, where we will describe how to communicate with Resource Provider through Azure Portal.
Hope this blog gives you a basic understanding on Azure Resource Provider.
Thanks for reading 🙂
Keep reading, share your thoughts, experiences. Feel free to contact us to discuss more. If you have any suggestion / feedback / doubt, you are most welcome.
Stay tuned on Knowledge-Junction, will come up with more such articles.
script to register all resource provider at a time