Highlight
Started up as manual extraction, evolved into PowerShell scripts, serverless Functions and ended up as Logic Apps. Read how this great service solved our business need for just 3 cents a month.
Introduction
When building cloud solutions, it is very important to manage ongoing costs. As such almost any company in the world which has Azure as their cloud provider has some sort of billing reporting solution. Our company is no exception here. This is a small story of how our solution for automated billing evolved over last few years.
Evolving over time
About three years ago our company moved from Pay as you Go to Enterprise Agreement for Azure. Initially we were exporting reports once a month manually via ea.azure.com but we quickly moved to Power BI Enterprise Azure connector to get all billing data. Later due to unknown reasons Microsoft removed connector from Power BI platform and as such we decided to develop complicated Power Query formula which was downloading all billing data using Enterprise Azure API. This was working fine for almost two years until Microsoft rolled out new API known as Azure Consumption API. For some time our old API was working but this year it stopped working.
This meant, we again had to rewrite the Power Query to use new API. While we could still do this using Power Query, we decided to try moving this to something more operationally sustainable. We initially decided on PowerShell hosted on Azure Automation. About 100 lines of code and running on Azure Automation every day downloading the data to Blob Storage which is used as source in Power BI. And this worked fine and still does but I personally felt this could be easier, so I wanted to try out different approaches. In just two days I had recreated entire flow as Azure functions.
Developing in Azure Functions is always fun for me, I’ve been coding most of my life. But even then, I felt like some simple tasks required multiple lines of code where it shouldn’t. An example of simple task like this was conversion of JSON array to CSV, while simple task and many libraries do it, it still can’t be achieved natively in C#, or that you needed either durable functions or multiple functions with queues for parallelization, etc. 200 lines, 2 queues, nice asynchronous patterns, fan-out logic, key vault integration and all felt amazing.
At some point I thought… I wonder if Logic Apps could do it… and so it began…
Benefits
I wanted to try Logic Apps because
- Logic apps do iterate in parallel by default; no need to do fan-out with queues or durable functions
- Logic apps support asynchronous (202) patterns and pooling scenarios extremely well out of the box
- Logic apps have out of the box action to convert JSON to CSV
- Logic apps connect to all sources and KeyVault using MSI
- And recently logic apps allows for obfuscattion of secrets
- There is no code with logic apps that we will need to maintain
- Logic apps logging and debugging is extremely easy
Therefore, I began working. To my surprise… I did entire thing in about an hour!
Design
Design consists of multiple components to ensure that while this application is small and simple, it must also be secure and reliable.
With following components
- Logic App - main function logic for pulling data
- Storage Account (Blob Storage) - storage of CSV data (CSV because it contains more data per MB than JSON)
- Key Vault - storing EA keys for API, authentication is done via MSI for Logic Apps
For the consumption API following endpoints were used
- Billing Periods
- Usage Detail pooling based asynchronous approach with CSV output
- Marketplace Charges with JSON output
Flow
Below flow uses Logic App which is executed every day after midnight at 3:00 in the morning and downloads all the billing data.
And this is how “big” it is… or is it?
Only 14 actions were required to complete this task.
Provisioning
You can quickly deploy entire application using ARM or by yourself using Azure portal.
One Click deployment
If you want to deploy everything with a push of a button simply use deploy button below.
- Click on the Deploy Button
But Logic App refreshed only last 2 months?!
Logic App only refreshes last two month since older months do not need to be refreshed as the billing will never change. In case your company has EA already for longer than two month, then
- Go to Logic App editor.
- Find the value 2, which can be found in in the For each billing period action as expression take(…) and simply change it to bigger number, and run it once.
- Remember to change it back to 2 afterwards.
And that’s it!
Last 30 days show consumption of 0.03 EUR per month.
Conclusion
Logic Apps are not the cheapest service out there, but when used correctly they solve business challenges in no time and at ‘no cost’. Used as the right tool for the right challenge they fit perfectly here. I’m glad I did try them out because this is the perfect solution for our company.
Source Code