main.tf 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. data "github_repository" "this" {
  2. name = var.repository
  3. }
  4. resource "aws_codebuild_project" "this" {
  5. name = "splunk_docs_${var.repository}"
  6. description = "Splunk Documentation build from ${var.repository} repository"
  7. service_role = aws_iam_role.codebuild_splunk_docs_role.arn
  8. encryption_key = aws_kms_key.s3_codebuild_splunk_docs_artifacts.arn
  9. badge_enabled = var.badge_enabled
  10. concurrent_build_limit = 1
  11. build_timeout = 60
  12. source {
  13. type = "GITHUB_ENTERPRISE"
  14. buildspec = "buildspec.docs.yml"
  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 = "ARTIFACTS_PATH"
  30. type = "PLAINTEXT"
  31. value = "s3://xdr-${var.environment}-portal-shared-artifacts/splunk-search-docs/${var.repository}/"
  32. }
  33. }
  34. # Example: s3://xdr-moose-test-splunk-docs/sh-es/content_source/
  35. artifacts {
  36. type = "S3"
  37. location = "xdr-${var.environment}-portal-shared-artifacts"
  38. name = var.repository
  39. path = "/splunk-search-docs/"
  40. namespace_type = "NONE"
  41. packaging = "NONE"
  42. }
  43. tags = merge(var.standard_tags, var.tags)
  44. # Govcloud incompatible with "project visibility"
  45. # See https://github.com/hashicorp/terraform-provider-aws/issues/22473#issuecomment-1081187035
  46. lifecycle { ignore_changes = [ project_visibility ] }
  47. }
  48. resource "aws_codebuild_webhook" "this" {
  49. count = var.enable_webhooks ? 1 : 0
  50. project_name = aws_codebuild_project.this.name
  51. branch_filter = var.webhook_branch_filter
  52. }
  53. resource "github_repository_webhook" "this" {
  54. count = var.enable_webhooks ? 1 : 0
  55. active = true
  56. events = ["push"]
  57. repository = data.github_repository.this.name
  58. configuration {
  59. url = aws_codebuild_webhook.this[0].payload_url
  60. secret = aws_codebuild_webhook.this[0].secret
  61. content_type = "json"
  62. insecure_ssl = false
  63. }
  64. }