0% found this document useful (0 votes)
11 views9 pages

Provision EC2 Instance With EBS Volume Using Terraform 1722666558

This document outlines the steps to provision an EC2 instance with a 3 GB EBS volume using Terraform. It includes prerequisites, IAM user creation, Terraform and AWS CLI installation, and the configuration of Terraform files. Finally, it details the initialization and application of the Terraform configuration to verify the successful creation and attachment of the EBS volume to the EC2 instance.

Uploaded by

mkshahi2024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views9 pages

Provision EC2 Instance With EBS Volume Using Terraform 1722666558

This document outlines the steps to provision an EC2 instance with a 3 GB EBS volume using Terraform. It includes prerequisites, IAM user creation, Terraform and AWS CLI installation, and the configuration of Terraform files. Finally, it details the initialization and application of the Terraform configuration to verify the successful creation and attachment of the EBS volume to the EC2 instance.

Uploaded by

mkshahi2024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Provision EC2 Instance with EBS Volume using Terraform

Prerequites -
- Terraform configuration is created to define an EC2 instance and a 3 GB
EBS volume.
- The Terraform code is applied, and an EC2 instance is provisioned in
your AWS account with the any AMI and instance type of your choice.
- An EBS volume of 3 GB is created. - The EBS volume is successfully
attached to the EC2 instance.
Step 1: Verify the aws console-
1. Login to AWS Management Console:
2. Navigate to the EC2 service in the AWS Management Console.
3. Verify that the EC2 Instance is created.

Step 2: Configuring AWS IAM credentials -


1. Create IAM user: In AWS Management Console, search “IAM” in the
services search bar and select “IAM”.
2. Click on “Users” from the left-hand navigation pane.
3. Click on “Add user” button. User name: Enter a user name.
Permission -
4. Set permissions: Choose “Attach policies directly”.
5. Search and select the ‘AdministratorAccess’ policy. Click “Next”.

Ankita Lunawat
6. Click on user and click on “Security credentials”.
7. Click on “Create access key”.
8. Select “Command Line Interface (CLI).
9. Tick the confirmation box, click Next.
10. After creating access key successfully, you’ll get the
credentials that you need to configure AWS on your Windows
machine.

Ankita Lunawat
Step 3: Install Terraform
1. Download Terraform.
2. Visit the Terraform downloads page.
(https://developer.hashicorp.com/terraform/install# windows)
3. Download the Windows 64-bit ZIP file. 2.Extract the ZIP file.
4. Right click on the downloaded zip file and select “Extract All”.
Command –
wget-O-https://apt.releases.hashicorp.com/gpg|sudogpg--dearmor-o
/usr/share/keyrings/hashicorp-archive-keyring.gpg
echo"deb[signed-by=/usr/share/keyrings/hashicorp-archive-
keyring.gpg] https://apt.releases.hashicorp.com$(lsb_release-
cs)mainsudo/etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform
Open a Command prompt and run the following command to verify
Terraform is installed successfully - terraform version

Ankita Lunawat
Step 4: To install the AWS CLI on Ubuntu
1: Update Your Package List
First, ensure your package list is up-to-date - #sudo apt update
2: Install Prerequisites
The AWS CLI requires unzip and curl, so make sure these are installed:
#sudo apt install unzip curl -y
3: Download the AWS CLI Bundle
Download the AWS CLI installation bundle using curl:
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip"
-o "awscliv2.zip"

Ankita Lunawat
4: Unzip the Installation Bundle
Unzip the downloaded bundle - #unzip awscliv2.zip
5: Run the Install Script
Run the AWS CLI install script - sudo ./aws/install
6: Verify the Installation
Check that the AWS CLI is installed correctly by verifying its version:
aws –version
7: Configure the AWS CLI
To configure the AWS CLI with your credentials, run:
aws configure

Step 1: Create Terraform Configuration Files


Create ‘provider.tf’ file.

Ankita Lunawat
Open a text editor (e.g., Notepad, Visual Studio Code).
Create a new file named ‘provider.tf’ and add the following
content.
Step 2: Write Your Terraform Configuration
Create a new file called main.tf and add the following code –

# main.tf
# Specify the provider
provider "aws" {
region = "us-west-2" # Replace with your preferred region
}
# Create a new EC2 instance
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0" # Replace with an appropriate AMI
ID for your region
instance_type = "t2.micro"
tags = {
Name = "example-instance"
}
}
# Output the public IP of the instance
output "instance_public_ip" {
value = aws_instance.example.public_ip

Ankita Lunawat
}
Save the file in the directory.
3: Initialize and Apply Terraform Configuration.
1. Initialize Terraform – terraform init

2.Apply the Configuration.


Apply the Terraform configuration by running: terraform apply.

Ankita Lunawat
When prompted, type ‘yes’ to confirm.

Verify the EC2 and EBS in AWS.

Also verify, An EBS volume of 3GB is created.

The EBS volume is successfully attached to the EC2 instance.

Ankita Lunawat
And here, I have successfully Install the Terraform and Provision EC2
Instance with EBS Volume using Terraform using CLI.

Ankita Lunawat

You might also like