Adafyn kuulumisia

Azure ARM Templates vs C# vs CLI #1: Background

<p><a href="https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-authoring-templates">Azure ARM templates</a> allow you to automate your environment setups. But with a cost. Dealing with the long JSON-files is hard, even though there are visualizers like <a href="http://armviz.io/">ARMVIZ</a> available.</p><p>What can we do? In this series I’ll explore the options for automating your Azure environment setup.</p><h2>Background</h2><p>If you can create a completely new and fresh Azure environment for your system with a click of button, with everything deployed automatically, you’re in the happy land. If you can’t and setting up the environment requires some manual work, <strong>you should aim to automate the process completely</strong>. If you run the automated process twice, we want to end up with two identical systems but with the following differences: Each installation should have <strong>their own passwords and own urls</strong>.</p><p>ARM in Azure’s context stands for <a href="https://azure.microsoft.com/en-gb/features/resource-manager/">Azure Resource Manager.</a> The key scenarios for ARM, as defined in the documentation, are:</p><ul><li>Deploy resources together and easily repeat deployment tasks</li><li>Categorise resources to clarify billing and management</li><li>Enable enterprise-grade access control</li></ul><p>We’re mainly interested in the first key scenario: How to automate your deployment.</p><p>When we use ARM, we’re using <strong>JSON based ARM-templates</strong>. We deploy the JSON-file, which Azure Resource Manager then converts to REST calls and the REST calls create the required resources. The key thing is that we only have to care about our JSON-template, ARM takes care of the rest.</p><h2>Problem</h2><p>ARM templates are great because they allow you to automate the environment setup. But they come with a cost: ARM templates tend to grow to these huge, almost monstorous JSON-files which are hard to understand and to maintain. And as we know, <strong>maintanability is the key</strong> when we want our systems to have a long life.</p><p><a href="https://github.com/Azure/azure-quickstart-templates">GitHub has a great source</a> for templates. You can create simple and complex environments with these templates, ranging from something simple as <a href="https://github.com/Azure/azure-quickstart-templates/tree/master/101-vm-simple-windows" target="_blank">Windows VM</a> to <a href="https://github.com/Azure/azure-quickstart-templates" target="_blank">MongoDB high availability</a> installation. But if you look at these templates you can easily see the problem: the simple Windows VM is 179 lines of JSON. MongoDB is 500 lines.</p><p>Personally I think that the problem with ARM templates is obvious: <strong>The templates try to use JSON in a situation where it isn’t build for.</strong> In theory you can use JSON to describe your environment. But to actually make things work you need some concepts from programming languages:</p><ul><li>Variables</li><li>Conditions</li><li>Loops</li></ul><p>XML and JSON are both great ways to describe static data but they fall short when you try to “programming languagefy” them. ARM templates aren’t the only one with the same problem: If you check the JSON-file behind the Azure Logic App, you usually find a mess. If you try to use text editor for editing a Mule ESB flow, you will encounter problems.</p><h2>Options</h2><p>Given that the aim of an automated environment setup is great but ARM templates are hard to maintain, what can we do? I personally believe that <strong>instead of trying to make JSON to act like a programming language, we should use an actual programming language.</strong></p><p>So instead of using an ARM template to describe your environment, you create a C# console application to describe and to create your environment using <a href="https://github.com/Azure/azure-libraries-for-net" target="_blank">Azure Management Libraries for .NET</a>.</p><p>Or if your environment is simple, you can use .bat-files (<a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest" target="_blank">Azure CLI</a>) or Powershell scripts (<a href="https://docs.microsoft.com/en-us/powershell/azure/overview" target="_blank">Azure Powershell</a>) to automate your environment setup.</p><h2>Conclusion</h2><p>This post was aimed to give you the background. In the following posts I will explore and compare three options for automating your Azure environment setup:</p><ul><li>ARM templates</li><li>Azure Management Libraries for .NET</li><li>Azure CLI</li></ul>