From the course: HashiCorp Certified: Terraform Associate (003) Cert Prep by KodeKloud
Unlock this course with a free trial
Join today to access over 25,200 courses taught by industry experts.
Recap: Variables - Terraform Tutorial
From the course: HashiCorp Certified: Terraform Associate (003) Cert Prep by KodeKloud
Recap: Variables
- [Instructor] Now let's recap what we know about variables in Terraform. Instead of using hard-coded values in our configuration, we can make use of variables. To assign variables, we need to make use of a variable block like this. It is a common practice to define variables in a new file called variables.tf, as we've done in this case. But keep in mind that this is not entirely necessary, as we can very well define the variable blocks, along with the resource blocks, in the main.tf file. To create a variable, we have used the keyword called variable, and this is followed by the variable name. Now, this can be named anything, but as a standard, use an appropriate name, such as the argument name. Within this block, we can provide a default value for the variable. This is an optional argument, but it provides us a quick and easy way to assign values for the variables. Now, to make use of these variables within our configuration file, we can replace the argument values with the variable…