Open In App

How To Create EBS Volume In AWS Using Terraform

EBS Stands for Elastic Block Storage is a block-level storage service provided by Amazon web services to use with Amazon’s Elastic Compute Cloud (EC2) instances.It provides persistent, high-performance storage volumes that can be attached to Amazon EC2 instances. it acts as an attached external hard drive to your instances. These EBS Volumes can be dynamically scaled to accommodate changing storage requirements. users can increase the size of a volume without detaching it from the instance, enabling them to scale storage capacity on-demand as they need.

What Is Terraform?

Terraform is an open-source Infrastructure as Code (IaC) tool created by HashiCorp. It allows DevOps teams to define and provision cloud infrastructure resources across multiple cloud providers and on-premises environments. Terraform is widely used IaC tool because of its key advantage it can be easily integrated with multiple cloud providers like AWS, Azure and GCP. The key idea for developing Terraform is to make it easy to define, provision, and manage cloud infrastructure using code, in a consistent way across different cloud environments.



Features Of Terraform

The following are the features of Terraform:

Important Terraform Commands

Here are the essential Terraform commands which commonly used:



Step by Step Guide To Create EBS Volume In AWS Using Terraform

Step 1: Open the Amazon EC2 console and log in with your credentials.

Step 2: Go to EC2 Console and launch one Linux EC2 instance to perform this practical

Step 3: Login to the EC2 instance and Firstly Configure your AWS Credentials using AWS Configure command.

Note: Make sure you installed AWS CLI to perform this step

/usr/local/bin/aws configure

Enter necessary fields like access key, secret key etc. of AWS account after entering the command

Step 4: After Configuring credentials now we need to install Terraform follow article Setup Terraform On Linux and Windows Machine

Step 5: After completion of installing terraform create one terraform file using vi command as below:

vi main.tf

The created file named main.tf copy the below code to it. This code helps in defining the configuration resource for creating EBS Volume in AWS account.

# Configure the AWS provider
provider "aws" {
region = "ap-south-1" # Replace with your desired AWS region
}

# Create an EBS volume
resource "aws_ebs_volume" "Terraform_Volume" {
availability_zone = "ap-south-1a" # Replace with your desired Availability Zone
size = 10 # Specify the size of the volume in GiB

tags = {
Name = "Terraform_Volume" # Removed leading space for the volume name
}
}

Step 6: Save the file by pressing ESC button and entering :wq! command

Step 7: Now we need to run this terraform file to do so, we have to firstly intialize the terraform, enter following command

terraform init

Step 8: Now Run Terraform plan command to review the changes in our terraform file

terraform plan

Step 9: After reviewing what is going to happen, we need to run terraform apply command to finally create EBS Volume

terraform apply

Step 10: In the final Step, go to the volumes menu in EC2 Console, you will see that EBS Volume created using terraform

Note: The volume which has empty name is the root volume of our EC2 instance

Advantages of Terraform

The following are the advantages of terraform:

Disadvantages Of Terraform

The following are the disadvantages of terraform:

Amazon EBS And Terrafrom – FAQs

What Is The Minimum Size For An EBS Volume?

The minimum size for an EBS volume is 1 GB.

Can I Create An Ebs Volume From A Snapshot?

Yes, you can create an EBS volume from an existing snapshot using the snapshot_id argument in the aws_ebs_volume resource.

Can I Create An EBS Volume With Provisioned Iops?

Yes, you can create an EBS volume with provisioned IOPS (for the io1 volume type) by using the iops argument in the aws_ebs_volume resource.

How Do I Delete An EBS Volume Created Using Terraform?

To delete an EBS volume created using Terraform, you need to remove the corresponding aws_ebs_volume resource from your Terraform configuration and run terraform apply. Terraform will detect the resource needs to be deleted and remove it.


Article Tags :