main.tf 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. output "ami" {
  38. value = var.default_ami
  39. }
  40. resource "aws_instance" "interconnects" {
  41. count = var.interconnects_count
  42. availability_zone = var.azs[count.index % 2]
  43. placement_group = aws_placement_group.interconnects.id
  44. tenancy = "default"
  45. ebs_optimized = true
  46. disable_api_termination = var.instance_termination_protection
  47. instance_initiated_shutdown_behavior = "stop"
  48. instance_type = var.interconnects_instance_type
  49. key_name = var.interconnects_key_name
  50. monitoring = false
  51. ami = var.default_ami
  52. lifecycle { ignore_changes = [ ami, key_name, user_data ] }
  53. tags = merge(
  54. var.standard_tags,
  55. var.tags,
  56. {
  57. Name = "interconnect-${count.index}"
  58. }
  59. )
  60. root_block_device {
  61. volume_type = "gp2"
  62. #volume_size = "60"
  63. delete_on_termination = true
  64. }
  65. network_interface {
  66. device_index = 0
  67. network_interface_id = aws_network_interface.interconnects[count.index].id
  68. }
  69. user_data = data.template_cloudinit_config.cloud-init[count.index].rendered
  70. iam_instance_profile = "msoc-default-instance-profile"
  71. #lifecycle {
  72. # This might allow us to update/replace easier?
  73. #create_before_destroy = true
  74. #}
  75. }
  76. # DNS Records don't support count yet! Time to migrate to 0.13 beta!
  77. # Seriously, though, if we change the count, we will have to change
  78. # this module, _if_ we want DNS entries.
  79. module "private_dns_record_0" {
  80. source = "../../submodules/dns/private_A_record"
  81. name = "interconnect-0"
  82. ip_addresses = [ aws_instance.interconnects[0].private_ip ]
  83. dns_info = var.dns_info
  84. providers = {
  85. aws.c2 = aws.c2
  86. }
  87. }
  88. module "private_dns_record_1" {
  89. source = "../../submodules/dns/private_A_record"
  90. name = "interconnect-1"
  91. ip_addresses = [ aws_instance.interconnects[1].private_ip ]
  92. dns_info = var.dns_info
  93. providers = {
  94. aws.c2 = aws.c2
  95. }
  96. }
  97. module "public_dns_record_0" {
  98. source = "../../submodules/dns/public_A_record"
  99. name = "interconnect-0"
  100. ip_addresses = [ aws_eip.interconnects[0].public_ip ]
  101. dns_info = var.dns_info
  102. providers = {
  103. aws.mdr-common-services-commercial = aws.mdr-common-services-commercial
  104. }
  105. }
  106. module "public_dns_record_1" {
  107. source = "../../submodules/dns/public_A_record"
  108. name = "interconnect-1"
  109. ip_addresses = [ aws_eip.interconnects[1].public_ip ]
  110. dns_info = var.dns_info
  111. providers = {
  112. aws.mdr-common-services-commercial = aws.mdr-common-services-commercial
  113. }
  114. }