main.tf 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. data "github_repository" "this" {
  2. name = var.repository
  3. }
  4. resource "aws_codebuild_project" "this" {
  5. for_each = local.splunk_server_types
  6. name = "splunk_apps_${var.splunk_prefix}_${each.value}_${var.repository}"
  7. description = "Splunk Application build for ${each.value} from ${var.repository} repository"
  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}/${var.repository}/"
  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 = var.repository
  44. path = "/${each.value}/"
  45. namespace_type = "NONE"
  46. packaging = "NONE"
  47. }
  48. tags = merge(local.standard_tags, var.tags)
  49. # Govcloud incompatible with "project visibility"
  50. # See https://github.com/hashicorp/terraform-provider-aws/issues/22473#issuecomment-1081187035
  51. lifecycle { ignore_changes = [project_visibility] }
  52. }
  53. locals {
  54. webhooks = var.enable_webhooks ? local.splunk_server_types : []
  55. }
  56. resource "aws_codebuild_webhook" "this" {
  57. #for_each = local.splunk_server_types
  58. for_each = local.webhooks
  59. project_name = aws_codebuild_project.this[each.value].name
  60. branch_filter = var.webhook_branch_filter
  61. }
  62. resource "github_repository_webhook" "this" {
  63. #for_each = local.splunk_server_types
  64. for_each = local.webhooks
  65. active = true
  66. events = ["push"]
  67. repository = data.github_repository.this.name
  68. configuration {
  69. url = aws_codebuild_webhook.this[each.value].payload_url
  70. secret = aws_codebuild_webhook.this[each.value].secret
  71. content_type = "json"
  72. insecure_ssl = false
  73. }
  74. }