R package for interacting with Azure Resource Manager
Перейти к файлу
hong-revo 24018e92fd fully implement token caching 2019-01-14 08:28:26 +11:00
R fully implement token caching 2019-01-14 08:28:26 +11:00
inst better md location 2018-10-25 01:47:40 +08:00
man fully implement token caching 2019-01-14 08:28:26 +11:00
tests fully implement token caching 2019-01-14 08:28:26 +11:00
vignettes Cli auth (#2) 2018-12-26 15:15:31 +11:00
.Rbuildignore update rbuildignore 2018-11-14 09:18:35 -08:00
.gitattributes R files 2018-04-30 21:09:03 +10:00
.gitignore require confirmation before delete 2018-05-08 12:40:22 +10:00
.travis.yml rm failing drat 2018-11-10 14:00:49 +11:00
AzureRMR.Rproj change repo name 2018-05-09 12:54:40 +10:00
AzureRMR.rxproj change repo name 2018-05-09 12:54:40 +10:00
AzureRMR.sln add sln file 2018-05-09 12:55:07 +10:00
CONTRIBUTING.md add citation, contrib docs 2018-10-19 07:23:53 +11:00
DESCRIPTION add openssl as import 2019-01-14 07:43:04 +11:00
LICENSE move license to license.md for cran 2018-11-14 09:07:24 -08:00
LICENSE.md move license to license.md for cran 2018-11-14 09:07:24 -08:00
NAMESPACE fully implement token caching 2019-01-14 08:28:26 +11:00
NEWS.md fix no-parameters deploy 2019-01-12 05:45:08 +11:00
README.md acknowledge AzureSMR 2019-01-12 21:58:09 +11:00

README.md

AzureRMR

CRAN Downloads Travis Build Status

AzureRMR is a package for interacting with Azure Active Directory and Azure Resource Manager: obtain AAD authentication tokens, list subscriptions, manage resource groups, deploy and delete templates and resources. It calls the Resource Manager REST API directly, so you don't need to have PowerShell or Python installed.

You can install the development version from GitHub, via devtools::install_github("cloudyr/AzureRMR").

Before you begin

To use AzureRMR, you must create and register a service principal with Azure Active Directory. This is a one-time task, and the easiest method is to use the Azure cloud shell.

  • If you haven't used the shell before, there will be a dialog box to choose whether to use bash or PowerShell. Choose bash.
  • In the shell, type az ad sp create-for-rbac --name {app-name} --subscription "{your-subscription-name}" --years {N}, substituting the desired name of your service principal (try to make it memorable to you, and unlikely to clash with other names), your subscription name, and the number of years you want the password to be valid.
  • Wait until the app creation is complete. You should see a screen like this.

  • Record your tenant ID, app ID, and password.

If you want to allow access at something other than subscription level, you can use the --scopes argument in place of --subscription. For example, to restrict AzureRMR to only the "AnalyticsRG" resource group: az ad sp create-for-rbac --scopes /subscriptions/{your-subscription-ID}/resourceGroups/AnalyticsRG.

Authentication

Under the hood, AzureRMR uses a similar authentication process to the Azure CLI. The first time you authenticate with a given Azure Active Directory tenant, you call create_azure_login() and supply your tenant, app ID and password. The resulting Resource Manager client object is saved on your machine, and can be retrieved in subsequent R sessions with get_azure_login("{tenant}"). AzureRMR will automatically refresh your credentials so you don't have to re-authenticate.

Sample workflow

library(AzureRMR)

# authenticate with Azure AD:
# - on first login to this client, call create_azure_login(...)
# - on subsequent logins, call get_azure_login("myaadtenant")
az <- create_azure_login("myaadtenant.onmicrosoft.com", app="app_id", password="password")

# get a subscription and resource group
sub <- az$get_subscription("{subscription_id}")
rg <- sub$get_resource_group("rgname")

# get a resource (storage account)
stor <- rg$get_resource(type="Microsoft.Storage/storageAccounts", name="mystorage")

# method chaining works too
stor <- az$
    get_subscription("{subscription_id}")$
    get_resource_group("rgname")$
    get_resource(type="Microsoft.Storage/storageAccounts", name="mystorage")


# create a new resource group and resource
rg2 <- sub$create_resource_group("newrgname", location="westus")

stor2 <- rg2$create_resource(type="Microsoft.Storage/storageAccounts", name="mystorage2",
    kind="Storage", sku=list(name="Standard_LRS"))

# delete them
stor2$delete(confirm=FALSE)
rg2$delete(confirm=FALSE)

Extending

AzureRMR is meant to be a generic mechanism for working with Resource Manager. You can extend it to provide support for service-specific features; examples of packages that do this include AzureVM for virtual machines, and AzureStor for storage accounts. For more information, see the "Extending AzureRMR" vignette.

Acknowledgements

AzureRMR is inspired by the package AzureSMR, originally written by Alan Weaver and Andrie de Vries, and would not have been possible without their pioneering work. Thanks, guys!


cloudyr project logo