Giter VIP home page Giter VIP logo

azr's Introduction

azr

Get resources by Azure ResourceGraph

Description

azr is a tool to list Azure resources.

Install

  1. Go to release page
  2. Download and extract

Usage

This tool requires Azure CLI and read permission for resources.

Case 1 : Query from command line option and output to stdout

# You need login and set target subscription.
az login
az account set --subscription <Your subscriptionID>
# Execute command
./azr  --subscriptionID <Your subscriptionID> -q "resources|where type =~ 'microsoft.compute/virtualmachines'|take 2"

Case 2 : Query from command line option and output to file

# You need login and set target subscription.
az login
az account set --subscription <Your subscriptionID>
# Execute command
./azr  --subscriptionID <Your subscriptionID> -q "resources|where type =~ 'microsoft.compute/virtualmachines'|take 2" -f result.csv

Case 3 : Query from YAML file

If the first character of the -q option starts with @, the character string after @ is regarded as the file path.

- name: test1
  query: |
    resources
    | where type =~ "microsoft.compute/virtualmachines"
# You get only 1000 result if you don't include 'id' column.
- name: test2
  query: |
    resources
    | where type =~ "microsoft.compute/virtualmachines"
    | project id,name
- name: test3
  query: |
    resources
    | take 10
# You need login and set target subscription.
az login
az account set --subscription <Your subscriptionID>
# Execute command
./azr  --subscriptionID <Your subscriptionID> -q @sample/query.yml

Result is output file to :<name>.csv

Limitation

If you get more than 1000 results, you need to include the id in the project. Otherwise, only 1000 results will be returned.

Help

NAME:
   azr - Azure Resource Graph Command

USAGE:
   azr [global options] command [command options] [arguments...]

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --subscriptionID value
   --query value, -q value
   --file value, -f value   Speify output filepath(If not specify, out to stdout)
   --help, -h               show help (default: false)

Authentication

You can use AZURE_AUTH_LOCATION environment. If you set this environment variable, this tool read credential from this file.

export AZURE_AUTH_LOCATION=azure.auth
az ad sp create-for-rbac --sdk-auth > azure.auth

Please read this document: https://docs.microsoft.com/en-us/azure/go/azure-sdk-go-authorization#use-file-based-authentication

Sample

Please see sample directory.

azr's People

Contributors

tsubasaxzzz avatar

Watchers

James Cloos avatar  avatar  avatar

azr's Issues

AzureCloudShellで実行するとエラーになる

概要

AzureCloudShellで実行するとエラーになる

再現手順

AzureCloudShell上で下記コマンドを実行する

genboku@Azure:~$ az account set --subscription hogehoge
genboku@Azure:~$ ./azr --subscriptionID hogehoge -q "resources|where type =~ 'microsoft.compute/virtualmachines'|take 2"
2020/02/20 05:46:17 Error parsing Token Expiration Date "N/A": Error parsing expiration date "N/A".

CloudShell Error:
parsing time "N/A" as "2006-01-02T15:04:05Z07:00": cannot parse "N/A" as "2006"

CLI Error:
parsing time "N/A" as "2006-01-02 15:04:05.999999": cannot parse "N/A" as "2006"

再現環境

genboku@Azure:~$ az version
This command is in preview. It may be changed/removed in a future release.
{
  "azure-cli": "2.1.0",
  "azure-cli-command-modules-nspkg": "2.0.3",
  "azure-cli-core": "2.1.0",
  "azure-cli-nspkg": "3.0.4",
  "azure-cli-telemetry": "1.0.4",
  "extensions": {
    "application-insights": "0.1.1",
    "resource-graph": "1.0.0"
  }
}

修正ないと困る内容

AzureCloundShellで使用できない

ほかに調査した内容

  • 下記条件ではうまくいった

    • AzureCloudShell上で az graph query -q (略) を実行
    • WSL上で同じコマンドを実行
  • エラーログ内容を調べたところ、下記Issueで似たような事例を発見
    * module.linux_server.provider.azurerm: Error converting Authorization Token to an ADAL Token: Error parsing Token Expiration Date "N/A": Error parsing expiration date "N/A".
    hashicorp/terraform-provider-azurerm#3035

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.