The Terraform Book
TheTerraformBook_sample
TheTerraformBook_sample
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Chapter 3: Building an application stack with <strong>Terraform</strong><br />
Let’s update our provider with the new variables we’ve just created.<br />
Listing 3.7: Adding our new variables<br />
provider "aws" {<br />
access_key = "${var.access_key}"<br />
secret_key = "${var.secret_key}"<br />
region = "${var.region}"<br />
}<br />
We’ve specified <strong>Terraform</strong>’s interpolation syntax: ${ }. Inside that syntax we’ve<br />
specified our three variables. Each variable is identified as a variable by the var.<br />
prefix. Currently only one of these variables has a value, the default of us-east<br />
-1 we’ve set for the var.region variable. Soon we’ll see how to populate values<br />
for the other variables.<br />
TIP Since <strong>Terraform</strong> 0.8 there is a command called terraform console. <strong>The</strong><br />
console is a <strong>Terraform</strong> REPL that allows you to work with interpolations and other<br />
logic. It’s a good way to explore working with <strong>Terraform</strong> syntax. You can read<br />
about it in the console command documentation.<br />
Maps<br />
Most of our variable examples have, thus far, been strings. We can also specify<br />
two other types of variables: maps and lists. Let’s look at maps first.<br />
Maps are associative arrays and ideal for situations where you want to use one<br />
value to look up another value. For example, one of our potential configuration<br />
attributes is the EC2 instance’s AMI. AMIs are region specific, so if we change<br />
Version: v1.1.1 (e771e4d) 7