I am new to terraform, have created 3 ec2 instances, and i have created 6 ebs volume. How do we attach 2 ebs volumes to each of the three instances?
#Create 6 EBS volumes and attach 2 per instance.
resource "aws_ebs_volume" "vertica_ebs" {
count = "6"
availability_zone = "${var.availability_zone}"
size = "500"
type = "st1"
}
}
#Attach ebs volume
resource "aws_volume_attachment" "ebs_att" {
count = "6"
volume {
device_name = "/dev/sdf"
volume_id = "[${element(aws_ebs_volume.vertica_ebs.*.id, count.index)}]"
}
volume{
device_name = "/dev/sdg"
volume_id = "[${element(aws_ebs_volume.vertica_ebs.*.id, count.index)}]"
}
instance_id = "[${element(aws_instance.vertica1.*.id,count.index)}]"
}
Errors:
- aws_volume_attachment.ebs_att #2: "device_name": required field is not set
- aws_volume_attachment.ebs_att #2: "volume_id": required field is not set
- aws_volume_attachment.ebs_att #2: : invalid or unknown key: volume
- aws_volume_attachment.ebs_att #4: "device_name": required field is not set
- aws_volume_attachment.ebs_att #4: "volume_id": required field is not set
- aws_volume_attachment.ebs_att #4: : invalid or unknown key: volume
- aws_volume_attachment.ebs_att #3: "device_name": required field is not set
- aws_volume_attachment.ebs_att #3: "volume_id": required field is not set
- aws_volume_attachment.ebs_att #3: : invalid or unknown key: volume
- aws_volume_attachment.ebs_att #0: "volume_id": required field is not set
- aws_volume_attachment.ebs_att #0: "device_name": required field is not set
- aws_volume_attachment.ebs_att #0: : invalid or unknown key: volume
- aws_volume_attachment.ebs_att #1: "device_name": required field is not set
- aws_volume_attachment.ebs_att #1: "volume_id": required field is not set
- aws_volume_attachment.ebs_att #1: : invalid or unknown key: volume
- aws_volume_attachment.ebs_att #5: "volume_id": required field is not set
- aws_volume_attachment.ebs_att #5: "device_name": required field is not set
- aws_volume_attachment.ebs_att #5: : invalid or unknown key: volume
But the below code is creating only 2 ebs volumes.
This sentence seems unfinished, what was the expected outcome of the code snippet you pasted? Is it not applying the different types correctly? Are you asking for help with additional code to associate it with an EC2 instance? – Anthony Neace