What is azure-arm-resource?
The azure-arm-resource npm package is a client library for managing Azure resources. It provides functionalities to interact with Azure Resource Manager (ARM) APIs, allowing you to create, update, delete, and manage Azure resources programmatically.
What are azure-arm-resource's main functionalities?
Create Resource Group
This code sample demonstrates how to create a new resource group in Azure using the azure-arm-resource package. It logs in using a service principal and then creates a resource group in the specified location.
const msRestAzure = require('ms-rest-azure');
const ResourceManagementClient = require('azure-arm-resource').ResourceManagementClient;
msRestAzure.loginWithServicePrincipalSecret(clientId, secret, domain, (err, credentials) => {
if (err) throw err;
const client = new ResourceManagementClient(credentials, subscriptionId);
const groupParameters = { location: 'westus' };
client.resourceGroups.createOrUpdate('myResourceGroup', groupParameters, (err, result) => {
if (err) throw err;
console.log('Resource group created:', result);
});
});
List Resource Groups
This code sample demonstrates how to list all resource groups in a subscription using the azure-arm-resource package. It logs in using a service principal and then retrieves and prints the list of resource groups.
const msRestAzure = require('ms-rest-azure');
const ResourceManagementClient = require('azure-arm-resource').ResourceManagementClient;
msRestAzure.loginWithServicePrincipalSecret(clientId, secret, domain, (err, credentials) => {
if (err) throw err;
const client = new ResourceManagementClient(credentials, subscriptionId);
client.resourceGroups.list((err, result) => {
if (err) throw err;
console.log('List of resource groups:', result);
});
});
Delete Resource Group
This code sample demonstrates how to delete a resource group in Azure using the azure-arm-resource package. It logs in using a service principal and then deletes the specified resource group.
const msRestAzure = require('ms-rest-azure');
const ResourceManagementClient = require('azure-arm-resource').ResourceManagementClient;
msRestAzure.loginWithServicePrincipalSecret(clientId, secret, domain, (err, credentials) => {
if (err) throw err;
const client = new ResourceManagementClient(credentials, subscriptionId);
client.resourceGroups.deleteMethod('myResourceGroup', (err, result) => {
if (err) throw err;
console.log('Resource group deleted:', result);
});
});
Other packages similar to azure-arm-resource
azure-arm-compute
The azure-arm-compute package is used for managing Azure compute resources, such as virtual machines, VM scale sets, and availability sets. It provides functionalities specific to compute resources, whereas azure-arm-resource is more general and can manage a wider range of Azure resources.
azure-arm-network
The azure-arm-network package is used for managing Azure networking resources, such as virtual networks, subnets, and network interfaces. It focuses on networking-specific functionalities, while azure-arm-resource provides a broader scope for managing various types of Azure resources.
azure-arm-storage
The azure-arm-storage package is used for managing Azure storage resources, such as storage accounts and blobs. It is specialized for storage-related operations, whereas azure-arm-resource offers a more comprehensive set of functionalities for managing different types of Azure resources.
Microsoft Azure SDK for Node.js - Resource Management
This project provides a Node.js package that makes it easy to manage Azure resources. Right now it supports:
- Node.js version: 6.x.x or higher
How to Install
npm install azure-arm-resource
How to Use
Authentication, client creation and listing resources as an example
var msRestAzure = require('ms-rest-azure');
var resourceManagement = require("azure-arm-resource");
msRestAzure.interactiveLogin(function(err, credentials) {
var client = new resourceManagement.ResourceManagementClient(credentials, 'your-subscription-id');
client.resources.list(function(err, result) {
if (err) console.log(err);
console.log(result);
});
});
Creating a Resource Group
var util = require('util');
var groupParameters = {
location: 'West US',
tags: {
tag1: 'val1',
tag2: 'val2'
}
};
var groupName = 'testGroup1';
client.resourceGroups.createOrUpdate(groupName, groupParameters, function (err, result, request, response) {
if (err) {
console.log(err);
} else {
console.log('result is: ' + util.inspect(result, {depth: null}));
}
});
Create a Generic Resource in a Resource Group
var groupName = 'testGroup1';
var resourceName = 'autorestsite102';
var params = { 'location': 'West US', 'properties' : { 'SiteMode': 'Limited', 'ComputeMode': 'Shared' }, 'Name': resourceName };
var resourceType = 'sites';
var parentResourcePath = '';
var resourceProviderNamespace = 'Microsoft.Web';
var apiVersion = '2014-04-01';
client.resources.createOrUpdate(groupName, resourceProviderNamespace, parentResourcePath,
resourceType, resourceName , apiVersion, params, function (err, result, request, response) {
if (err) {
console.log(err);
} else {
console.log(result);
}
});
Get a Generic Resource in a Resource Group
var groupName = 'testGroup1';
var resourceName = 'autorestsite102';
var resourceType = 'sites';
var parentResourcePath = '';
var resourceProviderNamespace = 'Microsoft.Web';
var apiVersion = '2014-04-01';
client.resources.get(groupName, resourceProviderNamespace, parentResourcePath,
resourceType, resourceName, apiVersion, function (err, result, request, response) {
if (err) {
console.log(err);
} else {
console.log(result);
}
});
Listing all resources in your subscription
client.resources.list(function (err, result, request, response) {
if (err) {
console.log(err);
} else {
console.log(result);
}
});
Deleting a Generic Resource in a Resource Group
var groupName = 'testGroup1';
var resourceName = 'autorestsite102';
var resourceType = 'sites';
var parentResourcePath = '';
var resourceProviderNamespace = 'Microsoft.Web';
var apiVersion = '2014-04-01';
client.resources.deleteMethod(groupName, resourceProviderNamespace, parentResourcePath,
resourceType, resourceName, apiVersion, function (err, result, request, response) {
if (err) {
console.log(err);
} else {
console.log(result);
}
});
Deleting the Resource Group
var groupName = 'testGroup1';
client.resourceGroups.deleteMethod(groupName, function (err, result, request, response) {
if (err) {
console.log(err);
} else {
console.log(result);
}
});
Please take a look at the tests over here for more examples.
Related projects