Terraform and AWS: What I Learned as a Beginner
I started exploring Terraform while learning AWS and DevOps. In this post, I share what I understood about Infrastructure as Code, the basic Terraform workflow, and how Terraform can be used with AWS and Jenkins.
My First Experience with Terraform and AWS
When I started learning AWS, I used the AWS Console to create and manage resources. It was easy to understand at first, but I soon realized that manually creating resources is not always the best approach.
While learning DevOps, I came across Terraform and the concept of Infrastructure as Code (IaC). I wanted to understand how infrastructure could be created using code instead of doing everything manually in the AWS Console.
What is Terraform?
Terraform is an Infrastructure as Code tool developed by HashiCorp.
The basic idea is simple: instead of manually creating infrastructure, we write what we want in a configuration file and Terraform takes care of creating it.
For example:
1
2
3
4
5
6
7
provider "aws" {
region = "us-east-1"
}
resource "aws_s3_bucket" "my_bucket" {
bucket = "my-terraform-demo-bucket"
}
Here, I am telling Terraform that I want to work with AWS and create an S3 bucket.
The configuration is written using HCL (HashiCorp Configuration Language).
Understanding the Terraform Workflow
The first thing I learned was the basic Terraform workflow.
1. Terraform Init
I started with:
1
terraform init
This initializes the Terraform project and downloads the required provider.
For an AWS project, Terraform needs the AWS provider so that it can communicate with AWS.
2. Terraform Plan
After initialization:
1
terraform plan
This was one of the most useful commands for me.
It shows what Terraform is planning to do before actually making changes.
For example, if I add a new resource to my configuration,
terraform plan can show that Terraform is going to create that resource.3. Terraform Apply
After checking the plan:
1
terraform apply
Terraform asks for confirmation and then creates the infrastructure.
So the basic flow is:
1
2
3
4
5
terraform init
↓
terraform plan
↓
terraform apply
Once I understood these three commands, Terraform started to make much more sense.
Why Not Just Use the AWS Console?
The AWS Console is useful, especially when learning AWS for the first time. But imagine having many resources and needing to create the same setup again.
Doing everything manually would take time.
With Terraform, the infrastructure is written as code.
This means the configuration can also be stored in Git and shared with other team members.
For me, this was the main difference I understood between manually creating resources and using Terraform.
Terraform State
Another concept I found important was the Terraform state file.
Terraform uses a file called:
1
terraform.tfstate
This helps Terraform keep track of the infrastructure that it manages.
At first, the state concept was a little confusing to me. But the basic idea is that Terraform needs to know the relationship between the configuration and the actual resources it has created.
For real projects and teams, state should be handled carefully and is often stored remotely.
Terraform with Jenkins
I also explored how Terraform can be connected with Jenkins.
A simple workflow can look like:
1
2
3
4
5
6
7
8
9
10
11
GitHub
↓
Jenkins
↓
Terraform Init
↓
Terraform Plan
↓
Terraform Apply
↓
AWS
This is where Terraform becomes interesting from a DevOps perspective.
Instead of running Terraform manually every time, a CI/CD pipeline can be used to automate the process.
For example, Jenkins can take the Terraform code from a GitHub repository and run the required Terraform commands.
What I Learned
The biggest thing I learned from Terraform is that cloud infrastructure can also be treated as code.
Some concepts that became clearer to me while practicing were:
- Infrastructure as Code
- Terraform providers
- Resources
- Terraform state
init,plan, andapply- Git-based infrastructure management
- Infrastructure automation
- CI/CD integration
I also learned that understanding the basics is more important than trying to learn every Terraform feature at once.
Final Thoughts
Terraform looked complicated when I first came across it, but after actually writing a few configuration files and running the commands, the idea became much easier.
If you are learning AWS and DevOps, I would recommend trying Terraform with a small project instead of only watching tutorials.
Start with one resource, understand
init, plan, and apply, and then slowly add more.Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article