Simplifying AWS Setup with Terraform: A Beginner's Guide Day - 64
๐ Hello, I'm Vishal, an aspiring Information Technology enthusiast currently embarking on a journey towards a Bachelor's degree in Engineering. My passion lies in exploring the dynamic realms of cloud computing and DevOps technologies, where I constantly strive to bridge the gap between innovation and practical implementation.
๐ก As a student of Information Technology, I'm on a mission to absorb knowledge, solve real-world problems, and contribute to the tech community. My academic pursuits fuel my curiosity, and my hands-on experience with cloud and DevOps tools empowers me to navigate the evolving landscape of modern technology.
๐ Join me as I share insights, discoveries, and challenges encountered on this exciting educational and professional adventure. Let's connect, collaborate, and grow together in the ever-expanding world of IT.
๐ Connect with me on social media and let's build a network that fosters learning, sharing, and innovation.
Happy coding! ๐
Introduction
Embarking on AWS provisioning becomes a delightful journey with Terraform, a robust Infrastructure as Code (IaC) tool. In this guide, we'll take you through the step-by-step process of setting up and provisioning an AWS EC2 instance using Terraform. But before we delve into the hands-on aspect, let's ensure you have all the necessary tools in your toolbox.
Prerequisites
Install AWS CLI
The AWS Command Line Interface (CLI) is the Swiss Army knife for managing AWS services seamlessly. To get started, download and configure the AWS CLI, providing a unified interface for controlling various services and automating tasks through straightforward commands.
aws configure
Create an AWS IAM User
AWS Identity and Access Management (IAM) is the linchpin for securely controlling access to AWS resources. Begin by creating an IAM user, endowing it with the requisite permissions. Make sure to retrieve the access key and secret access key associated with this user.
export AWS_ACCESS_KEY_ID=<access key> export AWS_SECRET_ACCESS_KEY=<secret access key>Add AWS Provider in Terraform Configuration
Now, let's configure your Terraform environment. Open your Terraform configuration file (
main.tf) and include the necessary details for the AWS provider.terraform { required_providers { aws = { source = "hashicorp/aws" version = "4.16" } } required_version = ">= 1.2.0" }
Specify AWS Region in Terraform Configuration
Within the same Terraform configuration file, specify the AWS region where you intend to deploy your instances.
provider "aws" { region = "us-east-1" }

Task-01: Provision AWS EC2 Instances
Now, let's dive into the heart of the matter โ provisioning AWS EC2 instances using Terraform. Update your Terraform configuration file with the following detailed code:
resource "aws_instance" "aws_ec2_test" {
count = 4
ami = "ami-08c40ec9ead489470"
instance_type = "t2.micro"
tags = {
Name = "TerraformTestServerInstance"
}
}

In this example:
count = 4: This line indicates that you want to provision four EC2 instances.ami = "ami-08c40ec9ead489470": Specify the Amazon Machine Image (AMI) you want to use for your instances.instance_type = "t2.micro": Choose the instance type, and here we've gone with the cost-effective t2.micro.tags: The instances will be tagged with a friendly name, making them easily identifiable in the AWS Management Console.
Conclusion
You've successfully navigated the initial steps of AWS provisioning using Terraform! This guide has provided detailed insights into the prerequisites and steps involved in configuring and deploying AWS EC2 instances. As you progress, feel empowered to customize configurations to suit your specific requirements. With Terraform, the seemingly complex task of managing infrastructure becomes not just powerful but also remarkably straightforward. Happy provisioning!


