ARM Series #2: Creating Your First Template

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to the DevOps lab demystifying arm templates this series on this episode we'll get started with arm templates we'll figure out what tools to use and we'll deploy our very first arm template and today we have a very special guest Neal Peterson welcome to the show Neal tell us a little bit about yourself and let's dive in and get started with arm templates thanks a lot abel for having me my name is no Peterson I'm a senior program manager and I work on the VSM code extension for authoring arm templates okay so first things first right before we get started with the arm we probably need the right tools so what are the tools you like to use when you start building out your arm templates yep so there's several out there really the one that I'm gonna focus on is just the Asha resource manager tools for vyas code so I'm envious code right here and we can see that I've got as your resource manager tools and if you want to see that on the marketplace we can just do a kms ford slash arm tools and we've got some Doc's and some other things as well you can get to the github repository from this page so if you do have issues with the tools or you need to ask questions this is a good place to do that cool cool so I just install this tool this extension and vs code and I should be ready to go yeah you want to see how it works absolutely idea and beyond that let's just go ahead and you know create a very basic arm template and look at the structure of an arm template and like you said we'll go ahead and deploy it okay so I'm just envious code here and I'm just gonna create a new file and I'll call that Azure deployed out JSON okay um so now it's armed templates are all in JSON um it's Jason likes so I like to refer to it as the arm templating language it's built on JSON but we've added some additional things like looping conditions and some more programmatic things to it okay so India's code I've got this JSON document in fact noticed down here that this code has recognized the language type as JSON um and that's pretty important we'll see why here in just a moment um so I'm gonna use the villa's code extension to scaffold out a very basic arm template and to do so and really when I say basic of a bare-bones arm template so in this JSON document I'm going to type in arm and then an exclamation point and what we have here now is a scaffolded arm template and all of the different areas that we use when deploying arm templates now we're gonna go through some of these and in more depth in future videos but just really quickly I'm gonna walk top to bottom and talk about some of these things so here on line two you see schema and this is really like the version of the arm template or another way to think about it is the scope of our arm template so I'm actually gonna play around in here it a little bit by default we've got deployment template JSON and this is assuming that we're gonna deploy this template at a resource group and when we're targeting a resource group there's a specific set of resources that can be be deployed to a resource group I'm gonna go ahead and delete that I'll just hit control space and we can see some of the other schema versions that we can use here so we can create arm templates that can be deployed to a management group or a subscription or a tenant and based on the scope you know we've got access to different types of resources and that's what this schema defines if it's a it's a JSON document that defines all the resources that we can include in the template when deploying to that scope so it defines our scope okay the next thing is a Content bird this is really just a an area for you to version your template so if you've made a major change you might change this content version to two um the next thing down here on line four we've got parameters so when we're deploying a template you may want to have like user inputs like if you're deploying a storage account which we're going to do in this video you might want to input the name that you want to give that storage account and we define those here the next thing we have is functions and a function is basically it gives you the ability to create your own functions within an arm template so let's say that you like have a complex method for naming resources that concatenates a couple different strings and perform some other logic to arrive at a resource name and you use that throughout the template in many different places rather than repeating that logic throughout the template we can just create a function that returns that properly named resource name and consume that later in the template cool the next thing we have is variables very similar to parameters but we don't allow you to input a value for a variable so this would be like maybe you know I've got a specific storage account size or storage count SKU that I want to use across my templates I can define that as a variable and if I change that rather than having to go to all those different resources and update that SKU I can just change it in the variable on the next section is resources and this is where we define the resources that we do want to deploy in Azure and this is where we're gonna spend all of our time in this video and then finally outputs so if there are things that I want to output to the screen during a deployment I can define those in this section but it's a little there it's a little more powerful than just outputting data when we get into like more complex deployments where we're chaining a series of templates together we can take the output from one template and use it as the input into a parameter in another so a couple different of the use cases of outputs okay alright so we've got a very very bare-bones template right here and now this is a valid template I can actually deploy this template if I wanted to in its current state however nothing's really gonna happen because we have nothing to find in there alright so let's go ahead and add a resource and I'm actually going to use a capability of the vs code extension to add a storage account in here so with the BS code extension we've got snippets for a bunch of different azure resources so I'm just gonna type in storage or sto R and you can see there that I've got arm - storage I'm just gonna hit enter and what this does is it puts in a valid the valid arm templating language for a storage account into the resources section now I can use the tab key to tab through this snippet and update a couple things so let me just give this a name I'll call it learn arm 0 0 1 and then if I hit tab you can see I'm now on line 16 at kind and I can like arrow through the different types of storage accounts I can change some other things but I'm just gonna leave it at that ok now looking at this resource here we've got a couple of different common things that we're gonna see across all different as your resources or requirements for defining a resource and a template the first is a name so I've given it a name that's pretty easy to understand that's gonna be the name of our storage account the next thing when we're defining any resource in a template is we need to specify the type and in this case we've got Microsoft storage and then storage accounts next line down we've got the API version so as we update the capabilities and properties on these resources the resources themselves get a new API version so we're just specifying which version of the storage account we want to create tags are gonna be the tags that we put on the resource once it's deployed to Azure and then we've got a couple other things but these are kind of the big ones that you're gonna see across all as your resources um now this is ready to go but I think what I'll do is highlight a couple other little things that we can do is we're offering resources when we create our templates and these are capabilities that the BS code extension gives us on the first thing is validation so notice here that I've got a kind of storage v2 let me give this on value like a non valid value so let me do mega storage and notice here that now my kind has a little yellow squiggle under it what it's doing is it's indicating like hey this is not a valid value for this property on a storage account and you can see there in the message that it does list out the valid values um so that's an example of validation validating our templates before we deploy them so let me now get a list of valid storage account kinds so I could put my cursor in these double quotes here hit control space and it provides me a completion list of storage account kinds and so I'll go ahead and select storage v2 now let's uh let's say we wanted to add some additional things to this storage account let's see what we can do I'm gonna add a comma under SKU a carriage return and again hit control space and this is gonna bring up a list of configurations and properties that I can add to this storage account so let me go down to properties I'll hit colon and I'll do the same thing here and we can see the things that I can configure inside the properties for storage account let's just go ahead and take a look at this supports HTTP traffic only hidden : and I'll hit true so you can kind of see how the LEAs code extension allows us to author these resources in kind of an intelligent way all right so now we've got our first arm template very basic we've defined a storage account we haven't messed around with parameters or variables or anything we'll dig into those and in a future video let's now go ahead and see what it looks like to deploy this thing and so I'm going to open up the integrated vs Code term there are actually several different ways that we can deploy arm templates we can use the azure CLI which I'm going to do here we can use PowerShell we can actually use the azure portal if we wanted to um so again we've got a couple different methods for doing it I'm gonna go ahead and create an resource group that we will deploy this a template into again kind of going back up to what we talked about earlier this is a template that's scoped for a deployment to a resource group so I need that resource group so I'm gonna I'm gonna use the azure CLI to create a resource group so I'll do a Z group create name and I'll just give it the same name as the storage account here and then I need to pick a location for it and I'll do us [Music] alright so we successfully created our resource group and now I'm gonna deploy this template into that resource group and again the end result is that we should have a storage account in that resource group when we're done so I'm gonna do easy deployment group create and what I want to feed into this is the name or the look the location and name of the template file so I'll do template file as your deployed JSON and then I need to give it the name of the resource group that we want to deploy it into so learn arm 0:01 go ahead hit enter and some now the adversity Ally is is locating the arm template file and deploying that into the resource group that we've just created and while that happens I'm gonna go ahead and pull up the portal and we'll just take a look at it once it's been deployed and there is the resource group and we can see that a deployment is in process now but it hasn't completed and we can also watch the progress here as the azure CLI works cool all right cool now we can see that the deployment is succeeded so let's pop back over to the azure portal I'll go ahead and refresh this damned it's there's our start account very cool man all right that wasn't that bad at all right so creating our first template not too hard especially with that extension I have got to install that extension now trying to learn arm all at once it can be a challenge but on this series we break it down one piece at a time so you can easily learn all the ins and outs of arm town for more information about on templates click on the links below we also have links to our github repos that has all of the stuff everything that we're doing and all you devs join us next time as we dive into parameters forearm on the dev ops lab [Music]
Info
Channel: Azure DevOps
Views: 2,870
Rating: undefined out of 5
Keywords:
Id: YqoiR5HDhSo
Channel Id: undefined
Length: 14min 38sec (878 seconds)
Published: Tue Jun 30 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.