A pet peeve of mine when I was new to tech, or even today when new tech finds its way to me, is when a tutorial picks up in the middle of the knowledge journey. It’s no fault of the author; many times, tutorials are simply not aimed at the complete novice - the tutorial author created it because they learned something useful or cool and want to share that knowledge with like-minded people.
What if, however, you don't have the fundamental questions answered, like "why" does this tech exist? How does it help me? Why should I care to learn it? I will review those questions quickly below; if you already know the "why" for Terraform, then skip this section.
I am assuming that if you are reading this, you have either installed a server OS on a piece of hardware or have manually created servers in the cloud at some point. You have the experience of clicking from screen to screen, answering questions, choosing options, and filling in the blanks as needed to create a server in the cloud. Then you have moved on and created other resources in the cloud like load balancers, storage, subnets, etc.--but again, clicking and typing your way through the process. That’s the manual version of Terraform. It is very slow, and because we are human, we are prone to typo or misconfiguration errors.
Terraform exists to:
What would take 40 minutes of manual clicking and typing can be done in 3 minutes. The end result not only gets done faster, but it’s always the same! If you work with a team, you can share this code (aka IaC or Infrastructure as Code) with them through services like GitHub. Sharing, working collaboratively, refining the code, and re-using it to focus on consistent, secure cloud services. Sounds nice, right?
Terraform here, Terraform there, everywhere engineers look in the modern job landscape, you will find the need for Terraform.
There's a good reason for it. Although there are other IaC tools (AWS CloudFormation & Pulumi, for instance), Terraform is and has been the dominant tool because it is cloud agnostic, declarative, and has a strong ecosystem and community support.
Starting from the top:
IaC: Infrastructure as code - this is the concept of turning your manual efforts of building infrastructure (virtual machines, load balancers, user identities/roles, DNS, etc.) into code. This code can be built once and re-used many times. It results in a uniform, consistent deployment of infrastructure. It can also be stored in Git platforms like Github for simplified management of the code itself.
Cloud Agnostic: Within Terraform, there is the concept of a "provider,” A Terraform provider is all of the pieces of code needed to interact with a specific cloud service provider (like AWS). The Terraform provider is included in the code (at the top of your file) and is referenced throughout your IaC configuration. It’s how Terraform is aware of the little nuances within the cloud provider, like how in AWS, a virtual machine is an "EC2" instance, and in Google Cloud, it’s a "Compute Engine.”
Declarative: This is important, so try to lock this away somewhere. Terraform is a declarative language, meaning with it, you define the end-state of your infrastructure, and the code figures out how to make it happen. You don't have to define every single step to build an EC2 instance in AWS. Instead, you define the outcome. The other model is an Imperative language, which requires the user to define, in order, the steps needed to create the EC2 instance.
Alright, now you have the basic pieces of Terraform in your head. Let’s dive into the next layer of Terraform knowledge needed to get up and running.
Once the initial learning and configuration occur, Terraform is a pretty straightforward technology to work with. The challenge for me, and likely other people, was identifying the key components that enabled Terraform to work its magic while also understanding their purpose. Identifying key components without also knowing their purpose will result in confusion and frustration further down the line when your code requires debugging.
Below are--in my opinion--the basic pieces of Terraform knowledge needed.
terraform init
, terraform apply
, and terraform destroy
to initialize, create, and tear down infrastructure, respectively.
If you have made it here, be sure to check out Part 2 (coming soon) as we take this abstract knowledge and turn it into action by setting up your Windows machine with all the pieces and parts needed to build with Terraform in AWS.