splunk_server.j 2.6 KB

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