Terraform-EBS Volume
Create EBS Volume
provider “aws” {
region = “us-east-1”
}
resource “aws_ebs_volume” “ebsvolume” {
availability_zone = “us-east-1d”
size = 1
encrypted = false
tags = {
Name = “raman test vol”
}
}
Attach the volume
provider “aws” {
region = “us-east-1”
}
resource “aws_ebs_volume” “ebsvolume” {
availability_zone = “us-east-1d”
size = 1
encrypted = false
tags = {
Name = “raman test vol”
}
}
resource “aws_volume_attachment” “inst1” {
device_name = “/dev/sdb”
instance_id = “i-0303681c628158d54”
volume_id = “vol-0ab1a4d0c2ad991d5”
}
Example2
resource “aws_ebs_volume” “ebsvolume” {
availability_zone = “ap-south-1a”
size = 1
encrypted = false
tags = {
Name = “raman test vol”
}
}
resource “aws_instance” “ins1” {
ami = “ami-0108d6a82a783b352”
instance_type = “t2.micro”
key_name = “devops”
availability_zone = “ap-south-1a”
}
resource “aws_volume_attachment” “mountvolumetoec2” {
device_name = “/dev/sdb”
instance_id = aws_instance.ins1.id
volume_id = aws_ebs_volume.ebsvolume.id
}