splunk_server.j 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. {% import 'variables.include' as var %}
  2. ###################
  3. # Splunk_Server Instance
  4. resource "aws_instance" "splunk-hp" {
  5. ami = data.aws_ami.ubuntu.id
  6. # ami = data.aws_ami.centos7.id
  7. instance_type = var.Splunk-Instance-Type
  8. availability_zone = data.aws_availability_zones.available.names[0]
  9. subnet_id = aws_subnet.subnet_Splunk.id
  10. private_ip = var.Splunk-IP
  11. ebs_optimized = var.EBS-Optimized
  12. disable_api_termination = false
  13. associate_public_ip_address = true
  14. instance_initiated_shutdown_behavior = "terminate"
  15. key_name = var.AWS-Key-Pair-Name
  16. vpc_security_group_ids = [aws_security_group.sg_splunk_secured_access.id]
  17. depends_on = [aws_internet_gateway.gw_primary]
  18. tags = {
  19. Name = "splunk-hp"
  20. }
  21. root_block_device {
  22. volume_type = var.Default-Volume-Type
  23. volume_size = var.Splunk-Volume-Size # Gigabytes
  24. delete_on_termination = true
  25. }
  26. ebs_block_device {
  27. device_name = "/dev/sdd"
  28. volume_size = var.Swap-Volume-Size
  29. volume_type = var.Swap-Volume-Type
  30. delete_on_termination = true
  31. }
  32. user_data = <<EOF
  33. #cloud-config
  34. package_update: true
  35. package_upgrade: true
  36. packages:
  37. - git
  38. - vim
  39. - wget
  40. - curl
  41. - tcpdump
  42. - python
  43. - iptables-persistent
  44. runcmd:
  45. - mkswap /dev/xvdd
  46. - swapon -a
  47. - git clone https://github.com/fdamstra/python_multithreaded_socket_logger.git /opt/multithreaded_socket_logger
  48. - bash /opt/multithreaded_socket_logger/splunkserver_init.sh
  49. mounts:
  50. - [ xvdd, none, swap, sw, 0, 0 ]
  51. growpart:
  52. mode: auto
  53. devices: ['/']
  54. ignore_growroot_disabled: false
  55. power_state:
  56. mode: "reboot"
  57. message: "Rebooting after first init."
  58. condition: True
  59. EOF
  60. # To reboot, add the following above the EOF line:
  61. # power_state:
  62. # delay: "+10"
  63. # mode: "reboot"
  64. # message: "Rebooting after first init."
  65. # condition: True
  66. # Fix issues with cached keys. Arguably less secure, but also way less annoying
  67. provisioner "local-exec" {
  68. command = "ssh-keygen -f ~/.ssh/known_hosts -R splunk-hp.lab.${var.Domain-Name}"
  69. }
  70. }
  71. # Give me the IP Addresses
  72. output "splunk-hp_ip" {
  73. value = aws_instance.splunk-hp.public_ip
  74. }
  75. # Give me DNS entries
  76. resource "aws_route53_record" "splunk-hp" {
  77. zone_id = var.Domain-Zone-ID
  78. name = "splunk-hp.lab.${var.Domain-Name}"
  79. type = "A"
  80. ttl = "300"
  81. records = [aws_instance.splunk-hp.public_ip]
  82. }
  83. resource "aws_route53_record" "splunk-hp_pvt" {
  84. zone_id = var.Domain-Zone-ID
  85. name = "splunk-hp_pvt.lab.${var.Domain-Name}"
  86. type = "A"
  87. ttl = "300"
  88. records = [aws_instance.splunk-hp.private_ip]
  89. }
  90. output "splunk-hp_dns" {
  91. value = aws_route53_record.splunk-hp.name
  92. }