How To Get Started With Terraform
A Beginners Guide With an Example project
Terraform is the infrastructure as a Code offering from HashiCorp. It is a tool for building, changing and managing infrastructure in a safe, repeatable way. Operators and Infrastructure teams can use Terraform to manage environments with a configuration language called the HashiCorp Configuration Language (HCL) for human-readable, automated deployments.
Nobody is doing the manual provision of infrastructure nowadays. Terraform is very popular as an Infrastructure as a code provisioning tool. In this post, we will see how anyone can get started with Terraform and we will do some infrastructure provisioning on your local machine.
- Prerequisites
- Installing Terraform
- Terraform Workflow
- Example Project With Docker
- Provision Infrastructure With Terraform
- Understanding Terraform State
- Terraform Inputs and Outputs
- Next Steps
- Summary
- Conclusion
Prerequisites
It’s very important to set up and configure a local development environment for the terraform. Please make sure you install the below tools before going through the entire CLI.
Installing Terraform
The first thing we need to do is to install Terraform on your local machine. Let’s do it based on your machine by going through this link here. Once the installation is complete you can check with the following commands.
terraform
terraform -version
Terraform Workflow
The next thing you need to understand is the Terraform workflow. There are three steps in the terraform core workflow.
- Write: You write the Infrastructure as code in the main.tf file or any other file. You can name this file whatever you want.
- Plan: Once you are done with the authoring, you can run this command
terraform applyto preview the changes before you actually apply this infrastructure. - Apply: After reviewing the changes in the output of the plan command, you can finally run this command
terraform applyto actually provision infrastructure.
Example Project With Docker
Now, you know the core workflow of Terraform. Let’s create a sample project which demonstrates this workflow. This is a simple Angular with Nodejs example project in which we can add users, count, and display them at the side, and retrieve them whenever you want.

You can clone the project with the following URL
// clone the project
git clone https://github.com/bbachi/angular-nodejs-minikube.gitHere is the Dockerfile for this application. We are using multi-stage builds here. In this multi-stage build, building an Angular project and put those static assets in the dist folder is the first step. The second step involves taking those static build files and serve those with the node server.














