Transcript for:
Understanding Terraform Variable Management

oh okay so let's look at varable definition files and they mostly end with an extension dot tfv f so last week we looked at variables five which are variables mostly referred named variable. TF it could be TF TFI that's fine so it must not be variables. TF just FYI so in this variables. TFI we Define the variables that our resource need so we Define the variable blocks that represents arguments needed by whatever resource we are trying to to Define being created VI terraform okay so if you remember you have your V TFI and uh um inside you have your variables block you define the name for the variable and values for the variable so that's the variables doy there is also a definition another definition inter form with the extension can you go back to page one let me take a snip go so on please okay thank you thank you so in the variabl definition files are files with extension anything dot TF so it could be um Franchesca doas um Victor whatever you want toas you're going to see examples in what what we're going to do and this file is mainly used for it's mainly used for assigning values to the variables defined in for example our variables do TFI does it make sense yes sir no it doesn't so what am I saying I'm saying that if you make our thing here is we want hello yeah not copy can I go ahead sure yes [Music] sir so if you remember we let's say we want to create an E2 resource okay so an is2 resource this is2 resource is what it needs an Ami before we defined a variables. TFI we defined a variables. TFI and inside this variable. TFI we have a variable block that says what variable um Ami ID or something like that remember and we Define the value of our Ami to be uh um something something in our account long string yes yes so I'm just trying to demonstrate here in here in this Val TFI we have given or we' have passed in the value of the Ami we want to use so this works however we can Define this and now remember in the east2 resource in order to get this um um how do you call it this um Ami ID you're going to do a VAR the name of the variable block and the local value so if we call this a VAR variable. Ami then we are going to say a we going to say Ami the Ami here will refer to uh um V Dot whatever name we give to this block here to this variable block so it be V for example in this case Amore ID so this would pass the value from our variables file into our is2 resource using the default value that is set in our variables file but this becomes strou uh troublesome if you want to use this same block of code for multiple environments because we are already passing the value inside the variables file does it make sense so let's say let's say I want to use the same block of code to Def to create an EAS to Resource um a test environment in the production environment or in the development environment I have a problem here because if I want to use a completely different Ami in my production environment it becomes challenging because I am already that um uh value in my variables. TFI however I could Define variable that I need for my resource can you hear me yes sir yes sir getting you can Define the variable that you need for your resource in the variable. TFI and Ami which we need so this Ami value we would remove it from our variables. TFI and we put it in another value call it you can call it um umio what your audio is going in and out I think I don't know but for me too now we've lost you completely no I'm here okay needed by and values t or whatever file which we are calling and has the extension do T in then Define the values for for the very defined in the F does it make sense yeah yes so far I think it's easier when you see see it in action yes I think so so Prof so what are we going to enter in the variable. TF file because if you remove the value from the T TF file and you put it in the TF uh tfv file what are you putting in in the TFI in the TFI we Define the variables that we need for the resource and in the T file we put the values for those variables you remember when you're defining variables you have variables you have a a type you have a default which you're passing the values for that variable so in this not using the default again whatever value that that variable needs we put it in the TF V FES and when you do a terraform plan terraform is going to um um assign all the values in theti val files or pass the values from theti Val files and the variables intf FES together and before uh uh uh uh creating your resource does it make sense yeah makes sense but why will you separate them so there's a big of of doing this I already said for example if we are using the same configuration to deploy resour for different environments then we have a problem because we already passed for example in um share my screen and maybe it makes sense to you it would make sense to you I expect it to why are you saying like that can you see my screen yes sir what do you see little small though but we we see your I think it's your vs code good so look at this can you make it a little it's a little small X thank you so we want to use um t f and normally this is the resource which we are creating right we can also call this V T let's call this V anything you want can you help me please so it means I need to go Define a variable called tag and string and default value so what did we call that J Tech instance or see test whatever instance so in here in our variables. TFI we are defining the um variables that we need for our resource so this would be our resource our isource can you help me move Please Mr Z hey Z give me a second I mute him that's okay let's go ahead he's muted so we we are def variables needed by our resource in our variables. TFI and we are calling variables in our resource this works if we p f or this variable which is what we've been doing so far this is also great and if we do a terraform in it and if we do a terraform in it and plan terraform would be creating our our resources using all the values that we Define here but let's say we want to use the same configuration to deploy to multiple environments then we Face a problem because we've already defined find all of those valubles in here if I deploying this to the same code to my test environment to my production or to a development environment and I want different instance sizes then I have a challenge defining the specific instance size which are need for the specific environment do you see that yes ma' alen because we've already said that the instant size which we need for this should be T2 micro so I can deploy this for my um first first deployment into my uh test account I have a T2 micro if I want to deploy into my uh how do you call it my production account or my production environment then I'm I already passed in this value in the TFI so the better approach to to do this is we remove all the values in our varable in our TFI and we pass all the different values in a TV file so so if I do a plan let's see what happens for the plan you can see we are creating an easy to in and the instance type size we are defining here is T2 micro so that is taking away instant size now we want to use a Tas F so we remove all the values we Define in our variables file we Define all those values in our TF vs F so we're calling it here terraform tsvs F there's a I I come to that point later so this is not a t ver five this is not how it looks the one on the left good this is yeah so now I'm passing the variable the the the values for those variables if you if you see the variable is called instance type it is called E2 AMR and it's also called T so in the five to pass another value for the variable called tag and what T what what name were we giving it we're giving it um value of this that make sense so now when we want to do terraform in it let me change it to T T3 micro just so you we can see the difference so this is my values my resource and my values. TF if you want to use a a TF v f you need to pass it with a like um tell terraform which values F to use in order to create your resource with a command line flag know called v f so you can see that if I do a terraform plan now I will say use the VY that is equals to in this case Terra form the TF vales so I expect it now to create an instance of instance Ty T3 micro so so you have a a tfvs for different environments right you have a TF V for different exam enir exactly and you pass it as through your plan picking the one environment you want exactly quite nice pardon it's quite tidy doing it that way yes so if you have this so you can see the first thing we want to do uh uh get across is using the Tas f now how do we use the Tas fire now to deploy into multiple environments so if I have because for example you can have a project that has seven environments I think I me to you guys I have one project that has seven environments and two weeks ago they asking for the eighth and we do not want to be carrying or repeating the same block of code um in those different environments or those different repositories and pipelines all we are doing now is if they're using the same resources we are only changing the class five and we set up the pipeline to pick the specific T CL that that represents the environment in which we want to build does it make sense yes ma Pro what if you don't pass the v file which one is it going to pick up okay good question terraform if you have a tfv file with the name terraform TF with a deep exact name called terraform or something do O2 terraform I show you give you a second then theform is already is going to use the values that see if ter plan here I do not pass in the values the the TF fire as a flag it should still pick up the values in my in my TF VY because it is called terraform it has this prefix terraform if the prefix is something different from terraform T VY then terraform is not going automatically you will need to specify the V the T VY for it to use Pam are we good yes sir following yeah we're good Franchesca lesie this concept is very important if I'm understanding um on this T FES we we State the values that we specified from the TF and TF like let me see what do you have here the instance Ami from the variable TFI right M so in the variables in the TFI we are defining the variables in the TF F we are we are we're giving the values to those variables okay Pro my question is um what if you don't pass the flag and what if you don't pass the flag which one is it going to pick up that's what I'm saying if you do not pass the PL but you your tfv f with a suffix terraform so it's called terraform is going to automatically know that you want to use the values called in this terraform T versy however if the T ver fire is named something like t t versy then that's a problem because theform is not going to Auto automatically pass form is going to ask me information coning the you break for a for a second you will pause for a minute yeah we didn't hear you for about 20 seconds actually unless I think I should restart my router let's see if it persists what I'm saying is um my V asked that if I do not pass you can still see my screen right yes yes if I do not in the TF V fire in the command line will terraform know where to get those values that there are two um ways if this is called terraform the T V is called terraform TF Vance then terraform is going to automatically use the values that are in the TF v f we okay yes please I need everybody to understand this because if I get you in an interview and we talking about terap I'm going to ask you a question that how do you set up your terap code oh my God you were breaking up we didn't hear it yeah audio is really how do you yeah it's been like ongoing okay give me a second I Chang set um internet connection okay all right okay okay stop the recording for a second while he does that streaming from your pleas so what uh I was saying is M asks that if you do not pass in your TF 5 in the command L flag how would terap know which way to get those values so I said terraform If You by default name your TF v file with the name terraform the prefix terraform then terraform knows that I'm terraform then terraform uses that that P to pass the values with the uh uh variables which you've defined in the TFI however if you call the value the T by Theta T you can see it well let let's let's let's do it with terraform so you see what I mean where is rename so if you if I call this terraform tfy and I do a plan you should see that terraform would automatically use values that are in my my T.T file to combine that with those variables in order to Define uh create my resource so here it would not ask me for any uh uh input however if I rename this to something else TFS for example I call it francesca. TFS hopefully that's how it's spelled and I do a TF plan terraform would not know where to get those values is's going to start asking me to give those values can you see that yes bro so now that he's asking you what do you put for the value if I so now it's it's it's in the command line it's very clear it's telling you that there's a variable that it's using called v. e2. Ami enter a value for that variable so you put it but normally you will not be able to do this right you should not be doing it like this then there's no way for you to automate the the the the scenario now in order to tell terraform where to get those values then we use the flag dovi so I would do pro was the previous one what we call environmental variables no that's different um Prof that means you cannot have a terraform um TF bars file and an another one say dev. TF tfvs file at the same time you can have you can you can now if you did not specify dev. tfas then terraform is by automatically going to use the terraform Tas file so that's way you can have default values you understand what I mean okay okay so what I hear you saying sir is if you have the T the terraform tfv file in your folder and there are other tfv files in there it's important that you explicitly specify that when you run the plan exactly otherwise it will use use the default it's otherwise it's going to automatically use the the the file name which it knows the terraform F make sense so if I want to use now my what is it franisco I will do a plan and I must tell ter form where to get this value using the flag uh uh dvy so dvy now will be equals to what's the name Franchesca do TF files theti form should be able to use the values in my d f combine those with values in my variables file and create my resource oh are we good yes one time again pardon can you please take it all over again good yes I'm here to take it all over this is very important so we can spend the day of today I guarantee you that most of you will face questions relating to how you handle this there are other ways of doing it but this is um very clean approach so you were asking a question and you didn't complete the question so I I was writing it down he said how would you um set up your TF code something something so I believe she's talking about the interview question that you said you were going to ask yeah okay I said if if I if I'm with you in an interview and you tell me that you're good with Tero and stuff like that then I'm going to ask you a very simple question I have uh we don't want to duplicate stuff right we have like five different environments and we don't want to duplicate our terap code how are you going to use the same terraform configuration terraform module to deplo deploy to those different [Music] environments that is a good question so the first thing is you need to variabe your terap code you need to make sure you're not putting any um values values in the terap form code in your base configuration so you start by variz it then it doesn't end at just using variables if you remember last when we started terraform we were just taking the our resource and put and we put all the information in there and we deploy it that was working right then we went further to remove it and put it in variable files and we also were passing those values in those in those variable. t f that's still good now we want to show you how to uh uh um continue the optimization of your base code this makes it really reusable so if I give you this code all you need to do is change the values in this t v f and deploy it into your environment the base code stays the same so it makes us to we write our module just once and we deploy it wherever but we can deploy it now we can customize each environment based on the TF V fire that we want if it's not clear please tell me I would explain it 10 times from different angles so you get it this is very important can I ask one more question sure you can ask so in the scenario where you have several environments that you want to deploy the same base code I uh and you is there a way of say that there are like you said eight environments are you going to individually run these lines of as when you're going to do the plan you will run each one independently is there a way of actually aggregating all of them to launch without you typing in for each of the eight environments I don't know whether you understand obviously we are doing it because we are we using tform CLI we are doing it from our local you would do it in um a pipeline for example and let me let me just explain the approach that we using we are using what we call terraform workspaces in the background so for every we we're going to get to tform workspace next week but every environment we create a workspace with that name for example example there's a workspace called production okay and we would create a t V5 that begins with that the name of that workspace production make sense yes sure do you follow right up to this point yes Ma so in our pipeline there is a terraform command called terap form. workspace that command basically tells you um by default any will get to workspaces once you install Tero and your running teram code there is a workspace that tform creates um by default so you can do it T from workspace Leist and you would see that it should give me a default a workspace with the name default so this is the default workspace so we can create different workspaces we get to workspace and we have a create we can create a workspace C production and if t v fire that begins with a name production production yes yes so in the pipeline I will just tell it that please evaluate the workspace that you running in all right or am I looking at the branch name my my G Branch name is it called production or is it called mean if that is tform do workspace equals production then use the production. tvy does it make sense okay most of those things make sense at the end of our session not not not terraform after we finish with G after we finish with uh with um cicd then I would give you an end to end that you see how all these things work come together so you're basically saying um so this is to do like a pipeline sort of like putting a condition inside a pipeline the pipeline exactly deploying yes it could be so if it's on production use the production T TF vers if it's development use the development TF pass exactly trying to I'm trying to just see if I work space right yes we have to still get to workspace don't worry we'll get to workspace okay your WhatsApp chat is showing the record they wanted to show us the git lab I think if I'm not mistaken okay Pro from what I understand like uh the out the actual valuables for the for the triform would be on the perform TF why the variables should be on v. TF right say that again like like these two like these two uh TR like Francis T T um um V so the actual the actual values will be on Francis T why the values for the variables like why like why why the why the values you use for your variables will be on your valf you put the actual numbers the actual values why on the other one you put just the like right yes you define the variables in thef file and you define the values in the t v f you pass the values in the t v f make sense yeah yeah yeah I get it thank you quick question when you say Define a value is it sort of like explicitly stating the type of variables that like it should expect you would State the type of values in the T file for example where is it if I go to my values file here I'm stating the type so it's expecting a string so what is it variable called tag so the tag variable is a string so it is here where you defining the variable that you're passing whatever constraints that the V variable needs so if I want my variable to be type object then it is here that I'm defining type object so I think you don't you don't is it that you you froze or it's not clear I had um a question regarding the homework I think this is a question that was actually missing that was it a way we could sort of send the tax without having to even though we defining the variables without having to sort of like give it to each and every resource like the S3 like the is there a way we can sort of put it somewhere in the code where he automatically goes everywhere yes there's something called local you can do it and you can just pick it from Locas and you you pass it into your values we'll treat Locas tomorrow so a local file is a file internal form that you can Define um an expression or a value that you need in multiple places in your in your um tone configuration and you just always um refer that in the local file so some might argue that the local does almost the same thing like the variables file but it's actually not the same there is there is a difference what okay so I just thought there was a way where we can write like just you know I think you said TF TF T Define or something to true in terms of like the general I think in the the assignment that you gave us in terms of like generally targeting the resources that were created by terraform in environment I think you gave us a t and I was kind of we could just put that that that at just one place so that we don't have to we don't have to call it every we don't have to call it so that every resource will inherit that tag no every resource you need to pass in the tag that it needs right right but I mean all of them will have the T the TF true or something I think the TF the TF the terraform T but I I was wondering if we could pass it somewhere in the code like there was a place you can pass it where all of the resources will sort of inherit it let's say if you want to let's say if Mr Victor wanted to owner give me a second I could do something like variable right and I see this is my variable. tack and I see the type it's something like an object right and I want the um what is it call uh like terone the the KE is terone was it Q was it t have manag was yes key what was it t TF manage yes key is TF manage and you just Define an object then you can call this the the object the object itself in the um resource that you you you need for you need a t can we not is there a way we can pass it so that we don't have to sort of call it in each and every resource because it looks like we we sort of repeating it because no because each and every resource must supported each and every resource must support the tar argument so I do not think it's something you can you can pass it like um I don't know maybe there's a master place we can sort of pass I was I actually T about a provider but I didn't know how I can pass a you can you can use it there that's not a good place for you to use it so Mo can you can I ask you what's the use case what you're thinking of you don't have to constantly type um TF created and C a variable you don't have to type you don't have to call constantly type it you type it once and you just call it yeah so that we don't have to constantly multiple times that's what I'm saying let's say if we we creating maybe thousands of resources it could mean we might I mean I guess you can put an automation to always remind us to tag or prevent the resource from creating if it's not tag but I just thought there was a that I just thought it might be a way to sort of um put it somewhere so that every resource would just inherit it without having to type it that was um yeah that was the only issue that I was I had with the homework just having to just call it all the time like the S3 um the ec2 and um yeah and the VPC yeah the VPC so the only use case I can think of is if you if you don't want to tag all the resources with the same tag um you know that's the only time I think you can want to just automate it to do it for for all because I mean all of all of the resources are going to still have the all of the resources that we create are going to be TF TF TF created right so I just told if I in fact to solve your problem this specific problem let's just say I want to create this one and I want a map of strings right and um let me say I call it a map of strings for my type of uh value then I can then Define the uh values which I need and I can call what is it called default what what was it TF TF created TF created TF whatever TF manage yes then the value will be true then this will be my v variable. t so if I remove this I can add another value here map of strings I can see um um environment and Dev I can see environment it's a it's a map strings I can see envirment uh or prod or whatever you want to call it then in means now let me what do you call what do you do this okay C so that's gone but here we are passing in the value so this is what I expected you to do so in this case I'm already passing in my V tax so let's just comment this out for now why is he complaining okay because it's it's different so my my tax will be talk then if I do a TF plan now I should ex see those TXS because it's calling a variable called Val tag in that Val tag I'm defining all the values which I need how do we add subsequent TXS let's say to that instance you always have to put in the default just just cas have to come come in and put it in the default or you can merge there's a condition there's a function in in um terap called merge you can merge multiple things so it's merging strings that's way Advanced so you can use a merge function to merge bar. tax local. tax and form is going to merge all those things together and give it into your uh um give those values to your attack make sense yes Pro this wasn't issue this wasn't the issue because we still calling it in our resource I want you have to call it in the resource you have to though there's no way you have to call it in the resource you have to Define it way we can defaultly set our tax to inherit defaultly like um so that all the resources can sort of inherit it without having to explicitly like call it all the time sure uh I can't say no but I I haven't really looked at it but there's something in a c resource tax right so I don't know if that's something we could use because you can use resource tax to tax ta different um as instances but I can I can check but normally this is this is how we we implement this yeah the type there what this is the first time we're running into it the one that that says map string can you just explain that what it's doing it's a it's um um terraform has what we call Value types so you remember we have uh um values that are strings which you've already seen right yes you have strings so you have strings you have um uh terraform V terraform types values so you have strings so you know what a string is and it's always represented with um in quotes you have could be it could be integers right yes sir you have what we call um uh list you have [Music] um maps maps are always going with what we call Objects so a map or an object it's basically defined with key value [Music] pairs so a map or a value is always a value um a type of value that always has what we call key value pairs okay so there's always a key and there's always a value like a dictionary a dictionary is a map so if you look at a dictionary most things you have the key which is whatever word you're trying to to look up and the value which is explaining the uh word which you're trying to to find a meaning right so those are um um basic definition for a map okay Pro so we can use maps and objects interchange they mean the same thing yes terap form in most cases you would in 99.99 cases maps and objects almost mean the same thing okay yes Ma so you have Leist you have integers you have uh strings and you have um there's a a unique value in terraform called a n value new value which is if used terraform treats the argument as not defined omitted so we will see a use case for a new value okay yeah hopefully that was not actually part of my plan I'm learning and oh there's another one called sets it's if if type called [Music] string um list it's integers so if basically you know what an integer is so you can just expand that so we can be able to see the otherin Ian you can close the other like exp it yeah thank you list Maps um sets so is bulling also a type bulling is a type exactly booing values set and another type is bullant values so this our true false right dra FAL values so it's actually called numbers of integers yeah numbers integers M list so a list would just be list if in in in um programming language list are always represented with the um square brackets that's what is happening yeah bracket sorry what be the difference between the map and the object um they have not it's not give me a second it's not very clear it's not very distinct so that's why when you define a map and you define an object terraform always passes it almost the same it doesn't really there's some very interesting uh differences then so a list let's just say this is a list is um I could say one two or I say what list of of you guys started python right yes bro yes you guys discuss uh uh things like this yes this different python types this exactly the same thing right right mhm so I can have a list of string so if you list are always represented like that sets are one two three four yes so this would be [Music] one what what is it one two three three four so this will be a list of numbers right so so it be a list of integers but if I want a list of strings I could say a list of fruits then it will be uh what is it orange Apple Paar apples yeah and stuff like this however now in ter form for me to say I want this type of list I would say my type should be a list of strings so that I can put a default value okay that you see already give me the uh if you have that extension already give me the list of strings so I can say um I could say uh what is it instance type so I could say the list of string is T2 T2 micro T2 I need a comma T what M5 large large D3 micro and the rest whatever that and this would be a list of strings so you need to tell terap from so the type matters you see this type I'm saying that it should be a list of strings this is what defines my Leist square the square brackets and this is what defines my strings inside are you seeing if you come down here I said I want a map of strings what is a map key value P here is a key TF manage the value true key environment value true that's is what defines a map what type of map a map of strings make sense yes which is why they in quotes too which is why they in quotes too thank you sir so so um Pro so for for example the one you have like the list of uh strings uh which is like T2 micro M M5 M5 large can it does it mean that the first instance it creates will be uh T2 micro the second one will be M m5. large is that how no you you need to tell terraform how to use the list of strings if you um um using a list you list have what we call an index beginning from zero so the first value in the list always has an index called zero and the second value has one just like that and the last value has if there are 10 values the IND the last value be of index you can either say for python is you get the index of the last value with index negative one I thing and you could if it's a billion or a million or 100 values in my lease it's almost impossible for me to count them um individually right so you need to know how to interpolate and get those values at the last of it they answer you use the for statement for something in something do this you can for each statement you can use a for Loop so a for Loop is going to iterate over all the values in the Leist okay I don't want us to get to that maybe but but but yes yes when you have a list you can use a for Loop a for Loop will iterate over every values because I'm just saying for X for example if this is my list T2 micro T2 M5 I can say for I or X in my list it means that for every value in my list do this that's what the first statement does simp as simple as that okay yeah the side sideb but important sidebar so I've made a change somewhere that's why my terraform is red because I've made a change and the type of value is not matching yeah ter is complaining check your I think this is the problem I made a list of strings but I'm not passing a list of somewhere yeah so this should be the problem I want a string what the heck inv that okay yeah good good are we okay yeah so now my situation is so issue what solved your what solved your situation what we did here yes as I run the tone destroy now I I started running those command back then remember you know whenever I run it back you create new IP you're switching you're switching you're taking the whole class to something else let's we deal with your later okay any question so far yep no we're good I'm good sorry p um shant Shanta has been very very quiet I'm here Prof yeah you're here are we here physically are you also here mentally and we are all moving in the same direction we together yes your your video is off if that was not intentional because I know you're always having your video on Prince lesie Terry yeah yes Prof we together okay so that is how you use tfas f so exactly we already talked about it but I had um folder here that shows you how to use the multiple TS V five so I have my terraform uh configuration and I have another folder called environment and inside the environment folder I'm defining all the t v FES based on the environment's uh specification so you can see that my base code stays exactly the same I have my is2 my provider my T VY this is what you ask um um who asked the question Victor so this will be my uh um default values that if I do not pass a t ver fire the teror would use the what is called what what is in the F for terraform T however if I want specific values based on the environment then I will tell terraform that please use def um or Pro or test to deploy to deploy to the respective environments Sor can you click on together can you click on your pro. tsvs I just want to see what the content is ah okay just a simple line it's a simple line because I'm defining values it's a value called instance type it means that in my variables. TFI remember in these five variables. TFI there should be a variable that defines that uh there should be a variable defined in that variable tsfi with the name instance type so we can confirm that by going to my variables. TFI and I should see a variable called instance type yep I got it then I my prod T EVS then in my prod T I'm passing those values inside in my dev. T I'm using T2 Nano in my prod I'm using T2 medium in my test I'm using T2 micro so that's how you just change the different um values based on the environment which you want to deploy but this base code stays exactly the same this is really very important Prof will you be able to share these uh different folders just for sample for us yes if you want I can share yes we love as long as we're not revealing any national Secrets no this this folder is all JJ related stuff so there's nothing here I can show you the whole folder if you want yes please because it will help us when we are trying to um create hours and and troubleshooting andig the whole video over again I mean we can do that but it will help sure sure I strongly encourage you guys please devops is all about practice there's no amount of talking I can talk here for two years and if you don't do it you don't get it okay cuz as we talking is very you're talking fast and there are so many things and it's going to be very difficult to screenshot type and all that practice at the same time we go back and do it yeah but problem yes I I'll share it with you there's no problem I'll put it I'll share the the folder with you so this is just my simple can you can run it so you see what actually happens so where am I so I I need to need to CD do dot uh now I need to go to D3 let's go M so if you look in here I have my Base information you remember what the DOT terraform file right it's it it terraform generates this when you run the terraform in need and the lock file we already talked about this and the state is because I run this before and we can back up on all stuff so this is basically the files which we we have in our in our code our base configuration so this is my base configuration this would be my terraform file clean varize so I have my resource which actually what I want to create resource called um um is2 instance and now the provider you obviously know the provider you don't nothing happens without the provider the TFI and I have my variables where I Define the variables that the resource needs so the resource needs a variable called is to Ami which is the Ami needed by my is2 instance and it also needs an instance type so I Define those variables in my variables. CFI now where do I pass those values I pass those values in my terraform my tsv file so I want to deploy for a specific environment so I want to deploy to say let's say the what environment death environment or test environment so I will do a terraform in it first of all to initialize you can still see my screen right yes yes you guys were very quiet I thought my internet is still disturbing is good we're just processing information uh Pro when do we use the init upgrade when I said it um give me a sec let's finish this and I I'll talk about init upgrade and I want to now deploy to let's say what development so I would say I want to do a terraform Plan D DVI equals environment and in my environment folder I have the different v files and I want the vile called what is it dev. TF F so now my dep. t v is using an instant size called T2 Nano so I should sure that my instance size is T2 nanu so that's tells me I'm using the right file my prod. T file us is T2 medium so if I run the same command if I'm deploying you can see that the only thing that's changing is my ts vire I want to use deploy to prod so I will say pro. tsv and now my instance size should be different so because we're running these two different environments we don't need to do an init um multiple times just the one time and then do the plan assuming we're deploying to both uh three environments the dev test prod we do an Emit and then pass the value for the plan for all three environments and then do the deploy if we deploying at the same time or really one at a time can you ask that question again yeah so if we're going to deploy to say we need to deploy to both Dev and test um why we're using the same terraform maybe it's they're all in the same um folder right so we just do an init once and then do the plan for de one after the other de um prod test and do a deploy death Pro test or do we do um each one for each environment one at a time until it finishes then do that then finishes then you do you do each one at a time you need um uh plan and then deploy for each it depends it depends on how you architect this if you if we are architecting this in um our bit pocket or in our GitHub repository we might see that all these different environments are using different branches right right so it will just be at um basically the same code in the same in all the branches and and that's it all right because however I'm I'm I'm not running in it again because I'm using my local and it's still using the same back end the same state the same everything that's why I'm not running in it again but if it's in a fresh State then you have to always run in it so that the providers are the plugins are downloaded and configured I think it will become clearer when we start doing the cicd P plan using GitHub or gitlab um through this terraform um deployment right then and I think we take a break and we will come back we talk about uh um give me a second yes we can look at um we you guys already know Expressions we can look at some meta arguments that uh variables that resources use like count and forish then we can call it a day for today right yes okay and you can give us an assignment too sure yeah and um the first I think today and and tomorrow please by the time we get to next week try to have an understanding of this Basics because next week we're dealing with modules modules is is chaining everything thing together so you guys will need to to be up to speed all right okay what time do we get back from the break so this is in um 15 minutes so three what's your time now 9 856 so let's get here by 9:15 yeah thank you what's name yep I just I just press record then I should share my screen so from next week I'll be we will be a little bit faster with terraform okay hope by that time you're are comfortable so someone can also call it output. TF it like that output. TF yes so output values basically output um attributes of resources that we've created okay output values so output values basically so we not see your screen what you cannot see my screen yes yes I thought you I thought I was sharing can you see my screen now yeah well we seeing your code yes that's what yes sharing yes so output values basically displays um attributes of the resource which we are creating output values uh Define with an output block so remember we discussing uh as for variables you you define variables with a variables block for output you also Define outputs with an output block okay so let's define an output so you just give it the name an output block so let's let's start with um I will just do a copy and paste um just to be sure give me a second I want F do I copy this is this already has my provider is it configured I need to have one here okay find some okay are we together if there's a problem please just pick up yes we are so I'm just trying here to define a resource just like every other resource which we've been defining so far so this is our resource we're calling going to define a web server and we're calling the web we're defining the profile here I don't need to and everything okay so this is basically creating an is to instance called web and I'm giving in the Ami I'm giving it the um t I think this that looks fine so we want to create an output so we are creating a resource called um is2 instance and if you remember when we talked about uh when when when I showed you the documentation give me a second I try to bring browser windows to this section and when we look at the terraform provider for AWS or you can also easily access this by just typing terraform AWS and the result we want which is easy to in this case and the First Resource always takes you directly to the resource which we trying to get and we want an is2 instance you remember when I showed you this I said there is an argument reference and there is what we call an attribute reference are we together Pamela yes yes I remember that good so the argument reference are the arguments that the resource supports are we together there so everything that is in the argument reference Ami associate public iability zones or whatever that is it is the type of arguments that you can pass to the resource that you're trying to create this case and E two instance some of the arguments are optional it means that if you do not pass them when you're creating the resource terraform uses defaults okay but remember um when you're creating the E2 instances we are not passing EBS volumes but EBS volumes are created alongside our E2 instances because there's a default but there reason uh uh it should be an argument for EBS volumes that you want to attach to the E2 instance and stuff that stuff like that so it's called EBS block device so you see it's optional if you do not pass one one is pass for you by default so some of those arguments are optional now the attribute reference is what we want to talk about right now these are the values that the research which you created with terraform makes available to the user how can I see those values if I am running or I am calling that resource from the same um level or from the same directory then I need not use output values I can directly use Expressions to get the attribute which I need however let me explain what I mean by us using an output block to see the type of things that we need for example an easy to Resource I think this is an easy to instance right is it easy to yep yes and is2 emits an ER in for the E2 instance do we want the is2 instance ID we can get it with the E2 instance ID and how how do we get that value so if I create this resource and I this normally should create my output value my is to instance so I'm pretty somewhere else good from init this directory so they should initialize my directory so this is an am I got 8 85 I hope this Ami is in the region that I'm I've declared so terraform plan Anita are we good and I'm good thank you terraform apply this should now create my is2 instance I need to be sure that this is an Ami for my region So Pro can you read up this particular attribute yes I'm getting there I like to talk and you guys see what I'm talking about so it makes makes more sense so if we why is it saying I should enter value oh enter yes create so there is a problem with this Ami that is not an Ami in the region that I am trying to create my EST instance in exist so I'm using the wrong Ami give me a second Daddy I think it's easier the only other likely scenario is what region am I using here EU Central one this I should try us this one yes is one that's not Virginia right yes T tfly tfit so why did you do an init again if you had done it actually I think it should also work without the the init but normally once you change provide everything that concerns the provider configurations it's always good to reinitialize okay got you and so I think this should be the right region for that Emi So Pro this output um part you're talking about so does it put the output to the screen yes is going to Output to to our screen exactly so if you see now it has just um it's done create and it says that apply complete one added zero change Zero destroyed so this instance has been created in my account but I see nothing no information about it if I want to see for example the instance ID for this E2 instance that was created then I can use an output block okay and I call this output block I can call it what um ec2 or I say instance details ac2 ID okay and the value for this is going to be gotten using an expression see the the name of the resource which you're creating it's local name which is um specific to your use case whatever name you decide to give it in this case we are calling it web dot whatever attribute that this support so we were looking for an instance and the ID is given by the attribute called ID so we want a ID notation so if I run this again I expected a to give me the ID notation so I expect to have expect to see an output value with the ID the instance ID can you see that yes okay so does it did it finish the apply complete yes it noticed that from from a configuration perspective there's no change so the only thing that is has been adding there is my output so it's just G giving me my output okay are we together why is this very important let's say I'm creating an is2 instance now right and I want to put this instance in a specific Subnet in a VPC so let's create a VPC and terraform terraform AWS VPC I want a VPC resource this creates me a simple VPC so this creates me a simple VPC I think this what I'm doing might not be good for the recording in terms of visualization so I remove it so I want a VPC resource so in here I'm creating a VPC so this will create me a VPC call um I need a VPC name so I need to give VPC a name so I should find the argument that supports naming my VPC is there an argument that supports naming the PPC side of block tendency so I think the only argument is taxs right so I could give it a talk tag of name equals to non default okay so this is the VPC that we are creating now I want to create a subnet in this VPC so I look for the resource that creates subnet AWS terraform subnet get a subnet resource this is an example subnet are we together yes BR this is an example subnet and um I can create the subnet weed let me give it a a so those C blocks you selected them or again no those are the defaults that came with so but you need to ensure that remember when we're doing subnets and vpcs the subnet sers must be part of the vpcs but this tool looks I think it it is within however let me be sure I need 10. 10. 16 yep and I want a subnet called 10.0.0 17 they should be withing my VPC so SL 17 that's fine and I'm calling it on default subject what do I call it you guys are not helping me uh well just call it n non subet or will good so you can see that I want to know where to create this subnet mhm this subnet needs to be in the VPC how does it get to VPC it needs the ID of the VPC can you see so this is exactly what we did with the output so if I want to see this VPC ID I can immediately create an output block here and I say VPC ID and the VPC ID value would be exactly this value equals AWS PPC mean do ID are we calling our own mean so yes we are calling our own mean so I would let me change it t VPC so in me this case we must change this to call to VPC VPC exactly T VPC do ID so if I run this line 67 so what about line 66 what is wrong with line 66 yeah main does that have anything to doour no this has nothing to do this is a name that that um is pertaining to subnet so remember now I cannot create another subnet with the same name um uh so let me create two subs that was so that was um 10 do so 17 so this doesn't matter this T fa the T from From terapon perspect perspective it doesn't matter because you're naming this is the name that goes to the resource in your account however this is the name that terap keeps in it St that's how terap that's a name that terraform gives to this resource so terraform knows this resource by this name that's why this name is always referred to the local name of the resource as P terraform this is the name that you will see in your account when you go checking for this resource and you cannot have two Resources with the same local terraform name so I cannot create this resource say terraform subn me and another resource here says terraform subn name even if the attributes here are different the side up blocks are different this is okay if I run this code you see ter is going to tell me that I cannot do this that's illegal VPC the VPC ID for the subnet I think 967 yeah yeah you're you're exactly thank you very much 967 is also wrong so I need to also change the name of VPC ID to be test mean thank you okay that's what you guys meant I did not uh catch that so this also has to be test Dom main are we all together yes sir so now I can output my value here but I just don't want to end here I want to create an E2 instance in this thing so let me destroy this instance that we already created and will put this instance in this specific PPC where did I end so I do ter from destroy what's the meaning of that one that you put there what do you mean by what 60 8 89 okay this is how you you you you can commend hundreds of lines so rather than always using the hash um is it hash yeah yes yes than always using the hash you can do uh um it must open and close so forward SL star and you close it with star forward slash so everything within this within this will be commented okay oh okay so anything I write now in there is commented yes that's a new one so yes I can destroyed that instance which I created so it was complaining before because of um the resources in the configuration that from uh you not recognize hope this is making sense to you guys if it's not please tell me I find another way to I get it pro the when you created a subnet the second sub net mhm I'm not created it it's commented so nothing is happening based on our code oh I mean when you wrote it though so it's not um I mean when you typed the second subnet block so yes what's your question no I thought I saw two entries for sub I thought you said it yeah so why I'm having to why does he have the aore subnet and then it has main main is pointing to what is that just a main is a name the local name we are giving for this instance of the resource subnet so this is what I'm saying you cannot have the same resources with the same name so if I do a Tero plan now it's going to tell me that I have a problem this big man you're trying to to do things that we Parliament said is illegal duplicate I cannot have duplicate resources so for me to solve this problem I need to tell that oh one person is called Main and I can say call this one subnet one sub one and I call the next one sub two okay and now say okay now you've given everybody unique name and I'm find with your configuration you see so now we should have as an um this instances being created in this subance being created in the VPC VPC now I also want to create this is2 instance to make sure it's it's in is in in one of those subnet that I'm I'm creating so it's easy I go back to uh AWS is to instance resource so this is subnet I was this instance resource there should be an argument that tells me how to pass in this specific subnet that I want so there should be an argument somewhere instance instance type key name if you want to pass in key name launch template if you base on launch template uh subnet ID you see that right yeah so so it's called subnet ID so I can say I want my is2 instance call Web to be placed in subnet ID equals to a uh instance. ID are we together on the output so the subnet ID is going to be AWS is to AWS subnet sub1 ID why is it ID because we need a subnet ID and the subnet resource is giving us an attribute called ID if you want to see it you can also put an output block for it so I want an output block for ID subet subnet ID sub one ID what is it what's the value going to be please somebody tell me what AWS underscore uncore sub one what id exactly so now we have one to three output blocks in our code once we run this code should be able to see three values displayed to us so prob this this output um file is is it's like a mixture of variable file variable. TF and um um the TF vars any way because it has the actual values and also an output it doesn't have values it has an expression on how to get the value okay well the side block line had the actual wasn't in this file no here you mean the resource itself yes for the resources yes yes this resource itself we can varize this if you want the CER block I can put now a variables file for VPC CER for VPC VPC uncore cider and I see the type what will it be I can use a string here and I can give it a default value of whatever this default value block is in numbers right should no that's a string you see it because of the that's a string so that's expressions in a variable [Music] um yes but a thing with some limitations but it's not very good practice to use expressions in a variable I thought it wasn't working no variables sorry variables cannot use Expressions but locals can use Expressions locals or TF variables cannot um so what was I doing I was trying to varize this uh side so in this case now what do I pass here V do Emma you the one who said we should verbalize why do I pass here I'm sorry I lost my screen for a minute um I I I didn't see what you did my screen was black we're trying to varize this value we don't want to put in our CER block we don't want to put in our oh okay I will pass um it will be V uh v. VPC cider good that's a good thing with that extension for tone which you installed you see it already identifies the things which you've defined and it's already trying to give you help you get that done so basically so that's our code and this code should be ready for us to run oh if I do a TF plan so it's going to create us four resources and I do a TF apply M did I get the name right Bo of greatness he here is he here he's here do you understand why I'm do you understand how you can clean your coat now I understand how I can clean my code out about The Destroyer no about so I'm I'm creating those resources everything is being created now yeah so I want us to see the things we just created so I we created a resource called G test is still initializing was that the T we gave to it yes and it should be created in a [Music] VPC which we've created and we call that PPC you see we call the subnet jtic subnet so this is how you link those things and it's a called it's in a VPC called known default all these are all values which you just passed does it make sense y that's that's um interesting please you guys I would really like you guys to put on your camera it makes me just your facial expression if I if this is is going or not going when you're in the in the um black background I don't know if it's okay or it's not okay do do as much as possible try to have it on if you can it's a request okay correct Pam that includes you Cor are we good everything good everything is not good not really sure I understand no problem let's take it all over again what did you not understand I'm ready to take it all over again yes so please if we can take it all over like the whole output I'm trying to put it together it's not really adding up there was one last thing just segue what she said I thought there were supposed to be outputs on the screen at the end of your running the plan is it there should be so the value is here okay that's what I was looking yeah okay cool okay output values are very very important when we start doing modules that's why I was sking it to do it at the end but I also wanted to make you guys know how to change different resources so you don't have to for example create a VPC and if you want to create a subnet then you go copy the VPC ID put it in a variable then pass that variable into the subnet it makes no sense you can change that just using this dot not DOT Expressions okay so this works perfectly fine when you have all the configurations at what at at one at uh one level so they at the same file level F hierarchy they at the same level if I am putting this in a module now when we get to modules you'll see what we call Child and parent modules if this was a child module it would not work until I Define an output value so but because right now all my resources at the at the same uh Direct in the same directory I can actually commend out all this uh uh uh output values it doesn't matter so this should still work fine the only thing is it would not be outputed to our um console this should still work perfectly and if I do a terraform apply apply is wrong what is wrong your apply spelling spelling apply if I do a terraform apply this are the changes that should go the resources still stay the same it should just not display us those outputs again to Z up 0 change Z destroyed but now you don't see those values again okay so basically we use the output t for to see the values of our resources you can use output videos to see the values the goal for output is not to see the values of sources when we Define output in ch modules when we discuss modules next week it outputs the value into the configuration that it means it puts it into the terraform State as you saw output value so this will go into the terraform state so if you're calling this module now from a parent module and you need these values then we will need to know how to get that value from the terraform state by in that case now using the value this output this the name of this output value here okay we'll get there let me one thing at a time let's not py so much and confus it Okay the reason why I outputed the value to conso is for you to see what these Expressions actually get what are they looking for so the expression here AWS test VPC ID what it is because we Define the same expression in our output value do you see that M yes [Music] sir so what is the issue let me re explain it again um I was just trying to understand what the output value is all about but from the last statement you made it's kind of adding up somehow well so if I can ask the question why why an output value is there any significance in using it or not using it same question there's a significance There is almost no significance here when you are having all your configuration files at at the same level what do I mean you have your variables. TFI [Music] um I'm create here I'm creating my E2 I'm creating my VPC I'm creating the subnet so all those attributes are available at in the state at the same level do you understand what I mean yes however when we start doing modules we would varize all these and put it in a modules file or in a modules folder and we will call that modules folder if we want to create an is2 instance if we want to create a VPC so what you see most companies would do is they have a module for each resource like in my company we have like 90 or 100 different modules okay we have a module that creates these two instances we have a module that creates S3 we have a module that creates Cloud phone we have a modu that creates um vpcs and stuff now if I want to put my VPC my is2 instance in a VPC I need to know the value of the value of the subnet that that is to inst should be plac in and how do how would the two separate modules communicate with each other is we that those output values it might not make sense all this just talking next we'll get to it I'm very sure you you get it everything is here here here and too many files so I I don't even see how they come together yet yes so you you you see the the power of output in modules why I even displayed outputs here is because if I if I tell you that okay now this this resource which want to create AWS subnet to it needs to know how to talk to the VPC and this is how it talks to the VPC but what does this expression actually does what is this expression actually what's the significance of this AWS tvpc do ID what is these resource a subnet looking for this is what it is looking for so you could see it from the output value that's why you're seeing it so if you have it in the if I have it in my in my root module it outputs the value to the console it outputs the value to your UI so you can see it or to your terminal so you can see it okay so I have a question sure go ahead um if we're not using the output value like if we didn't want to pass an output value um up I think it's line 77 like immediately after the the subnet and the sub the resource no line 76 sorry yeah where we said VPC ID equals to that uh if we're not using the output value on this line uh were we supposed to like pass this VPC ID there or we are still going to use the same expression pass you need to pass the VPC ID there so some some some other person will say I want b. VPC ID right so it's read because I've have not defined a variable so I'll come and Def Define a variable Now call say. PPC ID okay and I need a default value and the default value equals to some string then I'll have to go now to my console look for that VPC ID come and put it here for it to go but that doesn't work if you everything from terraform then you can just do it do it do it this way do you understand me I understand you so but yeah it's okay so I understand because um like say if we had created a variable file and we passed this information here it would have pulled the information from the variable file right this bar VPC ID yes it would have put the information from the varable file but that's back practice you're not using terraform to its full potential should be able to use those expressions to get those um uh values because in that case your heart coding a value yes it makes your code not very reusable for me because in your you're creating a subnet and you're passing a specific what is it called a specific PPC ID to that subnet you understand what I'm saying now I cannot take your code and I use it so it makes your terap module not reusable and the whole goal of IAC and is is to make your code reusable and stuff like that because you're hard coding that value obviously I don't have the same VPC ID in my account but because I'm looking at Expressions if I take that same code from you and I run it in my account it's going to create my own VPC it's going to iterate in that VPC and get the pass it to the subnet pass it to the is two instance dynamically and that's the goal I think you do not pass values as much as possible yes Victor no I was saying you you actually answered my question you know um when I asked so um what's the significance of doing what you're doing now and you just said it you know you when if you do it the other way you're really not using terraform to its full potential yes um which is basically the the whole idea of doing I yes because uh if I think about it if I pass in a a what is it called a VPC ID here right whatever you you calling if I pass in a VPC ID here if I had code it and I you have the same configuration just imagine I'm deploying this to One account I want to deploy this to another account you know that those two accounts can have the same defy ID right yes yes T is going to complain that oh this thing that deploying is not not work that ID does not exist in this account that I'm trying to deploy into so it means I have to go into your code now and start fixing stuff then your code is not basically not good a code is not standard so you should try as much as possible to make your terraform code dynamic dynamically creates resources dynamically pass those values to resources that need it yep thank you are we sure we are together the bio bio is the yes sir yes sir I'm on mute okay so if we had Cod we cannot reuse that you had Cod you cannot use it reuse it that's the goal try as much as possible not to thank you sir so with the output that that it's um giv to the to the conso not to our terminal is it for us to like say verify okay um this is It's created exactly what we wanted to create this you can ver use it to verify I use that a lot for example when I'm building modules for environments I'm putting the the output value just there during my my building phase so that I actually see that what I'm expecting is what I'm getting but once I'm pushing that module if in if they are all in the root configuration meaning they are all um at the level of the same directory I don't need those output blocks in there okay so I can remove it just like what I've done here I com way comment it out is like it's not there right so it ignores it but if I'm building modules and I need to use these attributes for resources that are inside my module then I must put this output blocks because the room module will not be able to pass those you understand that we'll talk about modules next week okay okay Al we good sir yes I'm sorry I'm just trying to put all youve oh God sorry I'm just trying to put all of what you've thought today together so you're saying it's not good to hard code um that's why in the variable. TF file we just pass in the variables we are supposed to be using while creating the resources then in the TF v file we can actually hard code there right like you can pass the values you need has yeah like pass the values maybe the side of block and all of that that's okay to do in the TF Val file right that's okay to do the file yeah and if we do that do we still need to use the output value like if we are using the TF v file do we need um an output value yes okay there are two things let me put it this way now the output is for attributes for resources created by terraform terraform created a VPC I need that VPC ID to be able to create a subname right so when terraform created that VPC the VPC that was created in my a account has a VPC ID remember that you when you're creating subnet you cannot just create subet you need to put it in VPC right so the VPC resource needs to know where it should be placed I need to know just the same you when uh like when you creating a route table that when you're creating an internet gateway when you're creating what security group it needs to know where it's going to and it's using these Expressions so we using these Expressions to get the attributes for resources created by terraform but if I'm creating an is2 instance and I want to know the is2 instance size that value is not available from terraform that's is where I'm using my tfv five you see the difference is it clear yes sir yes sir it's it's adding up m so I need something like is3 instance and I'm making a decision on my own that I know I want a T2 nano2 micro the instance type for the resource we want to create is what you and is a decision we are making however the VPC ID for the resource we have created it's not something you and I can decide it's there it's the same thing you cannot decide what the ID will be it's an it's it's an attribute that only you only know it after you've created the resource okay and that's what the output value shows us right that's what the output value shows us exactly okay thank you so Prof are you is it well one of the possible uses of those values is that something you can capture put it in an Excel spreadsheet and you know inventory or or what I know is there a use for saving that output value somewhere in a document if you're preparing a doc I've not seen a use for it okay they use the use for output is just so that other Tel resources can use them okay finish so most of most times we we we put this output in the console so that we can also as Engineers confirm that this is actually um um what we expect but the main use for it is so that tform um other tform resources can can see it okay okay for example I can create a uh what is it called let me see AWS terraform I am another a rle I want user so the I am user creates the username and stuffs like that so you probably need this username that you want to give somebody but I want to create access keys and secret keys what resource is that is there for that AWS I am us SSH key access Keys yes this is what I'm looking for so if you see this results this this creates an access key cre a user on the policy so you can see this is an output basically that is spitting out this the the the secret for if you want to copy it from your console or something like that but you hardly be displaying that all the time so the output is just B for you to display that information going of greatness are we together my you look like something is not adding up is past his bedtime together um I'm here I'm looking at a different screen okay because it's on you're on my secondary screen I get it all right then assignment will help us Build It Up I want to ensure this is clear here if you do not understand this we have a problem when we start talking modules is this clear please do not feel uncomfortable if you have a question 10 times ask me I'll do my possible best to um answer in different way so that you get it that's why I'm here did you say we're doing mod to starting it tomorrow or next week no next week oh okay so that modu sound like it's it has some great complexity in it uh I would not say complexity so complexity sounds scary no it's not complex it's everything that we are doing here we are actually already putting the building blocks to to have a module okay so everything put together will form a mod yes everything we're already doing here we already having the building blocks to get a module next week we just add it then we'll move it into a different fire and start coling it from another place and that's our module it's no nothing strange lead up lead up to the module if you will and trust me I just there seems to be we have like numerous files that were take putting with some variable thing here and then calling it here and then putting another variable that's the way with the way I see it when I'm looking at this output file looking at the uh variables file looking at I'm calling it output file is just you can put the blocks in the same quote wherever are you not seeing it right here everything is here right so from here I'm defining my providers normally if I'm having a big block of code I will not have one five with 4,000 lines of code right so if if if I want to push this module and make it easily maintainable by other colleagues then I will cut this line of this and put it in it provided to tiery so they know that this is a f that deals with the configuration then I will cut this this other line of code let's say this and what resource am I creating is2 instance I'll cut this L of and I put it on an is2 TFI so you know that this is a file that with the EAS to Resource our cut this line of code uh VPC and subnet and route tables and everything and put it in a network file or whatever but when I'm building modules especially if the modules a bit uh the lines of code a little bit uh long even in the network module I have a fire a main main.tf which is the file that actually has my VPC but I have a a rout table. TF that defines all rout table resources I have a a what igw dotf I have a n.f or stuff like that is the the number of files is just to make it easy to maintain so if I if I come in there I don't have to go through that 4,000 lines of code if I'm looking for something that concerns only IM or concerns only S3 okay I said that if you have a 100 files in this folder and all those 100 files end with a TF extension terapon Aggregates all the resources in those FES during the plan oh it reads all of to of them and Aggregates all the information in those files during the plan so even if you define a file say e2. TF and you put nothing in that file that aggregate it and say oh this there's nothing here so it does nothing so the splitting it into multiple files is just for easy maintenance and and and and and and make your code easily readable by others right what is different here is T TF and the that's the only difference so you can decide that all your provider is2 your S3 your that everything I have one file call the F MTF astf T will read it it doesn't care the name I'm just saying easy to so that you know that oh this an AWS person you know what is to is this is what is is dealing with I'm saying s3. TF because it's S3 I'm saying ssmf because it's SSM terraform does not care number of files you have there as far as it ends with TF Prof I I think I get you now even though I I would have thought it would be counterproductive if from an organizational standpoint but because you said that terraform actually reads the files if it's even if it's 100 files on the left hand side begin to make sense now you know said okay it's 100 files how you going to organize it how do you know which is which but it's not necessary because terraform will read it anyway as long as it has a TF at the end as far as it has a TF at the end okay and it knows how to sequence the creation of each of those things I think I showed you guys my uh uh my local for some project related files which I had right and that's what I showing you guys with all the different classification of files and stuff like that just so you see the organization so that if I pick up your your your project and I having some problems related to Route tables and stuff like that I should not be reading S3 lines and stuff like that I should already know the file that I'm looking for it's rout table is there rout table. TF if it's not if there's no rout TF I can see oh there's network. TF and I know that rout table is a network resource I can just go into your network. TF file and I look for the rout table res which I'm looking for and stuff like that okay is am I defining variables just look at what we are doing here um um I have def defined the terraform configuration I have defined the resource another resource another resource now I'm putting a variable in here another resource this makes maintenance a little bit difficult right because this is just a small what is it 9 to7 lines of code you can easily go through it the minute this cross a th000 that becomes a problem agree I I I I one one quick question Prof so is there any situation or scenario maybe in the modules file that you would have these 4,000 lines of code in one location am I just um going to fast but you see the way you presented it here was just so that we understand what you're doing but in reality does the module file contain as many lines of code AS whatever it is just and it will yes it will still work from terapon perspective telephone does not care how many lines or how many files are there as far as it is a TFI it reachs it okay so if you want to create your E2 S3 VPC um uh what is it Cloud front Lambda API Gateway load balancer um hosted zones if you want to put all those things in one fire that's your business just ensure it ends with a TF yeah and the reason so the reason why I say that is I've seen a file that long that immediately I lo I saw it I was so confused I just shut down I couldn't process all of that you know so I have I have FES that are almost in the I would say 500 600 lines but uh it's because they are all related resources especially when we're having so many conditioners with Cloud front and Lambda at Edge and stuff like that and we decid I decided oh especially during the module building phase when I'm building modules when I'm building modules I'm I'm still working from the same file the only place that I I start getting my values into is my variables. TF so that I know that variables are here but once I'm done and I know that my E2 resource is okay it's it's as the way is the way I want it to be I can just delete it from my main.tf and I open is2 TFI and I dump it inside ter doesn't care asfi going to read it as fire a billion TFI it's going to read it now there's a big difference with the TF and the TF vs so you get that right so you can decide to have one. TF and one. TF vs now your modu maintenance and the Wala that comes with reading that those number of lines and switching resources that's going to be a problem terraform doesn't care he going to read it okay I get it now sir so we we talked about this on day one when we were creating all this you remember I was saying that you canate have all these resources you separate them variables VPC dotf and you see then because we do not have anything VPC related we run our code it still worked there was nothing in the VPC dotf there's nothing s3. TF there was nothing easy2 nothing here just our provider and still worked so you would most likely have res saw descriptive names that for somebody that's into AWS if I want to create a hosted zone or DNS related information and I I can come here and I say maybe I call this dnsf so that anybody that comes in will know that hosted Zone resources are here or I can call it hosted hosted um zone. TF whatever domains. TF I think I have one one module that's actually called um uh do me. TF no it's called route 53. TF wow wow so we call we call it route 53. TF so you know that everything that's Route 53 is in this it's in that file this is very important if I get into your project and I see that you you've dumped everything into it I already pieces me off just be one mod what I said that everything combined will just be one module I guess it depends on the resources that you are deploying if you want to make all this a module the problem with a module is the thing with a module is once you call the module it's creating every resource in that module so that's why I will have a module for PPC I'll have a module for ec2 I'll have a modu for S3 I'll have a modu for R 53 because if I put all this in the same configuration for my module the minute I call that module all those resources are created all okay yes BR I got um regarding the the default tax I believe AWS um sort of ignores the ones I think it's actually um on the AWS website it sort of ignores it if it doesn't support it and I think they provided a configuration for auto scaling as well where you can sort of Mer with other TX yes you can merge tax there's a function I think I mentioned it there's a a function um called you guys can see my screen right yeah I strongly encourage you guys to read this there's no way we can cover it all ter from documentation configuration language expressions and functions so you can see those types of values that I were talking about okay you can see expressions and conditionals there are so many things that we cannot get all this is those four Expressions Splat Dynamic blocks and these are the functions so there are different collections of functions I think the merge is should be in um collection functions probably uh merge you see so yeah here if I have a a um two different uh this is what I'm trying to merge this is the first index is the second index so you see it gives me a collection so you can use merge to do a lot of things so they there there so many so many uh so much information there you just need to my advice is is read read it so this is just a documentation right yes this documentation documentation is there so it it's uh obviously we're going to cover the core things right yes good if no questions I think we can call it a day today rather than starting another topic I agree but I need are you going to destroy the whole thing you created or you already have no I will destroy it okay I will destroy so before you call it there give us an assignment that would help sure just full around a little bit terraform destroy so tomorrow I think we would do meta arguments then remote state so that we stop seeing our state here we'll put it in an S3 bucket and stuff like that so I think we've covered almost everything for you guys to be able to take this home am I too fast no it's not that you hope not too fast it's just that there are so many little pieces of different things so it's even hard to even make notes to tell me the honest truth because there's code invol a lines of codes so that's I was asking for if you could share some of those um folders yes I will I will I'll share them so just give me okay by tomorrow I'll reorganize it so I can share share it to guys to you guys okay okay you said tomorrow we're doing meta and something else um I think you said do uh state tform state and we would do meta arguments meta argument met arguments that's right so we'll look into that tomorrow um what did I want to give you guys yes remote State I don't I tried to I created my E2 inside the P subnet then I try to add like a load balancer to send traffic to that isas to I don't know why the target is not healthy I've tried to troubleshoot and troubleshoot balancer is it application load balancer no no no is it an internal or an external load balancer internet facing in the public subnet so it's in a public subnet and that public subnet where that load balancer is in do you have a corresponding private subnet that easy yes is associated to people with that links that connect internet gateway did you create Target groups yes so you need to have a load balancer in the public subnet and if that load balancer is in the public Subnet in US is 1 a and your uh Target is in um uh how do you call it how do you call it's in a different zone is going to be a problem except you enable cross Zone load balancing you remember cross Zone load balancing I don't know if I'm the one that about us however what the target group is in the same Zone anyway that's that's AIT off let's let's talk let's finish with this Bal issue recording and then we can talk about that one yes so or Simon Emma please just try whatever you're trying with if you have a any question any problem ping me okay okay so Jes she here she's very quiet Jess is quiet from here she's watching the news no no no I'm Victor why would you say that no subnets two public subnets my God I'm going to have a problem my my I already have this you can see can hear you we can hear youe has given up can you hear me yes yes a VPC your your your volume in the back is loud I have a problem with my when when you stop hearing me you tell me please we hear you create a VPC with two public subnets uh do it numerically attach an igw to the VPC create rout tables [Music] and is2 in each subnet with routes to the internet Z what is it again 0000 z z zero um I think this is good I want you to create a VPC I want you to create two two public updates I want you to create rout tables and rout table what we I already have done this from terraform yes that's nice you have a what she's already done it oh you've done this assignment already [Music] M I have a great not and uh so he's going to make a twist now in a minute just wait you asked for it you're I want you Lambda functions uh create an easy to with keeper Prof let me share my screen I've done it no that's okay leave him alone he's finishing you have done an is with keep good then I want you to use star TF f to deploy to what's that word in the middle sir emulate or emulate emulate emulate okay so um I want to see different tvf FES for two different environments okay so I can do multiple in test or death test okay so I guess that's clear all right workpace what is it workspace for the last part no what we talked about this morning no workspaces I'm not talking about or giving you anything which we've not talked about yet okay f bro please paste it in um slack please Zan I did not hear your voice for a very long time you just join us Zan has been there no I was there on Friday I was out of town uh I joined the class and I passed out in my hotel room I slept off but today I've been here day he's been here and I was here on Thursday too you know terraform is very very today is Thursday by the way th I I have to maintain my my innocen so I can grab everything use my whole number six Prof I have a question there was something you said about when you create these subnets and whether they are going to be public subnets whether they are associated to um because when o j was talking about him creating uh his public subnet you asked him a specific question whether he was associated with a private subnet what was that that's what was the essence of that question I wonder whether he need can you remember the question well he he he had created an environment where he had public subnets um you know in his in his deployment but one of the first questions you asked him was that is it associated with a private sub and he said no so I was wondering where you were leading to with that question when you asked him I I think it was with the load balance or the load balancer yes you the load balancer in public subnets okay you're talking about the person with the load balancer thing yeah that's that's was it right yes should I share my screen now just give me a sec so I think we're done isn't um on slack please yes it is on slack you can stop recording before we then talk about that one