main.tf 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. resource "aws_placement_group" "interconnects" {
  2. # Distribute them
  3. name = "interconnects"
  4. strategy = "spread"
  5. }
  6. resource "aws_network_interface" "interconnects" {
  7. count = var.interconnects_count
  8. subnet_id = var.subnet_id_map["untrusted"][count.index % 2]
  9. security_groups = [ aws_security_group.interconnects_sg.id ]
  10. source_dest_check = false
  11. private_ips_count = 0
  12. description = "XDR Interconnect ${count.index}"
  13. tags = {
  14. Name = "interconnect-${count.index}"
  15. }
  16. }
  17. resource "aws_eip" "interconnects" {
  18. count = var.interconnects_count
  19. vpc = true
  20. tags = {
  21. Name = "interconnect-${count.index}"
  22. }
  23. }
  24. resource "aws_eip_association" "interconnects" {
  25. count = var.interconnects_count
  26. network_interface_id = aws_network_interface.interconnects[count.index].id
  27. allocation_id = aws_eip.interconnects[count.index].id
  28. }
  29. output "ami" {
  30. value = var.default_ami
  31. }
  32. resource "aws_instance" "interconnects" {
  33. count = var.interconnects_count
  34. availability_zone = var.azs[count.index % 2]
  35. placement_group = aws_placement_group.interconnects.id
  36. tenancy = "default"
  37. ebs_optimized = true
  38. disable_api_termination = var.instance_termination_protection
  39. instance_initiated_shutdown_behavior = "stop"
  40. instance_type = var.interconnects_instance_type
  41. key_name = var.interconnects_key_name
  42. monitoring = false
  43. ami = var.default_ami
  44. lifecycle { ignore_changes = [ ami ] }
  45. tags = merge(
  46. var.standard_tags,
  47. var.tags,
  48. {
  49. Name = "interconnect-${count.index}"
  50. }
  51. )
  52. root_block_device {
  53. volume_type = "gp2"
  54. #volume_size = "60"
  55. delete_on_termination = true
  56. }
  57. network_interface {
  58. device_index = 0
  59. network_interface_id = aws_network_interface.interconnects[count.index].id
  60. }
  61. user_data = data.template_cloudinit_config.cloud-init[count.index].rendered
  62. iam_instance_profile = "msoc-default-instance-profile"
  63. #lifecycle {
  64. # This might allow us to update/replace easier?
  65. #create_before_destroy = true
  66. #}
  67. }
  68. # DNS Records
  69. resource "aws_route53_record" "interconnects" {
  70. count = var.interconnects_count
  71. name = "interconnect-${ var.environment }-${ count.index }"
  72. type = "A"
  73. ttl = 300
  74. zone_id = var.dns_public["id"]
  75. records = [ aws_eip.interconnects[count.index].public_ip ]
  76. provider = aws.legacy
  77. }
  78. resource "aws_route53_record" "interconnects_pvt" {
  79. count = var.interconnects_count
  80. name = "interconnect-${ count.index }"
  81. type = "A"
  82. ttl = 300
  83. zone_id = var.dns_private["id"]
  84. records = [ aws_instance.interconnects[count.index].private_ip ]
  85. provider = aws.legacy
  86. }