Skip to content

Instantly share code, notes, and snippets.

@mdrobnak
Created January 15, 2019 06:49
Show Gist options
  • Save mdrobnak/73deec3f1b895eead3eea154dc769980 to your computer and use it in GitHub Desktop.
Save mdrobnak/73deec3f1b895eead3eea154dc769980 to your computer and use it in GitHub Desktop.
Multiple instances with 2 EBS volumes each
variable "count" {}
resource "aws_instance" "server" {
ami = "ami-7ea88d1b"
instance_type = "t2.micro"
key_name = "normal"
count = "${var.count}"
}
resource "aws_ebs_volume" "volume1" {
availability_zone = "${aws_instance.server.*.availability_zone[count.index]}"
type = "gp2"
size = 1
count = "${aws_instance.server.count}"
}
resource "aws_volume_attachment" "volume1-volume-attachment" {
device_name = "/dev/xvdb"
instance_id = "${aws_instance.server.*.id[count.index]}"
volume_id = "${aws_ebs_volume.volume1.*.id[count.index]}"
count = "${aws_instance.server.count}"
}
# Second volume
resource "aws_ebs_volume" "volume2" {
availability_zone = "${aws_instance.server.*.availability_zone[count.index]}"
type = "gp2"
size = 2
count = "${aws_instance.server.count}"
}
resource "aws_volume_attachment" "volume2-volume-attachment" {
device_name = "/dev/xvdc"
instance_id = "${aws_instance.server.*.id[count.index]}"
volume_id = "${aws_ebs_volume.volume2.*.id[count.index]}"
count = "${aws_instance.server.count}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment