GithubHelp home page GithubHelp logo

isabella232 / resources-node-manage-resources-with-msi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from azure-samples/resources-node-manage-resources-with-msi

0.0 0.0 0.0 20 KB

sample that shows how to use msi with node sdk

License: MIT License

TypeScript 100.00%

resources-node-manage-resources-with-msi's Introduction

page_type languages products description urlFragment
sample
typescript
azure
This sample demonstrates how to manage Azure resources via Managed Service Identity using the node.js SDK with typescript.
resources-node-manage-resources-with-msi

Manage resources using Managed Service Identity using node.js

This sample demonstrates how to manage Azure resources via Managed Service Identity using the node.js SDK with typescript.

On this page

Create an Azure VM with MSI extension

Azure Compute VM with MSI

Run this sample

  1. If you don't already have it, get the latest LTS version of node.js.

  2. Clone the repository.

    git clone https://github.com/Azure-Samples/compute-node-msi-vm.git
    
  3. Install the dependencies.

    cd compute-node-msi-vm
    npm install
    
  4. Set the following environment variables.

    export AZURE_SUBSCRIPTION_ID={your subscription id}
    
    • optionally you can also set the port. If not set then it will use the default port 50342. This should be the same value that you specified while creating the vm with SMI extension.
    export MSI_PORT={port numer}
    

    [AZURE.NOTE] On Windows, use set instead of export.

  5. Run the sample.

    node dist/lib/index.js
    

What is index.js doing?

Create an MSI Token Provider

Initialize subscription_id, tenant_id and port from environment variables.

public domain: string = process.env['DOMAIN'];
public subscriptionId: string = process.env['AZURE_SUBSCRIPTION_ID'];
public port: number = process.env['MSI_PORT'] ? parseInt(process.env['MSI_PORT']) : 50342; //If not provided then we assume the default port

Now, we will create token credential using the msi login.

// Create Managed Service Identity as the token provider
credentials = await msRestAzure.loginWithMSI({ port: this.state.port });

Create a resource client and list resource groups

Now, we will create a resource management client using Managed Service Identity token provider.

this.resourceClient = new ResourceManagementClient(credentials, this.state.subscriptionId);
let finalResult = await this.resourceClient.resourceGroups.list();

resources-node-manage-resources-with-msi's People

Contributors

amarzavery avatar microsoftopensource avatar msftgits avatar v-hearya avatar

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.