instances.tf 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. root_block_device { volume_size = var.node-root-size }
  11. tags = merge({ Name = "RedisEnterprise-${var.vpc-name}-${count.index}" }, var.common-tags)
  12. }
  13. resource "aws_eip" "re-eip" {
  14. vpc = true
  15. count = var.data-node-count
  16. tags = merge({ Name = "${var.vpc-name}-node-eip-${count.index}" }, var.common-tags)
  17. }
  18. resource "aws_eip_association" "re-eip-assoc" {
  19. count = var.data-node-count
  20. instance_id = element(aws_instance.re.*.id, count.index)
  21. allocation_id = element(aws_eip.re-eip.*.id, count.index)
  22. depends_on = [aws_instance.re, aws_eip.re-eip]
  23. }
  24. # Handle attaching volumes if enable-volumes is set (true by default)
  25. resource "aws_ebs_volume" "re-ephemeral" {
  26. count = local.count_volumes
  27. availability_zone = element(var.vpc-azs, count.index)
  28. size = var.re-volume-size
  29. tags = merge({ Name = "ephemeral-${var.vpc-name}-${count.index}" }, var.common-tags)
  30. }
  31. resource "aws_volume_attachment" "re-ephemeral" {
  32. count = local.count_volumes
  33. device_name = "/dev/sdh"
  34. volume_id = element(aws_ebs_volume.re-ephemeral.*.id, count.index)
  35. instance_id = element(aws_instance.re.*.id, count.index)
  36. }
  37. resource "aws_ebs_volume" "re-persistant" {
  38. count = local.count_volumes
  39. availability_zone = element(var.vpc-azs, count.index)
  40. size = var.re-volume-size
  41. tags = merge({ Name = "persistant-${var.vpc-name}-${count.index}" }, var.common-tags)
  42. }
  43. resource "aws_volume_attachment" "re-persistant" {
  44. count = local.count_volumes
  45. device_name = "/dev/sdj"
  46. volume_id = element(aws_ebs_volume.re-persistant.*.id, count.index)
  47. instance_id = element(aws_instance.re.*.id, count.index)
  48. }
  49. # Handle attaching volumes if enable-flash is set (false by default)
  50. resource "aws_ebs_volume" "re-flash" {
  51. count = local.count_flash
  52. availability_zone = element(var.vpc-azs, count.index)
  53. size = var.re-volume-size
  54. type = "gp2"
  55. tags = merge({ Name = "flash-${var.vpc-name}-${count.index}" }, var.common-tags)
  56. }
  57. resource "aws_volume_attachment" "re-flash" {
  58. count = local.count_flash
  59. device_name = "/dev/sdi"
  60. volume_id = element(aws_ebs_volume.re-flash.*.id, count.index)
  61. instance_id = element(aws_instance.re.*.id, count.index)
  62. }