main.tf 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. resource "aws_placement_group" "interconnects" {
  2. # Distribute them
  3. name = "interconnects"
  4. strategy = "spread"
  5. }
  6. module "typical_host_security_group" {
  7. source = "../../submodules/security_group/typical_host"
  8. vpc_id = var.security_vpc
  9. cidr_map = var.cidr_map
  10. tags = merge(var.standard_tags, var.tags)
  11. aws_region = var.aws_region
  12. aws_partition = var.aws_partition
  13. }
  14. resource "aws_network_interface" "interconnects" {
  15. count = var.interconnects_count
  16. subnet_id = var.subnet_id_map["untrusted"][count.index % 2]
  17. security_groups = [ module.typical_host_security_group.id, aws_security_group.interconnects_sg.id ]
  18. source_dest_check = false
  19. private_ips_count = 0
  20. description = "XDR Interconnect ${count.index}"
  21. tags = {
  22. Name = "interconnect-${count.index}"
  23. }
  24. }
  25. resource "aws_eip" "interconnects" {
  26. count = var.interconnects_count
  27. vpc = true
  28. tags = {
  29. Name = "interconnect-${count.index}"
  30. }
  31. }
  32. resource "aws_eip_association" "interconnects" {
  33. count = var.interconnects_count
  34. network_interface_id = aws_network_interface.interconnects[count.index].id
  35. allocation_id = aws_eip.interconnects[count.index].id
  36. }
  37. resource "aws_instance" "interconnects" {
  38. count = var.interconnects_count
  39. availability_zone = var.azs[count.index % 2]
  40. placement_group = aws_placement_group.interconnects.id
  41. tenancy = "default"
  42. ebs_optimized = true
  43. disable_api_termination = var.instance_termination_protection
  44. instance_initiated_shutdown_behavior = "stop"
  45. instance_type = var.interconnects_instance_type
  46. key_name = var.interconnects_key_name
  47. monitoring = false
  48. ami = data.aws_ami.minion.id
  49. lifecycle { ignore_changes = [ ami, key_name, user_data ] }
  50. tags = merge(
  51. var.standard_tags,
  52. var.tags,
  53. {
  54. Name = "interconnect-${count.index}"
  55. }
  56. )
  57. volume_tags = merge(
  58. var.standard_tags,
  59. var.tags,
  60. {
  61. Name = "interconnect-${count.index}"
  62. }
  63. )
  64. root_block_device {
  65. volume_type = "gp2"
  66. #volume_size = "60"
  67. delete_on_termination = true
  68. }
  69. network_interface {
  70. device_index = 0
  71. network_interface_id = aws_network_interface.interconnects[count.index].id
  72. }
  73. user_data = data.template_cloudinit_config.cloud-init[count.index].rendered
  74. iam_instance_profile = "msoc-default-instance-profile"
  75. #lifecycle {
  76. # This might allow us to update/replace easier?
  77. #create_before_destroy = true
  78. #}
  79. }
  80. # DNS Records don't support count yet! Time to migrate to 0.13 beta!
  81. # Seriously, though, if we change the count, we will have to change
  82. # this module, _if_ we want DNS entries.
  83. module "private_dns_record_0" {
  84. source = "../../submodules/dns/private_A_record"
  85. name = "interconnect-0"
  86. ip_addresses = [ aws_instance.interconnects[0].private_ip ]
  87. dns_info = var.dns_info
  88. providers = {
  89. aws.c2 = aws.c2
  90. }
  91. }
  92. module "private_dns_record_1" {
  93. source = "../../submodules/dns/private_A_record"
  94. name = "interconnect-1"
  95. ip_addresses = [ aws_instance.interconnects[1].private_ip ]
  96. dns_info = var.dns_info
  97. providers = {
  98. aws.c2 = aws.c2
  99. }
  100. }
  101. module "public_dns_record_0" {
  102. source = "../../submodules/dns/public_A_record"
  103. name = "interconnect-0"
  104. ip_addresses = [ aws_eip.interconnects[0].public_ip ]
  105. dns_info = var.dns_info
  106. providers = {
  107. aws.mdr-common-services-commercial = aws.mdr-common-services-commercial
  108. }
  109. }
  110. module "public_dns_record_1" {
  111. source = "../../submodules/dns/public_A_record"
  112. name = "interconnect-1"
  113. ip_addresses = [ aws_eip.interconnects[1].public_ip ]
  114. dns_info = var.dns_info
  115. providers = {
  116. aws.mdr-common-services-commercial = aws.mdr-common-services-commercial
  117. }
  118. }