Git Product home page Git Product logo

azurermr's Introduction

AzureRMR

CRAN Downloads R-CMD-check

AzureRMR is a package for interacting with Azure Resource Manager: 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. Azure Active Directory OAuth tokens are obtained using the AzureAuth package.

The primary repo for this package is at https://github.com/Azure/AzureRMR; please submit issues and PRs there. It is also mirrored at the Cloudyr org at https://github.com/cloudyr/AzureRMR. You can install the development version of the package with devtools::install_github("Azure/AzureRMR").

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 credentials. AzureRMR will prompt you for permission to create a special data directory in which to cache the obtained authentication token and Resource Manager login. Once this information is saved on your machine, it can be retrieved in subsequent R sessions with get_azure_login(). Your credentials will be automatically refreshed so you don't have to reauthenticate.

Unless you have a specific reason otherwise, it's recommended that you allow AzureRMR to create this caching directory. Note that many other cloud engineering tools save credentials in this way, including the Azure CLI itself.

See the "Authentication basics" vignette for more details on how to authenticate with AzureRMR.

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()
az <- create_azure_login()

# 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"))

# tagging
stor2$set_tags(comment="hello world!", created_by="AzureRMR")

# role-based access control (RBAC)
# this uses the AzureGraph package to retrieve the user ID
gr <- AzureGraph::get_graph_login()
usr <- gr$get_user("[email protected]")
stor2$add_role_assignment(usr, "Storage blob data contributor")

# pass the GUID of the principal if you don't have AzureGraph installed
stor2$add_role_assignment("041ff2be-4eb0-11e9-8f38-394fbcd0b29d", "Storage blob data contributor")

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!


azurermr's People

Contributors

bertneef avatar hongooi73 avatar microsoft-github-policy-service[bot] avatar pedrobtz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

azurermr's Issues

list_resources() from AzureRMR fails for some subscriptions with “Invalid object names” error

I'm trying to list all the resources in a subscription.
Unfortunately, it fails with the following error:

library(AzureRMR)

az <- get_azure_login()
#> Loading Azure Resource Manager login for default tenant
az$
  get_subscription('00000000-0000-0000-0000-000000000000')$
  list_resources()
#> Error in validate_object_names(names(parms), required_names, optional_names): Invalid object names

Created on 2020-05-08 by the reprex package (v0.3.0)

I tried it for another subscription and it works fine.

How to manage reservations?

Hi,

is there any way to to manage Reservations with AzureRMR?
I'm thinking about getting the list of Reservation Orders and then the list of all Reservations.

I was trying to get the resource with:

az <- get_azure_login()
az_resource$new(
  token = az$token$credentials$access_token,
  subscription = sub_id, 
  id = "/providers/microsoft.capacity/reservationOrders/{guid}/"
)

When I added the required subscription parameter I got this:

Error: No API versions found
In addition: Warning message:
No stable API versions found, falling back to the latest preview version

That would be great to have a possibility to manage Reservations.
What I need now would be to only assign permissions for people/groups to the Reservation Orders.

Getting API version for subresources is broken

VM scaleset instance NIC:

> rg$get_resource(
+     id=".../providers/Microsoft.Compute/virtualMachineScaleSets/hongvmss/virtualMachines/0/networkInterfaces/hongvmss-nic"
+ )

Error in process_response(res, match.arg(http_status_handler)) :
  Bad Request (HTTP 400). Failed to complete operation. Message:
No registered resource provider found for location 'australiaeast' and API version '2019-03-01' for type
'virtualMachineScaleSets/virtualMachines/networkInterfaces'. The supported api-versions are
'2015-05-01-preview, 2015-06-15, 2016-03-30, 2016-04-30-preview, 2016-06-01, 2016-07-01, 2016-08-01,
2016-09-01, 2017-03-30, 2017-12-01, 2018-04-01, 2018-06-01, 2018-10-01'. The supported locations are
'eastus, eastus2, westus, centralus, northcentralus, southcentralus, northeurope, westeurope, eastasia,
southeastasia, japaneast, japanwest, australiaeast, australiasoutheast, brazilsouth, southindia,
centralindia, westindia, canadacentral, canadaeast, westus2, westcentralus, uksouth, ukwest, koreacentral,
koreasouth, francecentral, southafricanorth'.

Create Storage Account with blob versioning enabled.

I am currently trying to create a storage container with versioning enabled. Via the Azure CLI, this is straightforward. I haven't been able to get something similar to work using the properties argument of create_storage_account(). Is this possible to do somehow?

AzureRMR's set_tags() not working properly when called inside function

Hello,

I have quite a strange problem with the set_tags() method from the AzureRMR package.
I posted the question on SO (link).

In nutshell – set_tags() works fine in a script but fails while run inside a function (it cannot find an object passed to my function). The other methods (e.g. get_resource()) work ok within a function.

az$
get_subscription(resource$subscriptionid)$
get_resource_group(resource$resourcegroup)$
get_resource(type = resource$type, name = resource$name)$
set_tags(MYTAG = resource$new_tag)

Is it a bug? Should I do it differently while in a function?

Best regards,
Piotr

Troubles with using template.parameters.json

Hey,

I do not seem to be capable to use a template.parameters.json-file while deploying. It works fine using the template.json and according to the definition both parameters (template and parameters) are able to handle the usual Azure deployment templates.

rg$deploy_template(name = "foo",
                           template = "template.json",
                           parameters = "template.parameters.json"

I get the following error message:

Error in process_response(res, match.arg(http_status_handler)) : 
  Bad Request (HTTP 400). Failed to complete operation. Message:
The request content was invalid and could not be deserialized: 'Error converting value
"https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#" to type
'Microsoft.WindowsAzure.ResourceStack.Frontdoor.Data.Definitions.DeploymentParameterDefinition'.
Path 'properties.parameters.$schema', line 57, position 106.'.

I could supply you the json files but I know them to be working. Handing over the parameters as a list works fine.

Thank you!

Best,
Thomas

Fix retrieval of sub-resources by type/name

Currently this works:

rg$get_resource(type="provider/resourcetype", name="resourcename/subtype/subresourcename")

This should work but doesn't:

rg$get_resource(type="provider/resourcetype/subtype", name="resourcename/subresourcename")

Need Advice: Create Azure Batch Pool from R

I am hoping to use AzureRMR to create a pool for an existing Azure Batch account. I have googled and didn't find much help. I have only used AzureRMR a little bit, but tried the code below and got stuck. I would appreciate any advice on how to move forward. Is there another package I should be using?

library(AzureRMR)

 AzureRMR::create_azure_login(tenant = creds$password[creds$application == "azure_tenent_id"])
 az <- AzureRMR::get_azure_login(creds$password[creds$application == "azure_tenent_id"])

sub1 <- az$get_subscription(creds$password[creds$application == "azure_subscription_id"])
rg<-sub1$get_resource_group("gpubatch")
a<-rg$get_resource(type = "Microsoft.Batch/batchAccounts",name = "cmigpu")


a$create_subresource(type = "pools",name = "test_pool_1",location="westus2")

Error in process_response(res, match.arg(http_status_handler)) :
Bad Request (HTTP 400). Failed to complete operation. Message:
InvalidRequestBody
The specified Request Body is not syntactically valid. RequestId:de5ce3e7-2c70-4a17-9c4c-486ef9a95d6f
Time:2021-09-28T18:17:23.9594212Z
BatchAccount
Reason
Could not find member 'location' on object of type 'Pool'. Path 'location', line 1, position 12.
PropertyPath
location.

sign in with a personal account?

Hello,

Thanks for making this great package! I'm a newbie in Azure so this might be a silly question. I try to log in using AzureRMR::create_azure_login(). It uses the web-based authenticate and asks me to go to the web page

https://microsoft.com/devicelogin

I follow the instructions showing on my console, but when I type in my account on the web it gives me this error: You can't sign in here with a personal account. Use your work or school account instead., which is kind of surprising as I have used the same process for authenticating Azure CLI.

I think there might be some options that I need to adjust, but I just cannot figure out them from the function document. I'll appreciate it if you can shed some light on the problem. Any instruction and link will be helpful. Thanks!

Best,
Jiefei

Access to sharepoint

Hello, is there a way with this family of packages (azureRMR, AzureStor, ...) to interact with Sharepoint?

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.