DEV Community

Dawood
Dawood

Posted on

How I Created an EC2 Instance, IAM User, and S3 Bucket Using Terraform on AWS

Introduction

As part of my DevOps learning journey, I recently explored Terraform, an Infrastructure as Code (IaC) tool that helps automate cloud resource provisioning. Instead of manually creating resources in AWS, Terraform allows us to define infrastructure using code.

In this blog, I’ll share how I used Terraform to create an EC2 instance, IAM user, and S3 bucket in AWS.


What is Terraform?

Terraform is an open-source Infrastructure as Code (IaC) tool developed by HashiCorp. It helps automate cloud infrastructure creation using configuration files.

With Terraform, we can:

  • Automate infrastructure setup
  • Manage cloud resources efficiently
  • Reduce manual work
  • Maintain consistent environments

Instead of creating resources manually in AWS Console, Terraform allows us to create them using code.


AWS Resources I Created

In this project, I created:

  1. EC2 Instance – To launch a virtual server in AWS
  2. IAM User – To manage permissions securely
  3. S3 Bucket – To store files and objects in AWS

Prerequisites

Before starting, I completed the following setup:

  • AWS Account
  • AWS CLI configured
  • Terraform installed
  • IAM permissions for resource creation

Step 1: Configure AWS Credentials

First, I configured AWS credentials using AWS CLI:

aws configure
Enter fullscreen mode Exit fullscreen mode

Then I entered:

  • AWS Access Key
  • Secret Access Key
  • Region
  • Output format

This allows Terraform to communicate with AWS.


Step 2: Write Terraform Configuration

I created Terraform configuration files to define AWS resources.

The configuration included:

  • Provider configuration for AWS
  • EC2 instance setup
  • IAM user creation
  • S3 bucket configuration

Terraform uses .tf files to define infrastructure.


Step 3: Initialize Terraform

To initialize Terraform, I used:

terraform init
Enter fullscreen mode Exit fullscreen mode

This command downloads required provider plugins.


Step 4: Review Infrastructure Changes

Before creating resources, I checked the execution plan:

terraform plan
Enter fullscreen mode Exit fullscreen mode

This command shows what resources Terraform will create.


Step 5: Create AWS Resources

Finally, I applied the configuration:

terraform apply
Enter fullscreen mode Exit fullscreen mode

After confirmation, Terraform successfully created:

✅ EC2 Instance
✅ IAM User
✅ S3 Bucket


Challenges I Faced

While working on this project, I encountered a few issues such as:

  • Incorrect AMI ID
  • Permission-related errors
  • Terraform syntax mistakes

By checking error messages and updating configurations, I was able to resolve them.


Key Learnings

Through this project, I learned:

  • Basics of Terraform
  • Infrastructure as Code (IaC)
  • AWS resource automation
  • Terraform commands like init, plan, and apply

Conclusion

This hands-on project helped me understand how Terraform simplifies cloud infrastructure management. Instead of manually creating AWS resources, I learned how to automate everything using code.

I’m continuing to explore more DevOps tools and cloud technologies as part of my learning journey.

Thank you for reading!

Enter fullscreen mode Exit fullscreen mode

Top comments (0)