main.tf 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. data "github_repository" "this" {
  2. name = var.name
  3. }
  4. resource "aws_codebuild_project" "this" {
  5. name = var.name
  6. description = "Project for ${var.name}"
  7. service_role = aws_iam_role.codebuild_service_role.arn
  8. encryption_key = aws_kms_key.s3_codebuild.arn
  9. badge_enabled = var.badge_enabled
  10. concurrent_build_limit = 1
  11. #project_visibility = "PRIVATE"
  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_submodules_config {
  18. fetch_submodules = true
  19. }
  20. }
  21. source_version = var.source_version
  22. environment {
  23. compute_type = "BUILD_GENERAL1_SMALL"
  24. image = "aws/codebuild/standard:5.0"
  25. type = "LINUX_CONTAINER"
  26. environment_variable {
  27. name = "ARTIFACTS_PATH"
  28. type = "PLAINTEXT"
  29. value = "s3://${aws_s3_bucket.bucket.id}/"
  30. }
  31. }
  32. artifacts {
  33. type = "S3"
  34. location = aws_s3_bucket.bucket.id
  35. name = "/"
  36. path = var.name
  37. namespace_type = "NONE"
  38. packaging = "NONE"
  39. }
  40. tags = merge(var.standard_tags, var.tags)
  41. }
  42. resource "aws_codebuild_webhook" "this" {
  43. project_name = var.name
  44. filter_group {
  45. filter {
  46. type = "EVENT"
  47. pattern = "PUSH"
  48. }
  49. filter {
  50. type = "HEAD_REF"
  51. pattern = var.webhook_filter_pattern
  52. }
  53. }
  54. depends_on = [ aws_codebuild_project.this ]
  55. }
  56. resource "github_repository_webhook" "this" {
  57. active = true
  58. events = ["push"]
  59. repository = data.github_repository.this.name
  60. configuration {
  61. url = aws_codebuild_webhook.this.payload_url
  62. secret = aws_codebuild_webhook.this.secret
  63. content_type = "json"
  64. insecure_ssl = false
  65. }
  66. }