Chapter 2. Deploying First Server

Now that we know which problem Terraform solves, we can proceed to learning how exactly it works and how to use it. In this chapter, you will learn a bit about Terraform's history, install it on our workstation, prepare working environment, and run the tool for the first time. After getting everything ready for our work, we will figure out what is a Terraform provider is, and then we will take a quick tour of what AWS and EC2 are.

With this knowledge in place, we will first create an EC2 instance by hand (just to understand the pain that Terraform will eliminate) and then we will do exactly the same with the help of Terraform template. That will allow us to study the nature of Terraform state file. Once we know that, we will update our server using the same template, and finally, destroy it. By the end of the chapter, you will already have a solid knowledge of Terraform basics, and you will be ready to create a template for your existing infrastructure.

History of Terraform

Terraform was first released in July 2014 by a company named HashiCorp. It is the same company that brought some tools, such as Vagrant, Packer, and Vault. Being the fifth tool in the HashiCorp stack, it focused on providing a way to describe the complete Infrastructure as Code:

... From physical servers to containers to SaaS products, Terraform is able to create and compose all the components necessary to run any service or application. With Terraform, you describe your complete infrastructure as code, even as it spans multiple service providers. Your servers may come from AWS, your DNS may come from CloudFlare, and your database may come from Heroku. Terraform will build all these resources across all these providers in parallel. Terraform codifies knowledge about your infrastructure unlike any other tool before, and provides the workflow and tooling for safely changing and updating infrastructure. -  https://www.hashicorp.com/blog/terraform.html

Terraform is an open source tool released under Mozilla Public License, version 2.0. The code is stored (as all other tools by HashiCorp) on GitHub, and anyone can contribute to its development.

As a part of its Atlas product, HashiCorp also offers a hosted service named Terraform Enterprise, which solves some of the problems that open source version doesn't handle well. This includes central facility to run Terraform from access control policies, remote state file storage, notifications, built-in GitHub integration, and more. Terraform Enterprise is not covered by this book, but you will learn how to achieve some (if not all) of the same functionalities using only the open source version of Terraform.

Despite the support of over 40 various providers, the main focus of HashiCorp developers is on Amazon Web Services, Google Cloud, and Microsoft Azure. All other providers are developed and supported by the community, meaning that if you are not using the main three, then you might have to contribute to the codebase yourself.

Note

Be really prepared (mentally and skill-wise) to contribute some code yourself, otherwise you might be out of luck. The author of this book faced this issue during a project that relied heavily on OpenStack. It took half a dozen Pull requests on GitHub to get OpenStack support to the desired state. And OpenStack is a rather big and popular technology. With lesser known providers, things can get more complicated very fast, due to lack of Go libraries for the provider, for example.

The code of Terraform is written in the Go programming language, and it is released as a single binary for all major operating systems. Windows, Mac OS X, FreeBSD, OpenBSD, Salaris, and any Linux distribution are supported in both 32-bit and 64-bit versions.

Terraform is still a relatively new piece of tech, being just a bit over 2 years old. It changes a lot over time and gets new features with every release. The version this book will be using is 0.81.1, and all code samples are guaranteed to run only with this version. That said, Terraform developers are trying to preserve compatibility between minor versions; likely most, if not all, of the code will work with all versions between 0.8.0 and 0.9.0, excluding the latter one.

Note

This book was started when Terraform 0.7 was the latest release. Some companies are still stuck with this version. Because of this, every now and then you will see tips for 0.7.x releases as well.

Having learned these facts, let's finally proceed to installing Terraform and setting up our workplace.

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

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