Azure Bicep Parameters and Data Types

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we learned about parameters in azure bicep [Music] [Applause] [Music] hello everyone i'm travis and this is zeraldos in the last bicep video we set up a development environment and deployed a storage account we're taking things a little further in this video by reviewing parameters along with bicep data types before that please take a second to show your appreciation for these videos by subscribing liking sharing with a friend or casual acquaintance and clicking the bell icon for notifications of new content if you'd like to learn more about windows virtual desktop check out my course zero2hero with windows virtual desktop on udemy.com back at it we're going to get into parameters shortly but we have some formatting items to take care of i know slides may not be as exciting as getting hands-on but trust me this information is important to taking your bicep game to the next level and the slides are in this awesome portrait powerpoint format i recently discovered let's get started with data types there are a lot of key value pairs in a bicep file matter of fact that's almost all we create in a bicep file but there are different types of values in the key value pair in the last video we had to define the type of storage the key was kind and the value was storage v2 notice the single quotes around storage v2 that indicates the value is a string there are other data types including an integer a number with no quotes if quotes are added it becomes a string boleans have a value of true or false again no quotes we also have secure strings these are just like strings but the value is not saved or logged in any deployment history we'll use these for things like administrative passwords on a vm for a secure string the at symbol followed by the word secure and then open and closing brackets is the modifier that indicates the string is secure an array is a list of values there are two examples on the screen one is a list of integers that one has no quotes the other is a list of strings an array starts and ends with square brackets there are no key value pairs it's just a list of values and finally we have objects an object is simply a list of key value pairs everything in a bicep file and an arm template for that matter is an object the one special property of an object is that the value in a key value pair can be another object when we created the storage account we added a sku name as a value for sku the value for sku is an object because the sku has a second property of tier the nesting of objects is one of the things that can make arm templates tedious to work with bicep abstracts most of that out but they still do exist let's move on to parameters in the previous video we created two storage accounts the storage account name was a value of the resource because storage account names have to be globally unique we had to change the inline value of the storage account name when we created the second storage account that isn't a problem for small templates but for large implementations that could be problematic parameters make the templates portable by providing a single location for settings that will change with each deployment with parameters it's easy to reuse a template a value is assigned to the parameter once and then referenced throughout the file parameters also give us input validation we can set conditions for the accepted parameter for example we can set a minimum and maximum length on a string or add an array of allowed values we'll use parameter decorators or modifiers to restrict the parameter input or set default values the allow decorator is an array of allowed values a description explains how to use the parameter while metadata is a custom property that can be equivalent to a description the minimum and maximum length apply to arrays or strings while the minimum or maximum value apply to integers the secure modifier marks the parameter as secure so the value is not exposed in history or logs the demo coming up will pick up where the last one left off we'll start with our storage account bicep template and add some parameters we'll add parameters for the storage account name and we'll add tags we'll also include default value for the tags and the storage account kind let's get started in vs code with our storage account bicep template if you don't have that check the link below for a copy here we are in vs code with our storage account template i'll make this file available on my github repo if you need a starter file the link will be below let's start with a parameter for the storage account name go to the top of the file parameter should be at the beginning we'll add some spaces for the parameters parameters start with the identifier param spelled p-a-r-a-m after that we need to give it a name this example will use the name stgactname this is the symbolic name for the parameter we'll use this name to reference the value of the parameter in the file you can name it anything you want we still have a red squiggly line let's see what it's asking for we need to assign a type this is a name so let's give it the type string the red squiggly lines are gone and we now have a parameter but an azure storage account name has to be between 3 and 24 characters long it's a string so we can use the min and max length for input validation to make sure that the name is between 3 and 24 characters decorators have to go before the parameter let's add the min length modifier here it shows we need an integer so we'll add three that will be the minimum length we'll go to the next line and add the max length use the at symbol max length and that is 24. now the storage account name has to be between 3 and 24 characters now that we have the parameter we have to update the resource to use the parameter go to name under the storage resource remove the value of the name and replace it with the parameter stgact name and intellitype picks it up so we just have to hit tab notice there's no parentheses just the parameter name let's add the parameter for this storage account sku next we'll add a new parameter add pram followed by the name this example will use stgactsku that's also a string we don't want someone mistyping the value or maybe you want to limit the options available we'll use the allowed decorator let's add that above the new parameter add sign and allowed if we tab it will auto add the opening and closing parentheses next we have to add a list of allowed values more specifically an array of values since this is an array not a single item we need to add it between square brackets add an opening and closing square bracket between the square bracket we'll add the list of allowed values i'll include this list of storage account names in one of the links below or you can just add a couple be sure to include standard lrs for the next step however if you've worked with arm templates you may be used to putting commas between items in an array that's not required for a bicep file let's add a default value next a default value is what's used if it's not overridden during the deployment we'll set the storage account sku to the default value of standard lrs we can override that with another value from the list when we deploy the template but we don't have to we can leave it blank and standard lrs will be used to set the value we simply add an equal sign after the string and add the default value i'm going to copy and paste that in next and again we have to update the resource so it will use the parameter remove the sku name standard lrs and replace it with stg act sku there it is in the list next we'll add a tag parameter and update our resources to include tags start by adding a new parameter called stg tags this time the data type will be an object a tag is one or more key value pair so it has to be an object we'll add a default value so add an equal sign at the end after that we'll need an opening and closing squiggly bracket now we'll add our objects the tag and value pairs this example will use environment lab and department it next we need to add the tags to the resource this was an optional setting that we didn't use previously go to resources and at the end add tags and pass in the stg tags value we're done modifying the file so be sure to save that all looks good except for one thing we created a parameter for the storage account name but didn't include a default value this is on purpose storage account names have to be unique so adding a default value wouldn't be helpful after the first deployment we're going to pass that in along with updating the storage account sku at the deployment so let's do that next open up the terminal and be sure to log in we went over deployments with powershell in the command line interface in the last video in this video we're going to stick with just powershell be sure you're logged into azure before we start and the cursor is at the file location or you'll have to specify the path in the following commands let's start by creating a resource group use the new az resource group command passing in the name and location bicep test rg and central us for this example once that's done let's deploy the new storage account start with a new az resource group deployment command adding the name of the deployment and the resource group we just created after that add the template file parameter passing in the name of the file we just updated next we need to add the storage account name we're going to pass this in as part of the deployment add a dash stgact name and if everything's working correctly that should autocomplete we'll give it a name for this example i'll use cir storage 22331 remember this has to be unique so i just added a couple random characters at the end you can name your storage account whatever you'd like we also want to change the storage type to standard zrs add a dash followed by stgactsku after that add the value standard underscore zrs once finished hit enter it looks like something went wrong the deployment validation failed i actually did this on purpose the storage account sku is typed in wrong and does not match the allowed value that's an example of how input validation with the allowed decorator will prevent somebody from adding a value that's not allowed let's update the value and run it again there we go and if you get a different error message one indicating that it cannot find the storage account name parameter try updating the az module i ran into this problem with the 5.6 az module and updating to the latest version fix the issue keep in mind bicep is still in preview let's update the command and run it again this may take a second to finish this is a good point to pause and come back once it's done once finished let's get the account and verify it's what we expect run the get easy storage account command passing in the resource group and storage account name the name looks correct let's pipe the output into a format where we can see all the details fl for format list i'll make this a little bigger here the storage account and resource group is correct and we can see that the tags have been applied it doesn't show the skew with this view we can view that with the same command only outputting extended properties let's assign the value of the command to a variable called stg from here we can get the skew by getting the variable dot skew dot name and there it is that's how to create and use parameters in a bicep file i hope you found this video useful please don't forget to like and subscribe and thanks for watching
Info
Channel: Travis Roberts
Views: 1,030
Rating: undefined out of 5
Keywords: Azure, Bicep, Azure Bicep, VSCode, VS Code, extension, Azure CLI, Bicep CLI, storage, azure storage account, Bicep tutorial, azure tutorial, training, free training, PowerShell, .bicep, azure bicep tutorial, azure bicep vs arm, templates, data types, allowed values, parameters, secure value, default value, azure tutorial for beginners, microsoft azure, what is azure
Id: NoUyJYVsK2s
Channel Id: undefined
Length: 16min 23sec (983 seconds)
Published: Sun May 23 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.