AWS Builder Center
From AWS console to creating infrastructure with Terraform .

From AWS console to creating infrastructure with Terraform .

Infrastructure as code

I've been learning AWS and DevOps by working on hands-on projects. This time, I decided to try something different: creating AWS infrastructure using Terraform.
  • Earlier, I used the AWS Management Console to create and manage resources. With Terraform, I wanted to understand how the same infrastructure could be created using code.

What did I build?

I created a simple AWS infrastructure using Terraform.
The project includes:
  • VPC: Created a virtual private network in AWS.
  • Public Subnet: Created a subnet inside the VPC.
  • Internet Gateway: Connected the VPC to the internet.
  • Route Table: Added a route for internet access.
  • Security Group: Configured network access rules.
  • EC2 Instance: Launched an Amazon Linux EC2 instance.

How did I build it?

I started by installing Terraform on my Windows laptop and configuring AWS CLI to connect to my AWS account.
Then, I created a project folder and organized the Terraform configuration into separate files.
Here is how I organized the files:
  •  provider.tf  – Configures the AWS provider.
  •  main.tf  – Defines the AWS resources.
  •  variables.tf  – Defines reusable variables.
  •  terraform.tfvars  – Stores local variable values.
  •  outputs.tf  – Displays important resource details.
  •  README.md  – Documents the project.
After writing the configuration, I followed these steps:
  1.  terraform init  – Initializes the Terraform project.
  1.  terraform fmt  – Formats the configuration files.
  1.  terraform validate  – Checks the configuration for errors.
  1.  terraform plan  – Shows what Terraform is going to create.
  1.  terraform apply  – Creates the AWS infrastructure.
  1.  terraform destroy  – Removes the infrastructure after testing.

What challenges did I face?

Initially, I made a small mistake while using Terraform variables.
I wrote  var.vpc_cidr  inside quotation marks instead of referencing it directly.
For example:
cidr_block = "var.vpc_cidr"
The correct syntax is:
cidr_block = var.vpc_cidr
It was a small mistake, but it helped me understand how Terraform variables work.
I also learned how to use variables for configuration values and outputs to display resource information.

What did I learn?

This project helped me understand:
  • How Terraform communicates with AWS.
  • How to provision multiple AWS resources using code.
  • How AWS networking components connect with each other.
  • How to organize Terraform files.
  • How to validate, plan, create, and destroy infrastructure.
One important thing I learned is that creating infrastructure is only one part of the process. Cleaning it up after testing is equally important.
I destroyed the resources after completing the project to avoid unnecessary AWS charges.

Project Repository

I have uploaded the project files and documentation to GitHub.
This was a good learning experience for me.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article