Git Product home page Git Product logo

Comments (7)

mivano avatar mivano commented on May 27, 2024 1

It tries to fetch the data for the whole of the subscriptions, not on the resourcegroup level. That can be the reason you get the 401, as the scope is subscription.

from azure-cost-cli.

mivano avatar mivano commented on May 27, 2024 1

Your registration is correct, but you scope it to a resource group: az ad sp create-for-rbac --name "FinOpsCli" --role "Cost Management Reader" --scopes /subscriptions/Sub-ID1/resourceGroups/FinOpsRG --sdk-auth so remove the /resourceGroups/FinOpsRG from it.

And what you are doing is not wrong, but the tool does a call to the api with a scope on the subscription, not on a resource group level (yes, you can query or filter on resource groups, but it will still do the call on the subscription level). I could use a different scope, but for simplicity, it currently operates on subscriptions.

To get the authentication, the tool looks at the default credentials provided, so it will first query the AZ login call. So you can try to log in using the az login call. See the docs.

from azure-cost-cli.

mivano avatar mivano commented on May 27, 2024 1

Good to hear that it works for you. If you have more examples, then please do a PR with them.

from azure-cost-cli.

welcome avatar welcome commented on May 27, 2024

Thanks for opening your first issue! Reports like these help improve the project!

from azure-cost-cli.

ilyhel avatar ilyhel commented on May 27, 2024

ty! I will try to specify a resource group name

from azure-cost-cli.

ilyhel avatar ilyhel commented on May 27, 2024

@mivano I try with this command azure-cost costByResource -o markdown -s ${{ github.event.inputs.azure-sub-id }} --query "ByResourceGroup["FinOpsRG"].[ResourceGroup, Cost]" --debug >> $GITHUB_STEP_SUMMARY but I still get the same error Version: 0.32.0.0 Using token credential: ChainedTokenCredential to fetch a token. Fetching cost data for resources... Token retrieved and expires at: 09/01/2023 23:28:50 +00:00 Retrieving data from /subscriptions//providers/Microsoft.CostMana gement/query?api-version=2021-10-01&$top=5000 using the following payload: �[38;5;8m�[0m �[38;5;12m"type"�[0m�[38;5;11m:�[0m �[38;5;9m"ActualCost"�[0m�[38;5;8m,�[0m �[38;5;12m"timeframe"�[0m�[38;5;11m:�[0m �[38;5;9m"BillingMonthToDate"�[0m�[38;5;8m,�[0m �[38;5;12m"timePeriod"�[0m�[38;5;11m:�[0m �[38;5;8mnull,�[0m �[38;5;12m"dataSet"�[0m�[38;5;11m:�[0m �[38;5;8m�[0m �[38;5;12m"granularity"�[0m�[38;5;11m:�[0m �[38;5;9m"None"�[0m�[38;5;8m,�[0m �[38;5;12m"aggregation"�[0m�[38;5;11m:�[0m �[38;5;8m�[0m �[38;5;12m"totalCost"�[0m�[38;5;11m:�[0m �[38;5;8m�[0m �[38;5;12m"name"�[0m�[38;5;11m:�[0m �[38;5;9m"Cost"�[0m�[38;5;8m,�[0m �[38;5;12m"function"�[0m�[38;5;11m:�[0m �[38;5;9m"Sum"�[0m �[38;5;8m,�[0m �[38;5;12m"totalCostUSD"�[0m�[38;5;11m:�[0m �[38;5;8m�[0m �[38;5;12m"name"�[0m�[38;5;11m:�[0m �[38;5;9m"CostUSD"�[0m�[38;5;8m,�[0m �[38;5;12m"function"�[0m�[38;5;11m:�[0m �[38;5;9m"Sum"�[0m �[38;5;8m�[0m �[38;5;8m***,�[0m �[38;5;12m"include"�[0m�[38;5;11m:�[0m �[38;5;8m[�[0m �[38;5;9m"Tags"�[0m �[38;5;8m],�[0m �[38;5;12m"filter"�[0m�[38;5;11m:�[0m �[38;5;8mnull,�[0m �[38;5;12m"grouping"�[0m�[38;5;11m:�[0m �[38;5;8m[�[0m �[38;5;8m�[0m �[38;5;12m"type"�[0m�[38;5;11m:�[0m �[38;5;9m"Dimension"�[0m�[38;5;8m,�[0m �[38;5;12m"name"�[0m�[38;5;11m:�[0m �[38;5;9m"ResourceId"�[0m �[38;5;8m,�[0m �[38;5;8m�[0m �[38;5;12m"type"�[0m�[38;5;11m:�[0m �[38;5;9m"Dimension"�[0m�[38;5;8m,�[0m �[38;5;12m"name"�[0m�[38;5;11m:�[0m �[38;5;9m"ResourceType"�[0m �[38;5;8m,�[0m �[38;5;8m�[0m �[38;5;12m"type"�[0m�[38;5;11m:�[0m �[38;5;9m"Dimension"�[0m�[38;5;8m,�[0m �[38;5;12m"name"�[0m�[38;5;11m:�[0m �[38;5;9m"ResourceLocation"�[0m �[38;5;8m,�[0m �[38;5;8m�[0m �[38;5;12m"type"�[0m�[38;5;11m:�[0m �[38;5;9m"Dimension"�[0m�[38;5;8m,�[0m �[38;5;12m"name"�[0m�[38;5;11m:�[0m �[38;5;9m"ChargeType"�[0m �[38;5;8m,�[0m �[38;5;8m�[0m �[38;5;12m"type"�[0m�[38;5;11m:�[0m �[38;5;9m"Dimension"�[0m�[38;5;8m,�[0m �[38;5;12m"name"�[0m�[38;5;11m:�[0m �[38;5;9m"ResourceGroupName"�[0m �[38;5;8m,�[0m �[38;5;8m�[0m �[38;5;12m"type"�[0m�[38;5;11m:�[0m �[38;5;9m"Dimension"�[0m�[38;5;8m,�[0m �[38;5;12m"name"�[0m�[38;5;11m:�[0m �[38;5;9m"PublisherType"�[0m �[38;5;8m,�[0m �[38;5;8m�[0m �[38;5;12m"type"�[0m�[38;5;11m:�[0m �[38;5;9m"Dimension"�[0m�[38;5;8m,�[0m �[38;5;12m"name"�[0m�[38;5;11m:�[0m �[38;5;9m"MeterCategory"�[0m �[38;5;8m,�[0m �[38;5;8m�[0m �[38;5;12m"type"�[0m�[38;5;11m:�[0m �[38;5;9m"Dimension"�[0m�[38;5;8m,�[0m �[38;5;12m"name"�[0m�[38;5;11m:�[0m �[38;5;9m"MeterSubcategory"�[0m �[38;5;8m,�[0m �[38;5;8m�[0m �[38;5;12m"type"�[0m�[38;5;11m:�[0m �[38;5;9m"Dimension"�[0m�[38;5;8m,�[0m �[38;5;12m"name"�[0m�[38;5;11m:�[0m �[38;5;9m"Meter"�[0m �[38;5;8m�[0m �[38;5;8m]�[0m �[38;5;8m�[0m �[38;5;8m�[0m Response status code is Unauthorized and got payload size of 156 Response content: "error":"code":"RBACAccessDenied","message":"The client does not have authorization to perform action. Request ID: b72f026f-f1c1-4831-b133-7950fcfefb8a"*** �[38;5;9mError:�[0m Response status code does not indicate success: 401 (Unauthorized).

how do you register the sp to get AZURE_CREDENTIALS? I found this ref https://learn.microsoft.com/en-us/azure/cost-management-billing/manage/assign-roles-azure-service-principals

from azure-cost-cli.

ilyhel avatar ilyhel commented on May 27, 2024

Thank you so much @mivano it work fine now 😊 I remove the scope as you mentioned, still to play with the query parameters, I will try to add more examples to the Query section 😉.
cheers!

from azure-cost-cli.

Related Issues (20)

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.