Time to Dive in
I’m one of those guys that likes to learn by doing. Reading the documentation is great, and I do that a lot. But for me to really grok something, I need to play with it, run it, and probably blow it up.
If you missed part 1, read along and come back. I need a WebApp setup for my sample project. I realized I can do it a few ways. Some of the ways are very manual, some are repeatable, but one stood out to me.
- Create the resources in the Azure Portal
- Create the resources in Visual Studio when I right-click Publish
- Create the resources via a Powershell script
- Create the resources via the Azure CLI
- Create an ARM Template, create the resources on deploy, or via the CLI
Let’s Write an ARM Template
I know what I want to do, write an ARM Template. Do I have any idea what I’m doing or where to start at this point? No. Fortunately for me, Microsoft provides a BUNCH of resources to get you started. There is an entire searchable quickstart page with examples (backed by a github repo) as well the Microsoft Docs on ARM Templates.
Well, I found one in the quickstart: https://azure.microsoft.com/en-us/resources/templates/101-webapp-basic-windows/. From this quickstart, I can click Deploy to Azure, fill out some information and I’ve got an App Service Plan and a Web App. This is so cool. Now to tear this thing apart and figure out what it is.
Ok, Lets play with an ARM Template
In the github repo it looks like there are 2 or 3 files that make up the ARM Template.
Lets dissect azuredeploy.json. Schema, version, blah…
My eye is drawn to the Parameters section. I recognize some of these from when I deployed to Azure. Getting a feel for parameters I see you can have metadata describing them, types, lengths, and default values. This gives me lots of ideas and options.
This isn’t your mama’s json. That looks like a function to me! Looks like somebody got their code in my json. I like it. A quick google later and I see a huge list of template functions in Microsoft’s documenation. I’ll come back to that. In the mean time, those variables look a lot like the name of the webapp and AppServicePlan. I can work with this.
Meat and potatoes. Jackpot. This looks like where the resources are defined. Only a few properties on each, an apiVer, type, name, location, sku, and a few others. I also notice one has a “dependsOn” property, I bet I can build up what depends on what and it will do everything in the right order.
I’ve got an ARM Template now that works. I’ve poked at it a little. Time to make this thing fly. Lets setup an Azure Repo on DevOps and see about trying to deploy this thing and create my webapp on release. I want to be able to check in a change and have it create/update my resources in azure. Next time, we start the feedback loop.