5.1 Inputs

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or

Already have an account? Sign In »

Time
2 hours 48 minutes
Difficulty
Intermediate
Video Transcription
00:00
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
00:18
and take a look at the main
00:20
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.
00:39
This is a virtual network
00:41
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
01:00
isolated and kind of
01:02
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,
01:15
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,
01:34
but in this circumstance it's actually making reference to
01:38
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.
01:56
We only created to terra form files of both. Very simple. This is a very simple wanted, really has to. Resource is one provider.
02:01
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,
02:19
it's going to scour that working directory that the commands running it
02:22
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
02:42
that are going to be used and relied on by your Terra form script
02:46
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.
03:00
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,
03:19
we have used the location, and we've only used it once.
03:23
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.
03:38
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
03:50
terra form file. So coming back to the variables Terra form file,
03:54
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.
04:14
Ah, very good practice. So you're keeping track of the variable with this name. What's his purpose? What? Since intention
04:20
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?
04:30
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.
04:46
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
05:06
types variable types that we may want to use that that you're probably gonna use in a practical sense
05:13
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
05:30
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
05:36
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
05:53
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.
06:11
So this said has two unique elements
06:14
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.
06:28
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
06:47
just put, simply here we have to find an object variable called an object.
06:51
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
07:11
port value is 80 and protocol is H t T P.
Up Next