main.tf 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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, key_name, user_data ] }
  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 don't support count yet! Time to migrate to 0.13 beta!
  69. # Seriously, though, if we change the count, we will have to change
  70. # this module, _if_ we want DNS entries.
  71. module "private_dns_record_0" {
  72. source = "../../submodules/dns/private_A_record"
  73. name = "interconnect-0"
  74. ip_addresses = [ aws_instance.interconnects[0].private_ip ]
  75. dns_info = var.dns_info
  76. providers = {
  77. aws.c2 = aws.c2
  78. }
  79. }
  80. module "private_dns_record_1" {
  81. source = "../../submodules/dns/private_A_record"
  82. name = "interconnect-1"
  83. ip_addresses = [ aws_instance.interconnects[1].private_ip ]
  84. dns_info = var.dns_info
  85. providers = {
  86. aws.c2 = aws.c2
  87. }
  88. }
  89. module "public_dns_record_0" {
  90. source = "../../submodules/dns/public_A_record"
  91. name = "interconnect-0"
  92. ip_addresses = [ aws_eip.interconnects[0].public_ip ]
  93. dns_info = var.dns_info
  94. providers = {
  95. aws.mdr-common-services-commercial = aws.mdr-common-services-commercial
  96. }
  97. }
  98. module "public_dns_record_1" {
  99. source = "../../submodules/dns/public_A_record"
  100. name = "interconnect-1"
  101. ip_addresses = [ aws_eip.interconnects[1].public_ip ]
  102. dns_info = var.dns_info
  103. providers = {
  104. aws.mdr-common-services-commercial = aws.mdr-common-services-commercial
  105. }
  106. }