main.tf 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. function_name = "threatq_data_sync"
  40. role = aws_iam_role.role.arn
  41. handler = "lambda_function.lambda_handler"
  42. runtime = "python3.8"
  43. timeout = "900"
  44. vpc_config {
  45. subnet_ids = var.subnets
  46. security_group_ids = [ data.aws_security_group.typical-host.id, aws_security_group.threatq_lambda_splunk_sg.id ]
  47. }
  48. environment {
  49. variables = merge(local.environment_vars)
  50. }
  51. tags = merge(var.standard_tags, var.tags)
  52. lifecycle {
  53. # Ignoring changes to the code of the function so that we won't
  54. # overlay changes to the function made outside of terraform. Installing
  55. # new versions of a lambda should not be a terraform-ish action we don't think
  56. ignore_changes = [
  57. last_modified,
  58. source_code_hash
  59. ]
  60. }
  61. }