So coming back to the main terra form file, Let's do a little exercise and get you a little hands on.
We want to go ahead and update the name attributes for the resource so that in, instead of having a hard coded value here, we're gonna have the value of it be derived from resource group name and whatever that variable value is, and we're gonna go ahead and we're gonna save it.
and so it was a pretty easy process for you. Hopefully, in the auto complete capabilities of the I d. Really helped you get a full bearing off. What are all these variables in this context of the Terra form file? The resource group name.
Just playing around with this for a second. So I show you a little bit more about the an object.
Here's an object, and then you can see I had another dot and I've got port in protocol. So when we were talking about, If you have more structured input variables and and you want to try to create a hierarchy tomb, the object type is very powerful. Of course, you can make lists of objects.
You can create collections if you if you really want to get exotic as well.
There are several other types of variables that I didn't cover or providing the examples in the reference guide on the get home page, I included a link so you can see the full terra form documentation regarding variables and the different types of variables
if you're so interested to explore. But the ones I did cover, I think, or your bread and butter
that you're gonna be using quite frequently
final stop before we actually start doing some terra form work. Let's just take a little look at this vey net item this resource that we're defining and specifically let's start breaking down some of the the attributes in the value so we can see the location for the V Ned Resource. The value is not hard coded string.
In fact, I didn't use Varda location,
which, you can see we did here is we said I want the location of this virtual network to be in the same location as the resource group that we've defined up here. So this is an example of not an input variable so much as I'm making a cross reference
using RG as variable and the structure
between the different resources and entities within my terra form file. Similarly, the resource group name. I want this V Net to be created in this resource room up here. So rather than hard coating it or in this case, even rather than
daily, they're doing the bar. I'm going ahead and I'm just going to say reference the value of name
from that entity created up here, the RG entity which is of type resource group. So you can see now we're creating inter relationships between our different resource is and so a big value in doing it like this
is when we run terra form and it's doing its thing, it'll actually calculate their relationships between the resource is
so that it creates things in the correct order. And obviously that's going to be very helpful when we have interdependencies within the resource is such as a resource is that belong to an over our king resource group.
So let's move along
and give this a shot with what we've created here would open up the consul and I'm gonna make sure I've changed into my working director to be the 02 variables directory
and I'm going to run good old Terra Form and Nick's because this is a new working directory of no longer in the 01 basics directory. So the contents of this have not been initialized. And when we can see the tzar R M provider plugin has been downloaded as a result of that innit process.
Next, I am going to run terra form plan just to get a feel for how things were going and immediately you'll notice
that I'm being prompted to define the value for a variable called resource group name. If we come back up here to the variables, you may recall that that this we didn't define it a default value for this particular variable. We just gave it a description. We didn't even define a type
to be honest.
So because it no, wait a minute. This is a variable. This variable is being referenced by the resource is right. It was important. Variable. I don't have a default value. I need a value for this variable. So it's prompting me to enter enter the value. So I'm just gonna call it ah manual
dash R g
as a value in this context, it's Go calculate the planet's not actually gonna create anything here, and then it's gonna show me. Okay, what is this gonna be actually doing if I wore to run the apply process? And sure enough, it's creating a resource group with the name manual RG
located in the West US to region.
Ah, and it's also creating an azure resource manager. Ah, virtual network. Excuse me. Ah v Net, which a NCO, incidentally, belongs to the resource group manual dash RG and is located in the West us to region. So
let's talk another second about why we would want to do variables
like this and input variables. Let's say we had this terra form script and we wanted it to be reusable such that we had had different customers and maybe we wanted the resource group name to be a reflection of who that customer waas.
So there's a few different ways we can do that
and to find that with one approach would be to go in here and just define default. Value equals customer one. That's one approach that we could take
if you think about concepts of continuous integration and continuous deployment and having terra form scripts run, not manually like we're doing in these lessons. But by ah bite by a program such as a Jenkins or get lab C I or the desert pipelines.
Editing the files in a script, A Matic Ways is really not a good practice. So terra Form provides a few other capabilities around. How you do this, one of them is creating what's called referred to is is a t f ve *** file.
So I'm gonna create a new file in the Variables directory, and I'd like youto
to follow on and and we're gonna call a customer one dot t f bars. Okay, that's that's the extension there, and the contents of it is gonna be very simple. We're gonna say resource group name and nice to have that auto complete equals customer. One
customer one. Okay, so now what we've done is we've defined this, um, this value. And if we come back to terra form
and we say Okay, you know what? Show me the plan again. Terra form a plan.
It's gonna prompt me again for the resource group name, right, because we don't have a default value for this particular variable.
Now I'm gonna cancel out of that, and I'm gonna go terra form plan. But I must say, you know what? Look at this variable file.
Their file equals customer customer
And when I do this,
you'll notice I'm not being prompted for a value of that variable because it's reading in the value from the variables file that I specified on the command line. And sure enough, the name of the resource group is going to be a customer. One. What's also interesting And and I guess of note
is if I were to go back and edit that the TF bars file
and say, You know what? We don't want to put this in West us to that. That's the default. But we want to put this in East us,
and then I would run the plan again. It's actually gonna override the value off
the variables location file that is West us, too. And it's going to use the value that's in TF bars and so, sure enough, there's East us.