2 hours 48 minutes
we're gonna be talking about variables here and like we're doing in there, all the other modules we're gonna be doing in a very hands on fashion looking at terra form code. So I'm gonna open up the zero to directory on variables associated with this lesson and all the lab materials
and take a look at the main
terra form file. I really quick review. As you can see, we have the provider being defined at the top just like we did in the first module. 4.1. We have the resource group being defined down here, and then we have an additional resource.
This is a virtual network
resource you don't need to be in His. Your expert, just understand, is very common within cloud providers that you create a virtual network and then typically you will put servers or other service's. And resource is that need on? I pee in that virtual network too
isolated and kind of
segmented from everything being directly exposed to the general Internet. So that's what we're defining here is the virtual network. But putting our focus again on the variables,
you'll notice that the location, which is the region that the resource group is going to be created in is is actually doesn't have a value like we had in our first logical here. We had West us to It was a hard coded string value,
but in this circumstance it's actually making reference to
a variable using the var dot location. So there's a variable called location, so the value of location for the reserve resource group is going to be. Whatever the value of the variable location. Now we've only been creating.
We only created to terra form files of both. Very simple. This is a very simple wanted, really has to. Resource is one provider.
Careful Miles can get very big. And so it's. It's a very good practice to divide up the content of your terra form files into different files, they only to reside in the same directory. But when terra form commands or run,
it's going to scour that working directory that the commands running it
and look for all the dot t f files. And it's gonna when it's building its map in its planets, gonna load up information from all those different files. So in this circumstance, what I want to do is I'm gonna open up the variables dot t f file. And it's a very common convention to define all of the input variables
that are going to be used and relied on by your Terra form script
in a very file called variables dot t f. Right. And so these are the the input variables, variables who values They may change, and in fact, we're going to go through that very exercise of changing them here in this module.
But but, by and large, these air we want to get away from hard coating and writing hard coated strings hard Could numbers where possible if we're going to be reiterating that same value in multiple different situations. So in this particular case,
we have used the location, and we've only used it once.
If we were to be creating a more exotic terra form file Ming creating multiple resource groups, but we wanted the doll be in the location instead of just putting west us in there once and then putting it in there again, we're just gonna reference it by a variable.
You'll also see that there's some values in making these variables. If it's the kind of thing that we will want to change an override, the value without having to go in and muck around with the main
terra form file. So coming back to the variables Terra form file,
we're listing out the variables you can see. The construct is a pretty straightforward here. Variable, and then it is the name of the variable. In this case, it's resource group and then you have your brackets and then you have certain attributes so you can provide a description. It's not a required attributes, but it is.
Ah, very good practice. So you're keeping track of the variable with this name. What's his purpose? What? Since intention
moving down, we have another variable defined here called location. It's the name of the year. Is there a reason that the resource is gonna be created in?
We've also defined a default value. So we've created an attribute for this variable called The Fault in the Values West. Us too. And then finally of note, we have to find a type and we've said this thing this variable, the values need to be a string.
Okay, that that is that is important. So I want to do is is variables have typing is just like in any other programming language. You can define types and constraints for the variables, and I'm not gonna go exhaustively through all the variable types. But let's spend a moment to touch on the different
types variable types that we may want to use that that you're probably gonna use in a practical sense
and get exposed to here, certainly within the course of this lesson. So there's a number type that's pretty straightforward here have to find a deep all value of two. There's bullying where it's going to be a true or false. There's a list. So this is where we have a collection off
different and numerous values. In this case, I've created a list of strings. It could be a list of bullion is it could be a
A list of numbers, right? Those air, also referred to as primitives strings numbers billions, but a list is as a collection or or an array. Some may call it a set is very similar to a list, with the unique caveat that
no two elements of a set are the same. So if I were to type in west us two on West us to really this set on Lee has one element to it. And the value of that element is West us to In this case, I've got two unique values to find.
So this said has two unique elements
now with the list. If I were to go west, us to SUS to East us this actually still has three elements, and the order in the location is gonna be exactly as we've specified here.
Finally, this is a very powerful one. It's you're creating an object. So when you have inputs and variables and values of those variables that you wantto establish a little more of a hierarchical structure to for a variety of reasons, this is going to be, ah, very, very helpful construct to manage that information. So
just put, simply here we have to find an object variable called an object.
The type is an object. And within that object, it has two attributes. One attributes of this object is called port, and that is a number type and the other attributes is called protocol. And that's a strength. And then, of course, in this block here, I've gone ahead and defined the defaults for the an object. Variable
port value is 80 and protocol is H t T P.