Bonjour hi welcome to another episode of cloud in five minutes I'm Frank Boucher
and today I want to show you a quick tip to make your deployment work every time
so your code is ready is done and now you want to deploy it in Azure to see if
everything is working so you took your script and PowerShell or either CLI and
you're running it let's see this one oh no it happened again
that name is already taken okay you could just add a digit zero one zero two
zero true until you find that one that nobody took well it's not very nice you
could also use a variable something random and add it at the end of the name
but the problem with this solution is every time it will be a new string so if
you under redeploy this web app then you're screwed
because the name will have changed your solution is to use an arm template for a
sure resource manager let me show you an arm template is just a JSON file that
describe the structure so here I have the unarmed template the describe just
exactly the same structure that would have been created by the azure CLI
script of course if I run this arm template I will have the same error
because my app is running that demo app name so in arm template you have many
different functions because it's not adjacent fine it's like a JSON file you
have multiple resources at your disposal let me show you so for example the one
we want to use right now we'll create suffix and add it to the end of our name
so let's create a function another function a variable so if I want a value
of suffix to be process in the arm template I need to put it between square
brackets so just like that and I want to use today unique string and if we look
the definition UNIX string we'll take a few parameter and create a unique string
great so what we will be using is the resource group
I D because we're always deploying in a resource ID and that should be unique to
her case to be even more sure if we're deploying her solution and multiple data
center a different location we could add location also
so just had here the resource group and then location what yep so screwed up
location voila and now I have a suffix that will
be unique I just need to add it to my name if I'm using it right now for
example if I'm creating a storage I may encounter some problem because storage
required only lowercase so you know what let's put a lowercase so to do that you
just need to add to lower and to the war will take a string and put it in
lowercase very simple right excellent now I have a very long unique
string maybe I would like to have something shorter I don't want to like a
big blob of letters I want just like a little suffix maybe five character maybe
ten character it depends on you for this demo I will take five so let's do a
substring if I can spell it correctly
substring and substring will take the string to parse and x2 where it start in
the land perfect so we'll go here and then we'll start from the beginning zero
and we'll take five character long great so now I have a five character long
lowercase string that will be unique for this deployment excellent I just need to
use it so to use it we'll go back in our app name variable and we'll just put
everything between square brackets just like this and we'll use the function
name concat
so concat concat if we're looking that definition we'll take a few string and
just put everything together excellent so first we want a string demo
app and then the second string will be our suffix that is available in
variables so just like that I want to use suffix and I'm closing my concat
great so now everything works so let's try it so first we save excellent and we
go back to my script so now to create to use an arm templates is very easy you
just say AZ group and then you will say deployment I'll say create and we'll
give it a name so let's say the name will be used to
retrieve your logs in the portal so let's just test and then I will use the
same resource group that I had previously and of course I will need to
pass the file so what did I did wrong deployment oh I have a typo here and I
need the template file and in my case the template file was unlock alert and
what's called azure deployed that Jason so like this I sure did Chloe that jason
and just like that if I execute this I should have my solution
excellent it passed obviously so now let's go in the portal check what we
have so now we have it demo with the RB MD oh that is a unique string that I
have been generated the beauty of using an arm template is by default if let's
say I want to add a storage then I add it to my arm template and if I redeploy
it nothing will happen to my website since it already exists just the storage
will be added with this quick tip your deployment should work every time also
if you know more about the arm template have a look
to that video also output in the description a few links about arm
template thank you for watching