Azure Bicep: Authoring Experience

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone and welcome to another video on this channel in a previous video i looked at bicep and how to deploy bicep templates with azure devops in this video we're going to take a closer look at the authoring experience with visual studio code there are no further slides involved we're just gonna dive in and start showing you how the authoring of bicep templates works let's get started and i made a screen somewhat bigger so you can hopefully see clearly what is going on now suppose i want to create a resource group and within that resource group i want to create a network with subnets and then maybe a bastion host how do i do that that's still a relatively simple template but this is just to show the authoring experience right so let's get a go get started and create first of all our main dot bicep file now you heard me say i want to create a resource group yeah that actually means that we also have to set the target scope the target scope by default is a resource group in this case target scope equals and i can do control space that will be a subscription i want my resource group to be created but i want the resource group name to be also a parameter so i'm going to define a parameter rg name that's going to be a string and i'm going to set a default value just an example java r g then to create the actual resource group you have seen it in previous video that was the resource keyword and then a symbolic name and then the authoring experience uh makes it easy for you to select the the type of resource you want to create in my case i can just start typing resource group and there you'll see the different api versions that resource group supports i'm going to take the latest one just press enter and then set the properties of this now you see these quickly lines here by the way i used sdg that's for storage account i'm going to use rg as you can see here there are some squiggly lines because the resource declaration is missing name and location so i'm going to set the name of the resource that's the name in azure that the resource will will get that's going to be the name of the parameter so that's very easy we just have the parameter there the location i'm going to hard code now so i'm going to just set west europe as a location now what else can you do well suppose i don't know then i can just do control space there i can see oh yes i can set some tags on this resource group so i'm going to set text colon and then you see this this expects an object currently braces so just press enter and then i can specify the text for example i want the tag called environment and i want to set this to death right this should be enough actually this this is already a working a functioning bicep template that at the subscription level deploys a resource group now we're ready to create the network now we're not going to use a resource we're going to use a module so we have to create the module first so let's add a folder called modules and then create a module called v-net dot bicep there now to create the actual network we are going to use indeed resource over here i'm gonna call it symbolic name v-net and i'm gonna search for virtual networks um yes there we have it that's the latest api version then equals and then of course the curly braces now what do you put inside this this module well of course let's first look at the squiggly lines yeah name is something that i really need so let's pass in the name of the v-net now i want this module to have a parameter as well for this v-net name so v-net name is going to be a parameter and that's going to be a string so the name will be the v-net name how easy it is to work with parameters and then use those parameters inside a bicep file what i also need is a location so the location and i'm going to use a resource group function for that and the resource group function i can use location property location to retrieve the location of the resource group i'm creating this v-net in and you'll see later because my target scope is subscription you'll see later how i can set the scope for the v-net to the resource group but that's something that you will see in a moment now i'm a little bit lost i don't really know what to do now okay yeah control space to the rescue of course and yeah there's something like properties for our network when i'm using a colon here i can see yeah i need i need the curly braces so just enter and then again i'm i don't know what to do just control space again so you'll see me do that several times control space to find out more or less what i need to do of course you have to have some experience with these resources in azure to know what you need and what you really don't need that of course takes some some time and some experience to get that to get that right in this case we're going to keep it simple i need to need an address space for my vnet this address space is also just an object and then that one has i don't know control space address prefixes and address prefixes is up that's an array that's an array of of strings now i don't want to set the address prefixes to an array i just want to pass in one address prefix so okay that's limiting it a bit but that's fine so i'm gonna create a parameter here called v-net address uh prefix that will be a string and i'm going to just use that v-net address prefix over here now this does nothing for my for my subnets so um okay how do we do the subnets well let's see under address space what else can i add control space ah yes there we have also the subnets property that's indeed also an array that he expects and this array is something that you have to set as follows you have to create objects in here and then you're to specify for example the the name of the subnet etc now i want to make that a little bit different um because you have to type the name for example like this oh that's wrong wait that was a bit too simple yeah and then you have to type again you have to type properties and then within properties you have to use the address prefix again so this is how you supply the subnets now what i want to do is i want to make it a bit simpler and i want to pass in my v-net subnets with a simpler array that just contains items that have name and address prefix so i'm just declaring an array parameter here right and i'm not going to use this this thing over here that i don't want to use so i'm going to i'm going to delete this and i want to iterate over the items in my array now within bicep you can do that with a for loop so i'm using a 4 here and then i can take a variable i'm going to just call it item for item in v-net subnets right and then i can pass in my object now this object of course has to be formatted like a subnet should be formatted so it's going to have the name of the subnet but that will be the name of the item that that i find in my for loop and then of course the subnet has properties and that has an address prefix and that's going to be item address prefix and you'll see later of course how i pass in this v-net subnet's array from main bicep to v-net bicep let's see if all the curly braces and so on are fine let's do it like this yeah i think we have them all here yeah that's that's indeed correct so this defines uh or this creates a resource of type v-net a virtual network with an address space and then subnets within that address space but i pass in the subnets with my own array that just contains a name and an address prefix so that simplifies the parameter passing a little bit let's just save this and see now how we create this v-net from within main.bicep now we have the v-net module created we have to see how to use that module so that requires the module keyword also a symbolic name i'm going to use v-net and then the auditing experience is clever enough to give me the modules folder and then the module one of the modules within that folder so all the rest is the same we start adding properties to the module control space can help me here yes i need a name as well yeah i'm going to set this to a v-net givea here i also need a scope and that's important because the scope for my main.bicep is a subscription level scope but the v-net needs to be created in the resource group that i created so i can set the scope of the module to the resource group i created and that is of course rg that's a symbolic name of the resource group that was created before and of course it's a module so we need to add the parameters to the module so when we type enter here and then we do control space we can clearly see the parameters that the module expects i'm first going to set the v-net name and i'm going to use the same name as above there so i'm going to use v-net java here i also need a v-net address prefix let's make it simple here and just do 10 dot dot um 30.0.0.16 doesn't really matter and then of course it requires the subnet so subnets in this case is an array an array with items in it that have a name and an address prefix property so i need to provide these items over here and then i'm just doing the following thing i'm specifying uh the name here so the name is for example i want to have a servers subnet it doesn't really matter just an example and then the address prefix now there is not really suggestions here so that that is not that is not part so you have to know what you use in your in your array the address prefix for this subnet is uh going to be let's make it simple again 10.30 dot let's see yeah doesn't matter like this slash 24. now i am also going to create a bastion host bastion host requires a subnet with a specific name the name of that subnet should be azure bastion subnet so i'm gonna call this azure bastion subnet and the address prefix is going to be indeed the 10 dot 30.2.0 24 again just an just an example so with this we actually call our module our v-net module now what we're going to do here is we're already going to try and deploy this because there might be an issue here that that we are not working properly so let's just go to the terminal um i already am authenticated to my subscription using the azure cli so we are going to going to do a deployment of the main bicep file here we can use the azure as deployment sub create command for this so at the subscription level we are going to submit this this template template file i don't have any specific parameter that i need to set here because indeed i have a default value for my resource group i could override it of course by using the uh parameters option there oops this one i'm going to clear out and then do that again so i'm not setting i'm not overriding the parameter rg name let's run this and see what happens all right now that didn't work and that's okay i'm just leaving it in because i made a typo here i set it to address proxy whatever that is so that's of course not correct and that's something that the add-on clearly reflects that that is something that just won't uh won't work so let's go to address prefix here let's save this and then deploy this one again and this deployment worked properly so you can see the output of the actual command that i just just ran so let's check out in the azure portal if we really did provision all of this and here we are in the azure portal we are at the research group geva rg there we see our v-net that was deployed and of course yeah the resource group was also deployed by our bicep template if you look inside the v-net we see that two subnets were created servers and then the azure bastion subnet now it's time to deploy the bastion host now similarly to the v-net we are going to use a module to deploy the bastion host now i already created this module for you that we don't have to go through all the steps of typing all that text here the authoring experience is the same now in this case of course in our bastion module we expect two parameters the bastion name and also the v-net name in which we want to create the bastion host now a bastion host also requires a public ip so within the same module we create that ip as well so the resource of type public ip addresses we give that ip a name we concatenate ip dash with the bastion name we pass in as a parameter and then the rest is all the same a location an ip requires certain properties and also recommended today is that the sku is of the standard type so this creates that creates a ip address a public ip address for us to create the actual bastion host we create a resource of type bastion host here and again same thing it requires a name which we use a parameter for the resource group location is set and then these are the specific properties for a bastion host so a bastion host takes ip configurations each ip configuration has a name and an ip configuration has properties in this case we need to specify the subnet that our bastion host will use remember we created this azure bastion subnet subnet during the creation of our v-net now important here is that in the properties of the subnet the resource id is required for that subnet and i actually don't have that so i construct it here by using the resource id function resource id function takes a parameter for specific resource type in this case subnets and then we want a subnet in the vnet with vnet name that we passed as a parameter and the subnet that we know is going to be called azure bastion subnet because that required so this returns a string which is the resource id of the subnet now our bastion host also requires this public ip address yeah that's just the resource id of the ip we just created that's of course easy to get to because we have the bastion ip symbolic name here we can just retrieve the id using bastion ip.id and then we set the private ip allocation method to dynamic i think that's the default i don't really have to set that here this is just making it a bit more explicit now what do we do or how do we now create the actual bastion well that's of course very easy let's just just do that once more one more time drilling it in so to speak so i'm going to use the bastion module going to modules and then bastion bicep and then we're going to provide it with the properties the name of the bastion host you know what i'm going to just use this yeah that's going to be it the scope is the same as before that's going to be the resource group and then the parameters to my module and that's easy we know that there is with control space a bastion name i'm going to use the uh bust geba here as as there are well ways to do this cleaner but i'm just doing it this way and then the v-net name well actually the v-net name um i want to just illustrate that we can use something which is called outputs as well so the v-net was created in our v-net module now when you create something you can have an output for it so in this case i can say v-net and then outputs and then the output in this case i've chosen to output a name property so v-net output's name as you can see yeah it's giving us some squiggly lines there because it doesn't exist well let's first indeed just save this and have an output in our in our v-net here so if we go to our v-net dot bicep at the end we can specify outputs we want to we want to give this is just an illustration so in this case i'm saying okay the output let's make it simple is it going to be the name that's going to be a string and what is going to be the output well in this case it's really simplified just the v-net name that we use here but it does illustrate the concept of outputs so if my v-net module is outputting a property string i can refer to the output of my v-net creation by using v-net and then outputs of course i get help there and then i can use a dot and it knows now that there's a name output and remember we use the vnet name in the parameters for the bastion host because the vnet name is required to retrieve the id of the of the subnet now again for you advanced users out there there are other ways to achieve this this is a relatively simple way to do what we needed needed to do so this is it i'm going to again deploy this and see if my bastion host gets deployed my subnet and so on already exists as we're using the incremental method this should normally add the bastion host to my existing deployment so let's try and do as deployment subcreate again and run this and see what happens it takes a while before the bastion host is created but after a while in the resource group we see indeed that the bastion host was created when i click on the bastion host i can see that this is indeed in the v-net heber network nandi azure azure bastion subnet and this concludes our look at the authoring experience of bicep templates in visual studio code i hope you like this if you have questions of course do leave them in the comments and i see you some other time bye
Info
Channel: Geert Baeke
Views: 314
Rating: undefined out of 5
Keywords:
Id: 1UsHwwX4wx0
Channel Id: undefined
Length: 20min 16sec (1216 seconds)
Published: Wed Apr 28 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.