two clicks way too complex I wanted one click so that's what I did
Bonjour Hi, welcome to this new episode of cloud in five minutes I'm Frank Boucher and today
I want to show you how you can give the power to your user to deploy whatever he
wants using nested armed template and conditions
most solution contain multiple parts and all of those parts have their own
deployment cycle and live circles and sometimes we want to deploy just the
back end and sometime just front end and sometime we want everything to the be
deploy at once so that means we need multiple deployments structure and it's
painful so what I want to show you today is how you could write the cut once to
deploy and give the Liberty to the person who's deploying to pick whatever
it wants and everything will be fine and rested let me show you so in this
project easy URL shortener it's your open source
project that I have on github so all links will be in the description to the
documentation to the github repo and way more so have a look in the description
in this project what I did is I was really looking forward to make something
simple where the user could deploy everything that it wants so this use a
back-end that use Azure function and the front-end right now only have one it's a
web app that I did in blazer but you could run at less without any front-end
and you just calling it from postman or any tool you have or you could build
your own tool in whatever Python or JavaScript and call my API that's
whatever you want so I'm gonna give the choice to the person to deploy just what
it needs but I wanted to make it simple right now it was yes you could deploy
the backend one click you wait and then the second the front-end click and then
you're done two clicks way too complex I wanted one
clicks so that's what I did so if you click it will open the other portal and
now it will just go here and I had a parameter called front-end and in this
parameter would let me just first selection and then I will zoom so in
here what it does it gives you the option you could pick one or you could
pick different and you want in your case it
could be anything you want like it could be okay I'm on this package blah blah
blah you decide what you want with that of course you will need to pass more
parameters since you're deploying multiple source you may you need to
cover all those entries without those input so you have more inputs to you
know send at the beginning I want to show you how I did that using nested
armed template and some condition you will see it's very easy so let's go in
the arm template so this is my arm template I have two armed templates so
one for the back end one for the front end like I said and both will still be
able to to work independently so what I want to do now is add this new power
that we need that that will switch our condition so let's go here and we'll
just had it quickly I will explain so my parrot er is front end you name it
the way you want now the strategy here is to allowed only some values and
that's really important that's why you have the list or the drop-down menu in
the portal and that way you will be able to put some condition and you know the
expected value so it will be much easier that way my case again none in website
it's a good idea good best practices to put a default value because everybody
likes Next Next Next Next Next Next when they deploy and also put the description
because it may be clear for you what your intent to do with that but good
guess is it's not that clear for the end user so put as much clear instruction as
you can I will need to add the extra new parameter so let's just add that quickly
voila so I needed Annie and I mean email and a password for my interface perfect
so now I have all the input that I need theaters maybe already have the value
maybe I will generate that when I'm deploying for example in my case the
front end required the URL from the azure function that's not problem I
could retrieve that and I will show you how I did it so now what we
is to add this nested deployment so we'll go here and we'll go straight at
the end of her arm template and we'll add a new resource this resource will be
of type Microsoft resource deployments exactly right you want to do another
deployment inside the first deployment so you know it's kind of inception here
an important point is the depends on so make sure like your second deployment if
it has any dependency that those dependency are done deploying in my case
it was really important that not only the function app was deployed but my
function where define so I needed the synchronization between github in my
case and the get inside app service was done so I needed to also add this source
control in my dependency then resource group API version we're used to that
mode could be new for you so like the deployment mode is really interesting
very powerful right now it's using incremental that means when you're
deploying stuff it won't touch any resources that are not specified in this
arm template if you are changing the resource there's the same name something
then you will hack otherwise it doesn't care and it's also very powerful because
if you're deploying in mode complete an empty arm template you could delete all
the resource inside your resource group without losing your resource group so
that's pretty clever when you're trying to clean up without losing the security
and all the setting you did on your resource template but that's another
video the second let's clean that a little bit voila
boom so here template link and kind the main course of this activity so what we
do here is extract the URL from a variables and I will show you that
variables in two seconds but the template links what's important
is to understand it needs to be a URL or UI it cannot be a local file this way
you will be able to reach out and if they have security you could have the
Tok he will be able to get your second
template and deploy it you could also use the inline so if you're injecting
full object you could have inline code there but I prefer working with armed
template in a file so both deployment can be individual if I want let me show
you the variable so I will jump on the top of my screen in the variable so
front end just here so what I did I created a variable called front end info
and it will be a kind of an array of different objects so right now I only
have one object and it's the admin blazer website that match the variable I
have on the top so this way that's how I I can do a inside this take the object
name admin blazer website and give me the parameter or the value of the member
arm template URL so if I add multiple object I could do that
so you could have an object and then use that dynamically so see again that's the
main object the main variable name is called front-end info I want to go get
the object with this name matching the value of the front-end parameter and
will get the value of arm template so let's go again in the arm template to
see the value so see here I'm extracting the front-end info variable getting like
it's between square bracket here getting the value of the parameter front end so
get me the object and from that object so now I have like the object I can go
then pick up the property arm template URL that's how it works and then we have
the parameter so you know you pass the parameter that you already have in here
or here I'll just concatenate a new value to my
base name just to you know may sure the name have some kind of link
connection but they are not the same for the function URL that's a little bit
more complex let's go through it I will explain what I did so i'm concatenating
the URL and for me that was really important because my front end will call
those api is those function and i need to know exactly the URL with the
security code because my function are protected so that's what I did so let me
switch I have a little code snippet will be easier that way I'm cooking
concatenating for information so the first one HTTP that's kind of a classic
and now I'm building that reference I'm referencing my website and I'm getting
the O's name the O's names are Inari right now what I'm doing is I'm
extracting the blah blah blah as your website dotnet domain name so I need
that that could be cool as a URL for the function app but I want a specific
function in this case I was really looking for the you our URL list that's
the function I want to call and I'm already starting my query string to
retrieve the value of the variable code and that's for me the security key or
the token that is built in Azure that will be done using the new function
inside our template called list keys and again I will be Konkani T like getting
information from function app and let's zoom again for the end of the
information I will go then check in the O's default extracting the function key
default and that will be my security token that I need with all that together
now I have my complete function URL and I will be able to pass that to my
deployment so inside my config or whatever I will have those URL and then
my front-end will be able to call my back-end so cool so now we have all the
template but now you may tell yourself Frank now it will be deploying all the
time there is no condition here you're right and let's fix that
so what I want to do here is I will add a condition so to do that so here I do a
condition so very simple here it's a function of arm template so I use that
and you know when it's not equal to none when the front end is not equal to none
then it will be executed otherwise we'll just the full resources will be ignored
so very useful so of course the condition could be simpler more complex
it depends on you I know it's a lot of information and one shot very condensed
and an arm template it might be difficult to see on your screen so
that's why I put inside get up a folder name to toe and inside of it you will
have a before/after subfolder where with the two arm templates so this way you
could compare and see the difference and understand by yourself but you will see
at the end it's very simple I had a parameter I had a deployment
resource and the magic was done so I hope this video was useful for you if
you have questions notice is they to write it down in the comments or come
see me on Twitch so at twitch.tv slash f Boutros i stream live coding twice a
week and you can ask me their question and that's when we work on project like
this as your URL shortener so don't forget subscribe click the bell icon all
those things leave a comments it's always very appreciated and I will see
you next time Thanks
you