main.tf 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. locals {
  2. environment_vars = {
  3. "HTTP_PROXY" = "http://${var.proxy}"
  4. "HTTPS_PROXY" = "http://${var.proxy}"
  5. "NO_PROXY" = "${var.dns_info["legacy_private"]["zone"]},${var.dns_info["private"]["zone"]}"
  6. "VAULT_HOST" = "vault.${var.dns_info["private"]["zone"]}"
  7. "VAULT_PATH" = "threatq-lambda/data/lambda_sync_env"
  8. "PYTHONWARNINGS" = "ignore:Unverified HTTPS request"
  9. }
  10. }
  11. ####
  12. #
  13. #Security Group
  14. #
  15. ####
  16. data "aws_security_group" "typical-host" {
  17. name = "typical-host"
  18. vpc_id = var.vpc_id
  19. }
  20. resource "aws_security_group" "threatq_lambda_splunk_sg" {
  21. vpc_id = var.vpc_id
  22. name = "threatq-data-sync-lambda-splunk-sg"
  23. description = "Allow Lambda access to Splunk"
  24. }
  25. resource "aws_security_group_rule" "threatq_lambda_splunk_out" {
  26. type = "egress"
  27. from_port = 8089
  28. to_port = 8089
  29. protocol = "tcp"
  30. cidr_blocks = ["10.0.0.0/8"]
  31. description = "All Splunk SH"
  32. security_group_id = aws_security_group.threatq_lambda_splunk_sg.id
  33. }
  34. # Env variables for bootstrap only; true secrets should be in vault
  35. resource "aws_lambda_function" "function" {
  36. description = "Sync data between ThreatQ and Splunk"
  37. #filename = "code.zip"
  38. #source_code_hash = filebase64sha256("code.zip")
  39. s3_bucket = aws_s3_bucket.bucket
  40. s3_key = "code.zip"
  41. function_name = "threatq_data_sync"
  42. role = aws_iam_role.role.arn
  43. handler = "lambda_function.lambda_handler"
  44. runtime = "python3.8"
  45. timeout = "900"
  46. vpc_config {
  47. subnet_ids = var.subnets
  48. security_group_ids = [ data.aws_security_group.typical-host.id, aws_security_group.threatq_lambda_splunk_sg.id ]
  49. }
  50. environment {
  51. variables = merge(local.environment_vars)
  52. }
  53. tags = merge(var.standard_tags, var.tags)
  54. lifecycle {
  55. # Ignoring changes to the code of the function so that we won't
  56. # overlay changes to the function made outside of terraform. Installing
  57. # new versions of a lambda should not be a terraform-ish action we don't think
  58. ignore_changes = [
  59. last_modified,
  60. source_code_hash
  61. ]
  62. }
  63. }