main.tf 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. data "github_repository" "this" {
  2. name = "content_source"
  3. }
  4. resource "aws_codebuild_project" "this" {
  5. for_each = local.splunk_server_types
  6. name = "splunk_apps_${var.splunk_prefix}_${each.value}"
  7. description = "Splunk Application build for ${each.value}"
  8. service_role = aws_iam_role.codebuild_splunk_apps_role.arn
  9. encryption_key = aws_kms_key.s3_codebuild_splunk_apps_artifacts.arn
  10. badge_enabled = var.badge_enabled
  11. concurrent_build_limit = 1
  12. build_timeout = 60
  13. source {
  14. type = "GITHUB_ENTERPRISE"
  15. location = data.github_repository.this.http_clone_url
  16. report_build_status = true
  17. git_clone_depth = 1
  18. git_submodules_config {
  19. fetch_submodules = true
  20. }
  21. }
  22. source_version = var.source_version
  23. environment {
  24. compute_type = "BUILD_GENERAL1_SMALL"
  25. image = "${var.common_services_account}.dkr.ecr.us-gov-east-1.amazonaws.com/content_generator:latest"
  26. image_pull_credentials_type = "SERVICE_ROLE"
  27. type = "LINUX_CONTAINER"
  28. environment_variable {
  29. name = "TAG"
  30. type = "PLAINTEXT"
  31. value = "${var.splunk_prefix}:${each.value}"
  32. }
  33. environment_variable {
  34. name = "ARTIFACTS_PATH"
  35. type = "PLAINTEXT"
  36. value = "s3://xdr-${var.splunk_prefix}-${var.environment}-splunk-apps/${ each.value }/content_source/"
  37. }
  38. }
  39. # Example: s3://xdr-moose-test-splunk-apps/sh-es/content_source/
  40. artifacts {
  41. type = "S3"
  42. location = "xdr-${var.splunk_prefix}-${var.environment}-splunk-apps"
  43. name = "content_source"
  44. path = "/${ each.value }/"
  45. namespace_type = "NONE"
  46. packaging = "NONE"
  47. }
  48. tags = merge(var.standard_tags, var.tags)
  49. }
  50. locals {
  51. webhooks = var.enable_webhooks ? local.splunk_server_types : []
  52. }
  53. resource "aws_codebuild_webhook" "this" {
  54. #for_each = local.splunk_server_types
  55. for_each = local.webhooks
  56. project_name = aws_codebuild_project.this[each.value].name
  57. branch_filter = var.webhook_branch_filter
  58. }
  59. resource "github_repository_webhook" "this" {
  60. #for_each = local.splunk_server_types
  61. for_each = local.webhooks
  62. active = true
  63. events = ["push"]
  64. repository = data.github_repository.this.name
  65. configuration {
  66. url = aws_codebuild_webhook.this[each.value].payload_url
  67. secret = aws_codebuild_webhook.this[each.value].secret
  68. content_type = "json"
  69. insecure_ssl = false
  70. }
  71. }