Preparing work environment

In this book, we will focus on using Terraform in a Linux environment. The general usage of the tool should be the same on all platforms though some advanced topics and practices discussed in later chapters might apply only to Linux systems.

As mentioned in the previous section, Terraform is distributed as a single binary, packaged inside Zip archive. Unfortunately, HashiCorp does not provide native packages for operating systems. That means the first step is too install unzip. Depending on your package manager, this could be done by running sudo yum install unzip or sudo apt-get install unzip or might be even already be installed. In any case, after making sure that you can unarchive the Zip files, proceed to downloading Terraform from the official website,  https://www.terraform.io/downloads.html.

Unzip it to any convenient folder. Make sure that this folder is available in your PATH environment variable. A full installation command sequence could look as follows:

$> curl -O https://releases.hashicorp.com/terraform/0.8.2/terraform_0.8.2_linux_amd64.zip
$> sudo unzip terraform_0.8.2_linux_amd64.zip -d /usr/local/bin/

That will extract Terraform binary to /usr/local/bin, which is already available in PATH on Linux systems.

Finally, let's verify our installation:

$> terraform -v
Terraform v0.8.2

We have a working Terraform installation now. We are ready to write our first template. First, create an empty directory, name it packt-terraform, and enter it:

$> mkdir packt-terraform && cd packt-terraform

When you run Terraform commands, it looks for files with the .tf extension in a directory you run it from. It doesn't take files from subdirectories. Be careful: Terraform will load all files with the  .tf extension if you run it without arguments.

Let's create our very first, not yet very useful, template:

$> touch template.tf

To apply template, you need to run the terraform apply command. What does this applying mean? In Terraform, when you run apply, it will read your templates and it will try to create an infrastructure exactly as it's defined in your templates. We will go deeper into how Terraform exactly processes templates in a following chapter.

For now, let's just apply our empty template:

$> terraform apply
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

After each run is finished, you get a number of resources that you've added, changed, and destroyed. In this case, it did nothing, as we just have an empty file instead of a real template.

To make Terraform do something useful, we first need to configure our provider, and even before that, we need to find out what is provider.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.251.22