From the course: Learning Terraform

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Variables

Variables

- [Instructor] I've been a bit hand wavy about variables in Terraform so far, hoping that we could cover a good foundation of resources before we talk about them. Here's some code for how you might define a variable for the AMI of an instance or ASG resource. This example also defines a default so you'll always have a base. We can use a variable like this in the instance config. Using variables like this can be a handy way of organizing your code by keeping together anything you might change often, like the AMI ID, or say, the allow list of IP addresses for your security group. It's possible to override that default value in Terraform Cloud or with the command line by passing in the -var parameter, which looks something like this. Although that can be handy for learning and QA uses, it feels like a fairly manual process not in the spirit of Terraform. Let's take a look at data sources, which are like variables, but allow data to be retrieved from elsewhere. For example, pulled from…

Contents