The Terraform Book
TheTerraformBook_sample
TheTerraformBook_sample
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Chapter 3: Building an application stack with <strong>Terraform</strong><br />
Listing 3.72: A conditional attribute<br />
module "vpc" {<br />
. . .<br />
cidr = "${var.region} != "us-east-1" ? "172.16.0.0/12" :<br />
"172.18.0.0/12"}"<br />
. . .<br />
}<br />
Here we’re setting the value of the cidr attribute using a ternary conditional. If the<br />
var.region variable is not equal to us-east-1 then use the CIDR of 172.16.0.0/12<br />
. If it is equal then use 172.16.0.0/12.<br />
TIP You can read more about conditionals in their documentation.<br />
Now let’s look at provisioning some application configuration on our EC2 instances.<br />
Provisioning our stack<br />
Provisioning is the process of adding configuration, packages, applications, and<br />
services to the infrastructure we’re creating. It usually involves making more<br />
granular changes to our infrastructure than we do with <strong>Terraform</strong>—for example,<br />
installing Apache on an EC2 instance. For complex provisioning we’re likely to<br />
hand off the task to a dedicated tool like Puppet, Chef, or Ansible. For our stack,<br />
however, we’re going to do some simple provisioning using EC2 user data. With<br />
Version: v1.1.1 (e771e4d) 57