instances.tf 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. resource "aws_instance" "re" {
  2. count = var.data-node-count
  3. ami = data.aws_ami.re-ami.id
  4. instance_type = var.re-instance-type
  5. availability_zone = "${element(var.vpc-azs, count.index)}"
  6. subnet_id = "${element(var.vpc-subnets, count.index)}"
  7. vpc_security_group_ids = [aws_security_group.re.id]
  8. source_dest_check = false
  9. key_name = local.ssh_key
  10. tags = merge({ Name = "RedisEnterprise-${var.vpc-name}-${count.index}" }, var.common-tags)
  11. }
  12. resource "aws_ebs_volume" "re-ephemeral" {
  13. count = var.data-node-count
  14. availability_zone = "${element(var.vpc-azs, count.index)}"
  15. size = "${var.re-volume-size}"
  16. tags = merge({ Name = "ephemeral-${var.vpc-name}-${count.index}" }, var.common-tags)
  17. }
  18. resource "aws_volume_attachment" "re-ephemeral" {
  19. count = var.data-node-count
  20. device_name = "/dev/sdh"
  21. volume_id = "${element(aws_ebs_volume.re-ephemeral.*.id, count.index)}"
  22. instance_id = "${element(aws_instance.re.*.id, count.index)}"
  23. }
  24. resource "aws_ebs_volume" "re-persistant" {
  25. count = var.data-node-count
  26. availability_zone = "${element(var.vpc-azs, count.index)}"
  27. size = "${var.re-volume-size}"
  28. tags = merge({ Name = "persistant-${var.vpc-name}-${count.index}" }, var.common-tags)
  29. }
  30. resource "aws_volume_attachment" "re-persistant" {
  31. count = var.data-node-count
  32. device_name = "/dev/sdj"
  33. volume_id = "${element(aws_ebs_volume.re-persistant.*.id, count.index)}"
  34. instance_id = "${element(aws_instance.re.*.id, count.index)}"
  35. }
  36. resource "aws_ebs_volume" "re-flash" {
  37. count = local.count_flash
  38. availability_zone = "${element(var.vpc-azs, count.index)}"
  39. size = "${var.re-volume-size}"
  40. type = "io1"
  41. iops = var.flash-iops
  42. tags = merge({ Name = "flash-${var.vpc-name}-${count.index}" }, var.common-tags)
  43. }
  44. resource "aws_volume_attachment" "re-flash" {
  45. count = local.count_flash
  46. device_name = "/dev/sdi"
  47. volume_id = "${element(aws_ebs_volume.re-flash.*.id, count.index)}"
  48. instance_id = "${element(aws_instance.re.*.id, count.index)}"
  49. }
  50. resource "aws_eip" "re-eip" {
  51. vpc = true
  52. count = var.data-node-count
  53. tags = merge({ Name = "${var.vpc-name}-node-eip-${count.index}" }, var.common-tags)
  54. }
  55. resource "aws_eip_association" "re-eip-assoc" {
  56. count = var.data-node-count
  57. instance_id = "${element(aws_instance.re.*.id, count.index)}"
  58. allocation_id = "${element(aws_eip.re-eip.*.id, count.index)}"
  59. depends_on = ["aws_instance.re", "aws_eip.re-eip"]
  60. }