BestSeller
Best Seller!
$27.49
$24.99
Terraform Associate: HashiCorp Certified: Terraform Associate

Terraform Associate: HashiCorp Certified: Terraform Associate Certification Video Training Course

Terraform Associate: HashiCorp Certified: Terraform Associate Certification Video Training Course includes 78 Lectures which proven in-depth knowledge on all key concepts of the exam. Pass your exam easily and learn everything you need with our Terraform Associate: HashiCorp Certified: Terraform Associate Certification Training Video Course.

134 Students Enrolled
78 Lectures
10:08:00 hr
$27.49
$24.99

Curriculum for HashiCorp Terraform Associate Certification Video Training Course

Terraform Associate: HashiCorp Certified: Terraform Associate Certification Video Training Course Info:

The Complete Course from ExamCollection industry leading experts to help you prepare and provides the full 360 solution for self prep including Terraform Associate: HashiCorp Certified: Terraform Associate Certification Video Training Course, Practice Test Questions and Answers, Study Guide & Exam Dumps.

Read, Generate, Modify Configurations

2. Understanding Attributes and Output Values in Terraform

Hey everyone and welcome back. Now in today's video, we will be discussing attributes and output values. Now, these two topics proved to be very important, and you will be using them quite extensively while managing your production infrastructure in TerraForm. So let's go ahead and understand them in detail. Now, TerraForm has the capability to output an attribute of a resource with the help of output values. So let's understand this. Now, let's say that you have launched an EC2 instance and you have launched S 3 buckets. So there are two resources that you have launched. Now, after the resource has been created, let's say you want to fetch the public IP address of the ECQinstance that has been created or a domain name associated with the S3 bucket that you have created. One common method is to go to the EC console or the S console and retrieve the necessary information. However, you can tell Terraform that it should output these values once Terraform has been applied. So you can get output values something similar to this, where once the EC2 instance is created, TerraForm will say that the public IP of your EC2 instance is this. And if your S 3-bucket is created, then TerraForm will basically return you the hostname associated with your S three bucket.So these are two examples. You can also output a variety of other information. Now, along with outputting, the value for user-reference attributes and output values has one major function: a specific output and attribute can act as an input to other resources that are being created through TerraForm. And this is one thing that you will be using very extensively. So let's understand what I mean by this with an example. So let's say that you have created an IP address. So this is an elastic IP address. Now, once this EIP gets created, the output of that EIP should automatically get whitelisted within the security group. So you have two resources that you are creating in TerraForm. So the first resource is EIP, and the second resource is the security group. So once the EIP gets created, it should output its public IP address, and this output should go to the security group and should automatically get whitelisted. So this is one of the major advantages of attributes and output values, and this is the place where they are extensively used. So again, I am sure that this might be still confusing because we are still discussing theoretical aspects. So let's do one thing. Let's jump into the demo and understand what these are. So, I have a TerraForm file for today's demo. It is known as attribute TF. As you can see, we are creating two resources here. The first resource is basically an elastic IP. So this is the first resource, and the second resource is basically an S-shaped bucket. So these are the two resources, and we also have the output associated with both of them. Now before we go ahead and discuss output values, let me go ahead and comment out the output section here. All right, so we'll just talk about the resource creation section post, which will discuss the attributes and output. So, I have saved this. Let's do a TerraForm plan here. So today's video is primarily intended to demonstrate that we understand the concept well. Now on the TerraForm plan, as expected, it is showing that there are two resources that will be created. The EIP is the first resource, and the S3 bucket is the s three bucket.So let's go ahead and do a TerraForm application. So you can just verify if things are expected, and if they are, you can put "yes." All right, so both the resources are created. Now, as we're talking about it, once these resources are created as a user, I'd like to see what the IP address associated with this elastic IP is, as well as what the identifiers associated with the S3 bucket are. So generally, how would people do? So, going back to the EC console, you can go a bit down, you can open up the elastic IP, and this is the elastic IP address value for you. And in a similar way, you can go to the "S" bucket, and this is the "S" bucket for you. So then you can go to properties and see more details about a three-bucket list. So this is the basic way of doing things. Now let's understand this approach in terms of the output values. So now for our second demo, let's go ahead and remove the output section associated with both the resources. I'll go ahead, and I'll save it. So now for our second demo associated with the output values, let's go ahead and destroy the infrastructure that we had just created earlier. output as great. So the infrastructure is destroyed. So coming back here now, let's go ahead and remove the comments that were associated. So now we have output associated with both the resources. I will also change the name; let's call it a one. All right, so you have the EIP resource and you have the output associated with the EIP resource. So this is one block, and in the second block, you have a three-bucket set and you have the output associated with the SV bucket. So now let's go ahead and do a TerraForm directly. I'll put a "yes." Great. Now if you would see here under the output section, there are two values that TerraForm has basically shared: one is the IP address, so this is the EIP, and the other is the bucket DNS name. So this becomes much easier for users because now they don't really have to go to the console. They can directly look at the output values and proceed accordingly. So this is a very useful feature of TerraForm. Now, going back to our TerraForm file, if you would look into the output section here Now, I hope you have seen the earlier video where we discussed how exactly a resource is identified. So this specific resource block can be identified with this resource name followed by the name that the user has given. So the resource name here is AWS, and the name that we have given to this resource is LB. So this is the name with which we can refer to or call this specific resource block. And in a similar way, the second resource block can be called with the resource name here, which is AWS underscore s three underscore bucket, followed by the name that you have given to the resource block, which is my s three. All right, so this is the identifier by which you can call this specific resource block. So let me go ahead and remove this. Now, if you look into the output section here, you'll see the value of this EIP output. So if you would like to see the value of this EIP output, it is AWS underscore EIP LB. So this is the identifier to locate the right resource block. So from here, we know that the resource block that has been called is this one. And on the right-hand side, this is basically the attribute associated with an EIP resource. Similarly, examining the output of the three buckets yields the name. So three buckets, three MYS. So this is this resource followed by a dot. Then you bucket underscoredomain underscore name, which is basically the attribute. Now, one of the questions that comes up is, let's say that I have created a three-bucket three bucket.What are the things that I can input as part of the output? Because we had just entered the DNS name. Now, there are a lot of things that you can produce. It's not just one thing. Let's understand those aspects as well. So I'm currently in my phone documentation for the resource AWS underscore AIP. In the documentation, if you go a bit down, there is a section on attribute reference. So this section basically contains the list of attributes that you can output within your TerraForm code. Now, we have output the public-underscore IP for today's demo. However, there are other things that you can do. The same goes with the other resource in the three-bucket system. Now, if you look into the documentation, and if you go a bit down, there is a section on attribute references. So in today's video, we basically referenced a bucket underscore domain underscore name attribute. However, you can also reference various other attributes associated with this resource. So this attribute reference is basically associated with different kinds of resources that you might be using. So in today's video, we just took an example of elastic IP and SD bucket, but this can also be associated with EC, two instance loads, balancers, et cetera. Now, before we conclude, let me show you an interesting thing. So let's remove the attributes here; I'll remove the attributes, and let's just do a TerraForm apply. So now you see what happened in the output. You know the values associated with every attribute of a specific resource. So for EIP, you have an associated ID, a domain ID instance, the network interface, the public DNS, et cetera. So these are all the attributes associated with the IP. Same goes with S's three buckets. These are all the attributes associated with the three buckets that have been outputted. So, if you don't explicitly mention a specific attribute from the output in your code, it will basically list all the attributes associated with a specific given resource. Now, within the TerraForm state file as well, you will see that there is a dedicated section for outputs. So within the outputs here, you have the output associated with EIP. Same goes for the second output of the S3 bucket, where you have all the attributes associated with the S3 bucket, which are listed in the output sections here. Now if I just minimise the output section, let's also minimise the resource section here. So now you would be able to better understand the structure of the TerraForm TFC file as well. Now, output basically contains all the output attributes that you might have defined within your TF files. And resources are the actual underlying resources, which have been created through TerraForm. So that's the high-level overview of the attributes and the output values. I hope you understand this in a high-level overview. Today's video was primarily a demo video to understand both the attributes and the values. So just to revise, attributes are basically a value block associated with a specific property of a resource, and output values are basically used for outputting that specific attribute. So that's the high-level overview. I hope this video has been informative for you, and I look forward to seeing you in the next video.

3. Referencing Cross-Account Resource Attributes

Hey everyone and welcome back. Now in today's video, we will be discussing the referencing cross-resource attribute. Now, we're in the section of attributes and output values. We had discussed an example where an attribute associated with the E IP can be referenced to a security group automatically. Now, this was just an example. In today's video, we'll be doing things practically. So there are two examples that we'll be discussing in practice. One is where we create an elastic IP and we create an EC2 instance, and this elastic IP should automatically be associated with this specific EC2 instance. So this is one example, and the second example is of EIP and the security group where you have an elastic IP resource, you have a security group resource in your TerraForm TF files, and your EIP attribute would automatically be added within the security group rules. So those are the two examples. Now, the way in which we can take the practical aspects associated with both the examples is a little bit different, but the concept is similar, and hence I decided to include two examples so that we cover a wide variety of use cases. So let's do one thing. Let me go ahead and create a new file. I'll call it reference TF. And as we were discussing, within the first example, you have two resources: one is the EIP resource, and the other is the EC 2 resource. So we'll use the resource block already available. So we had already discussed how you could create an EC2 instance. So I'll just copy the resource block from one of our earlier demos and I'll put it within the reference PF file, and we'll also make use of the EIP resource because we have already discussed this within the PF file. Now let's do one thing. Let me just go back to the attributes file because we have the provider block, which is the same across attribute and reference. So we only have one block of providers. Now let's do a TerraForm plan. So I'll quickly do a TerraForm plan, and as discussed, it is basically creating two resources. So the first resource is of type EC-2 instance, and the second resource is of type Elastic IP. However, what we want is that once this elastic IP gets created, it should automatically get attached to this EC2 two-instance resource. So currently, what is happening is that only Elastic IPs are getting created and EC2 instances are getting created. This elastic IP is not being associated with the EC2 instance. So now in order to associate EIP with the EC2 instance, you have a resource called AWS underscore EIP underscore association. and this is basically an example usage. So let's copy this up and, within a file, I'll go ahead and paste it. So now what do we have to specify over here? Now, the first argument here is the instance ID. So instance ID basically states to which instance ID orEIP should be associated with so if you look intothis diagram, so once this EIP is created to whichinstance ID, this EIP should be associated because there canbe hundreds of easy to instance. And this is the reason why we have to specify the instance ID. So far as we know, our EC2 instance has been created with this specific block. So we can directly reference this block here. So let me remove this. I'll use AWS underscore instance MYEC 2 as an example. So this will reference this block. However, here we have to specify the instance ID. Now, according to the documentation, if you open the AWS underscore instance here quickly, let me just change it to resource block. Now, within the attributes here, I'm sure you know what attributes are. Within the attributes, you have one attribute, which is dot ID, and this is basically the instance ID. So we'll quickly reference that attribute within the instance ID column here. The second is the allocation ID. Allocation ID is where you specify which EIT will be attached to this specific instance. Now there can be hundreds of elastic IP addresses. So within here, you specify the elastic IP block. So let me use an AWIP LP ID. All right, let me go ahead and save this. So let's do a TerraForm plan yet again. Great. So there are three resources. Let's go ahead and do a TerraForm application. All right, so the resource creation has been completed. Now, from the console, if you would like to verify, you see that you have an EC2 instance that is currently running, and it automatically has an elastic IP that is associated with it. So I hope in a high-level overview you understood how we were referencing the attribute of one resource. So in instance it, we were basically referencing the attribute associated with the EC-2 instance resource, and in the allocation ID, we were referencing the attribute related to the EIP resource. So this is our first example here. Now we have one more example of EIP and security groups. So this example is a little different; the concepts are similar, and this is the reason why we are taking up the second example as well. So the thing that we have to do thisthing, we have to create a new security group. So going back to the documentation, I'll say AWS Underscore Security Group; if you do not find it, you can directly put it into Google. So you can specify something like an AWS underscore security underscore group, and this will give you the TerraForm documentation here. So this is a simple example for creating a security group. Let me just copy this up, and I'll pace it within an Adam editor. So currently for security group, we don'treally require a lot of things, let'scall it as Kplabs hyper Security group. All right, so let's remove the unnecessary documentation here. Soingress is now primarily inbound in English. So if you want to verify, let's go to a security group here. Now, if I create a security group, I have a security group name, description, and VPC. Now you have inbound and outbound. So in a similar way, you have the ingress for inbound and the egress for outbound. So whenever you add a new rule, you have to basically specify various things. One of the important parts is the port, as well as the IP address here. Now let's do one thing. Let's open up the existing security group here and let's add a rule. I'll use a port of 22 and a random IP address of 50 30 for the IP address. All right, so this is the IP address. Now, if I do a shape, it basically errors out. The reason why is because you have to specify the entire subnet, which is 32. So if you specify a subnet, it can be 32, 24, et cetera. Then only you will be able to add a ruler. So within your TerraForm block, let's go ahead and reference the elastic IP. So I'll say AWS EIP LD. So this is a resource, and you have to specify the public IP. Now, within the EIP documentation, if you go a bit down, in order to reference the public IP, you have the attribute of "public underscore IP," which is available. So you can say "public underscore IPover" here and we'll close this block. So let me just remove the underscore, which is atypo here, and we'll also put it within a block. So this is very similar. So if you look into the documentation, you have citi block, and within a block here, you specify the IP address. All right, so I'll go ahead, and I'll save this. So now let's go TerraForm plan.And on the TerraForm plan, it is basically giving an error, saying that it must contain a valid CR. Now, if you would see it, it is automatically able to detect the IP address that is associated with the EIP resource. However, as we discussed, within the AWS Security Group, you have to specify 32. All right? So you have to specify something like 32 over here. So let's try this out. So I'll do a TerraForm plan, and again, it is basically giving you an error. So you'll have to go with the 00:11 TerraForm version style, where we specify the CiDI block. So within the CiDi block, this is the block style. If you've worked, you'll recognise this as the zero-point-eleven version. So what you do is put it here, and then you add a slash 32. So let me add it within the block here, and let's comment on a second CiDI block. So let's do a TerraForm plan. And now you see, it seems to be working. Let's go ahead and do a TerraForm application to double verify.All right, so it has given rise to more errors specific to protocol. So this is a simple one. I just made it as a TCP here. So let's quickly do TerraForm, apply it again, and this time it should work. So basically the "minus one" protocol is generally used for ICMP. And what happened was that we had specified a port, and this is the reason why it was giving an error. Because you can't really specify a port like 443 for ICMP because it goes to TCP or UDP. So I'll give it a C for ICMP. AnSo the resource is completed. So let's quickly reverify. So this is the security group, and within the security group, you see automatically that EIP got whitelisted on port four three.So that's the high-level overview of today's video. Now we have explored both approaches. Remember that we're using the second approach here because we're adding a slash 32 at the end. So you're combining a variable with a string. So this is the reason why we are using this specific approach. Now, if you look into the second approach, it is quite similar. So how things would work is that you create a block or something similar to this, all right? And then you use the exact same value attribute as you might use without the blocks. So you have AWS underscore EIP LB public here. So the only additional thing is this specific block. So this specific block was the standard one for the 00:11 version, but from the 00:12 version onward, you can directly reference attributes without adding these blocks. However, in some cases where you may want to add a string, you will still need to use a block, similar to this. However, for most of the cases, this is directly referencing the resource and its attribute, which is the right approach for the zero-one-two version onward. So that's the high-level overview of today's video. I hope this video has been informative for you, and I look forward to seeing the next video.

4. Terraform Variables

Hey everyone and welcome back. Now in today's video we willbe discussing about TerraForm variables. Now generally, whenever you are creating TerraForm for a production environment, there can be cases where there are a lot of repeated static values within the TerraForm code. Now do remember, the more the repeated static value, themore the work you'll have in the longer term. So let's understand this with an example. So let's say that you have a TerraForm project A, and within this you have three repeated values throughout the entire project. So it can be where you have a security group and you have basically allowed this specific IP address on three different ports, let's say 22, 80, and 443. So you have three IPaddresses which you have whitelisted. Now let's say you have a project B where, again, you have whitelisted the same set of IP address here.Now, although this seems to be fine, the problem here is that, let's say, after some amount of time, this IP address changes. So now what you have to do, you haveto change or you have to update a newerIP address in all of these locations. So in this diagram there are six locations, but in your production environment there can be a lot of other locations as well. So this is the reason why it is recommended not to add static repeated values directly within the project directly.Now, instead of adding the values to each and every location, what you can do is create a central source. So let's say that you have a central source over here, and what you do is you supply that value to this central source, and from your TerraForm project, you can reference that source within your TerraForm code. So you have VAR sources. So this VAR source will basically have the value which isassociated with the source, which is one one six X. Now let's say tomorrow you have to update this specific IP address. So now what you do is update this IP address at the source, and you do not really have to touch your code automatically.The code will refer to the latest value, which has been assigned to the source. So this is the reason that creating variables proves to be very important here. So let's quickly jump into the demo so that we understand this in a better way. So I have created a file called Aswardsdemo TF, and this is basically a security group where there are three rules. You have four, 4380, and 53. Now in each of the rules, we're basically whitelisting an IP address here. So this is very similar to the situation that we were discussing on the first slide. Now, let's say that tomorrow this IP address changes. So now what you have to do, you have toupdate this specific CIDR block in the location one, inthe location two, and in the location three. So this is just for the demo; in production, you can have 20 or 30 locations. So in all the 20 or 30 locations, you have to update the IP address. And again, after one week, that IP address also changes. You update there once more. So that is not the right approach. So instead of defining the IP address here, as we were looking into the PPT, you create a central variable and then you reference that variable within your TF file. So creating a variable is very simple. Let's create a new file. I'll call it "variable variables. TS. So within here, let's define our first variable. So I'll say variable. Let's give a name to this variable. I'll say VPN underscore IP, and within this, we'll add a default value of 1116 50. This is just an example here. All right, so this is our first variable we've created. So the name of this variable is VPN underscore ID. So looking at this diagram, this source, we have basically called it "let me just do it right now so you can understand more clearly." So this central source here has the name VPN underscore IP, and we have basically assigned an IP value here. Now, instead of manually hardcoding this variable in your TerraForm file, you can simply reference it here. You can accomplish this by using VAR VPN underscore IP. All right? So the syntax is VAR dot the variable name. In our case, the name of the variable is VPN underscore IP. This is what we will be referencing to.So let's copy it in all the locations, and I'll go ahead and save it now from the CLI. Let's do a TerraForm plan. So now you see that for all the blocks for 53, you have the same IP address that is being shown. So to double verify, let's go ahead and do a Terraform application. I'll do it, is being So the security group is now created from the AWS console. If you look at the security group, you'll notice that there is a new set of IP addresses within the inbound, and this IP address is basically referenced from the variable. So now speaking about a situation, let's say that a client has said that their IP address has changed, and we basically have to update that IP address everywhere. So, since we're using variables here, we won't have to touch the code to update the IP address. The only thing that we have to touch is the variable TS, and let's change the IP address to 50. Now let's again do a TerraForm apply. Oops, we'll put a yes, fantastic. So the update is complete. Now if you want to verify, let's refresh. And now you see all the IP addresses changed to 50. So that's the high-level overview about variables. Now, if you are working with TerraForm and production, you will be extensively making use of variables. Variables are very important in writing clean TerraForm code. And as you might have seen, variables prove to be very important in the reusable code aspect as well. So that's the high-level overview of today's video of variables. Again, I will encourage you to always make use of variables wherever possible. And when we discuss the TerraForm modules, variables will prove to be a very important topic there. So I'll really encourage you to try this out within your environment because variables are something that we will be using extensively, and you will also be using them quite often within your production environment. So with this, we'll conclude this video. I hope this video has been informative for you, and I look forward to seeing the next video.

5. Approaches for Variable Assignment

Hey everyone and welcome back. Now in today's video, we'll be discussing multiple approaches for variable assignment. Now, variables in TerraForm can be assigned values in multiple different ways. So some of these include environment variables; you have command-line flags; you have the "from file" option; you have variable defaults; and so on. So let's do one thing: let's quickly have a look into it so that the overall concept of variable assignment can be better understood. So for today's demo, I have a file called EC-Two Hypervariable TS. So this is a very simple file that contains the provider block and also contains a resource block where we are creating an instance. Now do note that here all the values are hardcoded, and we have already seen how we can make use of variables to remove the hardcoding aspect. So let's do one thing. Let's quickly add a variable over here. So in the instance type instead of hardcorein this we can say VAR instance type. Now what we can do is go ahead and create a file called "variables TS." And here we can specify the variable, which is the instance type. And now you can specify the default value, which is "two dots micro." Alright, once you have done that, you can save this from the CLS. When you do a TerraForm plan, you see that things are working as expected, and the instance type has a value of t two micro.So this specific approach is also referred to as "the variable defaults," where if no explicit value is mentioned for a variable, then this default value is assigned to it. So now let's go ahead and specify an explicit value for a variable. So after clearing the screen, let's do a TerraForm plan. And now we'll be specifying a variable. The name is instance type, and the value is, let's say, t two small.When you do this, you'll notice that the instance type is "two small." So I hope you get the overall concept of this default value. So if no explicit value is defined for Terraform, then Terraform will make use of this default value. Now the question that comes is, "What happens if you have not defined this default value?" Let's try it out. So let's go ahead and remove this block. So let's make it a single line. So now we have not really specified any value associated with the instance type. So let's clear the screen and just do a TerraForm plan. And now immediately you see it is asking youfor the value associated with VAR instance type. So let's try t two medium over here. When you look at the instance type, you'll notice that it's a medium. So this is where you go ahead and explicitly specify. So even if you have not defined the default value within the variable, you still have an option to define it within the CLI. So we have explored the command-line flag. We have also explored the variable defaults. So let's also look into a file base perspective. So generally, whenever you specify via the CLI, what generally happens is that you have to always specify the instancetype, such as "t," "2D," "small," and so on. So this is not the best approach that can be taken. So what you can do is specify this within the file itself. So you can go ahead and create a file with the name of TerraForm PFW. Remember this naming convention. And now what will happen is that all the values associated with the variable can be part of this file. So you can say the instance type is equal to "two large." Let's do a save. And now what will happen is that you will have this variable, and the value of this variable is defined within the pfparse file. So when you do a Terraform plan, if you go back, you see the instance type is "two large." So I hope you got this specific concept. So generally, in a production environment, it is considered a best practise to have both the variables and the TFWs file. So generally, what would happen in a typical production environment would be that you would define the default type of T2 micro. So this will be the default type. So let's assume that the developer wants to launch an easy instance. So he uses this template. Now, he has not defined anything within the TFWs file. All he has done is download this specific configuration, and he does a TerraForm install. So by default, what will happen? An instance of Type 2 Micro will be created for him. So in case, at a later stage, he wants a bigger instance, what he can do is, within the TerraFormTFWs file, he can specify that two last, and then the bigger instance will be launched for him. So if he does not specify anything, by default, two micros will be launched. So that's the basic concept of having a variable PF and having a TerraForm PF file. So generally, in production, you can expect both of these files if you are working extensively on the telephone. Now, one important part to remember here is that this file name is very important. So if you do not have the same name as this file, then you will have to explicitly specify the file name. Let me also show you that. So let's call a new file custom TFWs. All right? And what we'll do is have the same content as the TerraForm TFWs file within the custom TFWs. And now let's go ahead and delete the TerraForm tfwars file. So now let's see what happens. So I'll rip the screen and we'll make a Terraform plan. Now, if you quickly go a bit up, you see the instance type is "p-two micro." So although you had specified the instance type as TerraForm, by default it does not see this file; it will only look into the file that has the name TerraForm TFWs. So that's why it is recommended that you keep the file name static as TerraForm TFWs. Now the question that comes is: What happens if I want to use only this file, which is a custom TFR? So in such cases, you can explicitly define this TFRsfile within this CLI, so let's try it out. So I'll say TerraForm Plan, then we have to specify a VETRON file, and then you specify the file name, which is custom TF files. Let's try it again, and now you can see that the instance type is two large. The next thing that I wanted to show you was the environment variable-based approach, so let's do one thing—let's set a new variable, so I'll say setting So basically, this is a Windows-specific command; we will also explore the Linux-specific one. So you do the settings, and then there is a specific format that is of the TAPI instancenst type. So this is an underscore y underscore is essentially the format of an erasable form in which you must specify the name associated with the variable, followed by a given value, say m five large. So now it says that it has successfully added the specific value associated with this variable. So now let's go ahead and do a TerraForm plan, and if you go a bit up, you still see that you have an instance type of TWO micro. So this is a Windows-specific issue. This will not really occur in Linux, so let me show you why this occurs. So when you quickly do an echo on the variable that you have saved, which is an instance type, you see that you do not really see any value associated with it. However, if you run the same commandlet in a new terminal and try it out now, you'll see you got the value here, so any time you're doing settings and setting the value associated with the variable in the same command prompt, you won't be able to feed the value, so you'll have to load a new command prompt. So now let's do one thing from the newer command prompt: let's go to the specific directory and to a TerraForm plan. So let me open up the newer one and let's go to the specific directory, and from here, let's go ahead and do a TerraForm plan. So now if you go a bit up, you see that the instance type is "m five large." So, as part of the second step, let me demonstrate how to do it in Linux. So this wave should also work for the Mac-based operating systems. So now what we do here is we make use of the export command, and you give the value, which is TF underscore VAR underscore, the name of the variable, which is instance type followed by the value. So let's say the value here is T2 nano. So now, when you do an echo on the left, you see that it works directly. So you no longer have to create a new terminal from here. So if you quickly do the Terraform plan, let's go back up. This time you should see the instance type as T-2 nano. So that's the high-level overview of the multiple approaches to variable assignment. We look into all four approaches. Now. In production environments, the best way is to always define the values within them.

6. Data Types for Variables

Hey everyone and welcome back. Now in today's video, we will be discussing the data types for variables. Now whenever you define a variable in TerraForm, you can also associate a specific type with that variable. So whenever you specify the type argument within the variable block, that will basically restrict the type of value that will be accepted as the value of the variable. So this is better explained in this specificcode block, where you have defined an explicit type of spring for the variable of image underscoreID. So now what will happen is that whenever you define a value associated with an imageid, maybe in TFRs or maybe in CLI, it will only accept a value that has a type of string, and any other value will not be accepted. So if you do not explicitly define this specific type constraint, then any value will be accepted. Now let's go ahead and understand the importance as well as the benefits of typing in variables. Now let's go ahead and understand the benefits of defining a type within the variable block with a simple use case. So the use case states that every employee in a medium corporation is assigned an identification number. Now any resource an employee creates should be created with the name of the identification number that has been assigned to the employee. So let's understand: this is an example where you define a variable TF where the instance underscore name is not defined. So this remains to be defined. So whenever an employee creates a new EC2 instance, that EC2 instance should have the name, which is the identification number. Now in TerraForm TFW, it can happen that the user enters an instance underscore name equal to John hyper one two three, which is not the identification number. So here you do not have any check that can deny the TerraForm plan if the identification number is not entered correctly. So here you have the name, then you have the number, and so on. So now, in such cases, what you can do is explicitly define a type here, which states that the type should be number. So now what will happen is that anytime Auser tries to have a TerraForm TFW or basically assign a value to the instance name that is not the number, then the TerraForm plan will fail. So that is the significance of type. So let's do one thing. Let's quickly have a quick demo post in which we'll be discussing a few more important pointers. So for today's demo, I have a very simple code block where you have a provider and a resource called an IAM user. This essentially creates an imuser within AWS. Now, if you see over here, the name is "demo user." Now that we've discussed the use case, we want any name entered by a user to be the user identification number. So initially, what you can do is have a VAR user number. All right, so this is a simple word that we have defined. Let's go ahead and also create a variable PF where we'll define a variable called "user number." All right, let's go ahead and say this now from the CLI. When you do a Terraform plan, since we have not defined the variable value, the command prompt will allow us to put that in. So let's give a random value. Say I am joined. All right, so now what has happened is that it has accepted this specific string. All right. So now you see it tries to create an "Im" user with the name "John." So this is something that is not really required. So now what an administrator can do is explicitly specify the type as a number. All right, let's go ahead and save this yet again. Let's clear the screen, and let's try to do the TerraForm plan yet again. And now again, it requests a value. So let's try I am John and immediatelyyou see you got an error which statesthat invalid value for the input variable. The value entered for the variable user number is not valid. A number is required. So it clearly states that the value "number" is required for this specific variable. So now let's go ahead and try it out once again, where we'll be specifying a number. So let's say that this is the unique identification number for the user who is creating a resource in AWS. This time, it works perfectly well. So this is one of the use cases where specifying a type within the variable can prove to be quite useful. So with this basic concept understood, let's look into some more types of keywords that can be used. So the first one is a string. String is basically a sequence of Unicode characters representing some text like "hello." So if you just say hello, So this represents a string. Then you have a list that is basically a sequential list of values identified by their position. So it starts with zero. So if you have worked with arrays, this is very similar to that. So here you have Mumbai, you have Singapore, you have the US, and so on. So you have multiple values that are available in a specific list, unlike those of a string. Then you have a map. So a map is basically a group of values identified by named variables, like name being equal to Mabel, age being equal to 52, and so on. So that is more of a map. Then you have a number, for example, 200. So numbering is something that we have already seen. So let's do one thing: let's explore a few more so that things can be better understood. So, for the next example, we'll be making use of the AWS underscore ELB resource primarily because of a few aspects, including the availability zones over here. So currently, you see that you have the list of values that are defined over here. Now we'll look into how we can make it a variable. So let's copy this entire section. And I'll create a new file called ELP PS. And let me go ahead and paste it. Now, within this, there are a few things that are not really required. So let's go ahead and remove that. We will remove the instances here, and we'll also remove this specific listener so that our code block remains small. We'll also remove the access logs over here. So this is a very simple EAV file over here. Now, again, we do not really need to understand this in detail, but what I wanted to show you is how we can make it part of the variable here. So the first part, which is the name, is very simple. So before we do that, let's do one thing. Let's go ahead and comment on this out.And now start to work on the ELB aspect. So now the name is pretty simple if you know, and we can easily make it part of the variable. So you can say "VAR ELB." So this is pretty simple. Let's also fill the variable block here. So I'll say "variable ELB underscore name. All right. So this is the first variable. Second. Here are the availability zones. Now, if you look into the availability zones, there are multiple availability zones that are available over here. And when you try to define a variable, let's try to do that. So I'll say variable, I'll say easy, and let's do that. And within this, consider VAR AZ. All right. Finally, let's have a variable like this, where you have an idle timeout. So both the idle timeout and the connection framing timeout have the same value. So let's just call it as bar timeout. We'll do the same for the Connection Training Timeout as well. And within this, let us define the timeout grid variable. The following step will be to create a TerraForm TfWar. So let's quickly do that. So I'll make a TerraForm Tfwarp file. Now, for the first thing, which is the ELBname, let's go ahead and define it. So I say ELB's name. I'll call it my ELB. The second is the timeout. So let's also configure the timeout. So I'll say timeout is equal to 400. Now, we also forgot that this is equal to over here. And next were the availability zones. So let's try to define an availability zone called us west one A. Okay, let's go ahead and do a safe. Now, from the CLI, let's go ahead and do a TerraForm plan. All right, so we had not commented on the first one. Let's quickly do that. And currently it is asking us to enter the value associated with the user number. However, this is something that we do not want. Let's comment on it out.All right, let's try it out once again. We'll do a TerraForm plan. So now it has basically asked us for the region. Now, if you look into this configuration file, we do not really have any provider that has been configured. So, if you have the provider, you can directly copy this into the ELB. Let me actually do that. So within the provider, we have the region block that is configured. So let's do a Control C yet again and do a TerraCom plan. So now immediately you got an error stating thatincorrect attribute value type and it is also showinghere and it is saying that set of stringis required for the Availability Zones. Now generally, when users see the template, they see the variable ELB name, the variable availability zone, and the variable timeout. However, from here, it is difficult to identify the value that is expected from this specific variable. And this is the reason why it is always considered a "best practice" that you manually specify the type of value that is expected. So for the ELB name, the type is expected to be String. So for the availability zones, the type that is expected is list; then for the time, the type that is expected is number. As a result, whenever a user reads this variable TF, they can create their own TerraForm TF parts file by ensuring that the value they are entering matches the value expected from a specific variable. So not only will this variable give an error if a specific type is not matching the type that is specified within the variable, but it is also a reference point, or, you can say, some kind of documentation, through which a user can quickly identify the type of value that he needs to enter. So now what we have to do is create a list, something similar to this. So let's try the US West One B, and I'll do a save. So let's clear the screen yet again. And now you have a TerraForm plan, and you see things are working as expected. And within the availability zones, you have one A, and you have one B as well. So remember that whenever you are specifying a variable, specifically if you are writing some big modules, it is very important to explicitly specify the type for each variable that you are entering. Now, before we conclude, let me actually show you the TerraForm module associated with the elastic load balancer. Now, if you go to the variables TF file over here, you will see that for each variable they have explicitly defined the type, which for the name is String. When you go back down, the security group is a list, internal is a Boolean, and so on. So there is a number for idle time, and so on. So there are multiple data types that are available, and defining things in this way is considered one of them.

Read More

Comments
* The most recent comment are at the top

Add Comments

Feel Free to Post Your Comments About EamCollection's HashiCorp Terraform Associate Certification Video Training Course which Include HashiCorp Terraform Associate Exam Dumps, Practice Test Questions & Answers.

Only Registered Members Can Download VCE Files or View Training Courses

Please fill out your email address below in order to Download VCE files or view Training Courses. Registration is Free and Easy - you simply need to provide an email address.

  • Trusted By 1.2M IT Certification Candidates Every Month
  • VCE Files Simulate Real Exam Environment
  • Instant Download After Registration.
Please provide a correct e-mail address
A confirmation link will be sent to this email address to verify your login.
Already Member? Click Here to Login

Log into your ExamCollection Account

Please Log In to download VCE file or view Training Course

Please provide a correct E-mail address

Please provide your Password (min. 6 characters)

Only registered Examcollection.com members can download vce files or view training courses.

Registration is free and easy - just provide your E-mail address. Click Here to Register

SPECIAL OFFER: GET 10% OFF

ExamCollection Premium

ExamCollection Premium Files

Pass your Exam with ExamCollection's PREMIUM files!

  • ExamCollection Certified Safe Files
  • Guaranteed to have ACTUAL Exam Questions
  • Up-to-Date Exam Study Material - Verified by Experts
  • Instant Downloads
Enter Your Email Address to Receive Your 10% Off Discount Code
A Confirmation Link will be sent to this email address to verify your login
We value your privacy. We will not rent or sell your email address

SPECIAL OFFER: GET 10% OFF

Use Discount Code:

MIN10OFF

A confirmation link was sent to your e-mail.
Please check your mailbox for a message from support@examcollection.com and follow the directions.

Next

Download Free Demo of VCE Exam Simulator

Experience Avanset VCE Exam Simulator for yourself.

Simply submit your e-mail address below to get started with our interactive software demo of your free trial.

Free Demo Limits: In the demo version you will be able to access only first 5 questions from exam.