master.tf 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. # Some instance variables
  2. locals {
  3. instance_name_master = "${ var.prefix }-alsi-master"
  4. }
  5. resource "aws_network_interface" "master" {
  6. subnet_id = var.subnets[0]
  7. security_groups = [ data.aws_security_group.typical-host.id, aws_security_group.alsi_master_security_group.id ]
  8. description = local.instance_name_master
  9. tags = merge( var.standard_tags,
  10. var.tags,
  11. { Name = local.instance_name_master }
  12. )
  13. }
  14. resource "aws_instance" "master" {
  15. tenancy = "default"
  16. ebs_optimized = true
  17. disable_api_termination = var.instance_termination_protection
  18. instance_initiated_shutdown_behavior = "stop"
  19. instance_type = var.instance_types["alsi-master"]
  20. key_name = "msoc-build"
  21. monitoring = false
  22. iam_instance_profile = "msoc-default-instance-profile"
  23. ami = local.ami_map[local.ami_selection]
  24. # We need to ignore ebs_block_device changes, because if the AMI changes, so does the snapshot_id.
  25. # If they add a feature to block more specific changes (eg `ebs_block_devices[*].snapshot_id`), then
  26. # that could be removed.
  27. lifecycle { ignore_changes = [ ami, key_name, user_data, ebs_block_device ] }
  28. # These device definitions are optional, but added for clarity.
  29. root_block_device {
  30. volume_type = "gp2"
  31. #volume_size = Override via var?
  32. delete_on_termination = true
  33. encrypted = true
  34. kms_key_id = data.aws_kms_key.ebs-key.arn
  35. }
  36. network_interface {
  37. device_index = 0
  38. network_interface_id = aws_network_interface.master.id
  39. }
  40. user_data = data.template_cloudinit_config.cloud-init-master.rendered
  41. tags = merge( var.standard_tags,
  42. var.tags,
  43. { Name = local.instance_name_master, }
  44. )
  45. volume_tags = merge( var.standard_tags,
  46. var.tags,
  47. { Name = local.instance_name_master, }
  48. )
  49. }
  50. module "private_dns_record_master" {
  51. source = "../../../submodules/dns/private_A_record"
  52. name = local.instance_name_master
  53. ip_addresses = [ aws_instance.master.private_ip ]
  54. dns_info = var.dns_info
  55. reverse_enabled = var.reverse_enabled
  56. providers = {
  57. aws.c2 = aws.c2
  58. }
  59. }
  60. # Render a multi-part cloud-init config making use of the part
  61. # above, and other source files
  62. data "template_cloudinit_config" "cloud-init-master" {
  63. gzip = true
  64. base64_encode = true
  65. # Main cloud-config configuration file.
  66. part {
  67. filename = "init.cfg"
  68. content_type = "text/cloud-config"
  69. content = templatefile("${path.module}/cloud-init/cloud-init.tpl",
  70. {
  71. hostname = local.instance_name_master
  72. fqdn = "${local.instance_name_master}.${var.dns_info["private"]["zone"]}"
  73. splunk_prefix = var.prefix
  74. environment = var.environment
  75. salt_master = var.salt_master
  76. proxy = var.proxy
  77. aws_partition = var.aws_partition
  78. aws_partition_alias = var.aws_partition_alias
  79. aws_region = var.aws_region
  80. }
  81. )
  82. }
  83. }
  84. ## Master
  85. #
  86. # Summary:
  87. # Ingress:
  88. # 9000 - From private ALB
  89. # 9000 - From vpc-access
  90. #
  91. # Egress:
  92. # 9997/9998 - To Splunk
  93. resource "aws_security_group" "alsi_master_security_group" {
  94. name_prefix = "${ var.prefix }_alsi_master_security_group" # name prefix and livecycle allow for smooth updates
  95. lifecycle { create_before_destroy = true } # handle updates gracefully
  96. description = "Security Group for Aggregated Log Source Ingestion"
  97. vpc_id = var.vpc_id
  98. tags = merge(var.standard_tags, var.tags)
  99. }
  100. # Ingress
  101. resource "aws_security_group_rule" "alsi-master-alb-web-in" {
  102. description = "Web access"
  103. type = "ingress"
  104. from_port = 9000
  105. to_port = 9000
  106. protocol = "tcp"
  107. source_security_group_id = aws_security_group.alsi-master-alb-sg.id
  108. security_group_id = aws_security_group.alsi_master_security_group.id
  109. }
  110. resource "aws_security_group_rule" "alsi-master-vpn-web-in" {
  111. description = "Web access"
  112. type = "ingress"
  113. from_port = 9000
  114. to_port = 9000
  115. protocol = "tcp"
  116. cidr_blocks = var.cidr_map["vpc-access"]
  117. security_group_id = aws_security_group.alsi_master_security_group.id
  118. }
  119. resource "aws_security_group_rule" "alsi-master-interconnections" {
  120. description = "Cribl Replication"
  121. type = "ingress"
  122. from_port = 4200
  123. to_port = 4200
  124. protocol = "tcp"
  125. source_security_group_id = aws_security_group.alsi_worker_security_group.id
  126. security_group_id = aws_security_group.alsi_master_security_group.id
  127. }
  128. # Egress
  129. resource "aws_security_group_rule" "alsi-master-splunk-mgmt" {
  130. description = "Management Access"
  131. type = "egress"
  132. from_port = 8089
  133. to_port = 8089
  134. protocol = "tcp"
  135. cidr_blocks = [ var.vpc_cidr ]
  136. security_group_id = aws_security_group.alsi_master_security_group.id
  137. }
  138. resource "aws_security_group_rule" "alsi-master-splunk-data" {
  139. description = "Management Access"
  140. type = "egress"
  141. from_port = 9997
  142. to_port = 9998
  143. protocol = "tcp"
  144. cidr_blocks = [ var.vpc_cidr ]
  145. security_group_id = aws_security_group.alsi_master_security_group.id
  146. }