main.tf 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. build_timeout = 60
  12. source {
  13. type = "GITHUB_ENTERPRISE"
  14. location = data.github_repository.this.http_clone_url
  15. report_build_status = true
  16. git_submodules_config {
  17. fetch_submodules = true
  18. }
  19. }
  20. source_version = var.source_version
  21. environment {
  22. compute_type = "BUILD_GENERAL1_SMALL"
  23. image = "aws/codebuild/standard:5.0"
  24. type = "LINUX_CONTAINER"
  25. environment_variable {
  26. name = "ARTIFACTS_PATH"
  27. type = "PLAINTEXT"
  28. value = "s3://${aws_s3_bucket.bucket.id}/"
  29. }
  30. }
  31. artifacts {
  32. type = "S3"
  33. location = aws_s3_bucket.bucket.id
  34. name = "/"
  35. path = var.name
  36. namespace_type = "NONE"
  37. packaging = "NONE"
  38. }
  39. tags = merge(var.standard_tags, var.tags)
  40. }
  41. resource "aws_codebuild_webhook" "this" {
  42. project_name = var.name
  43. branch_filter = var.webhook_branch_filter
  44. depends_on = [ aws_codebuild_project.this ]
  45. }
  46. resource "github_repository_webhook" "this" {
  47. active = true
  48. events = ["push"]
  49. repository = data.github_repository.this.name
  50. configuration {
  51. url = aws_codebuild_webhook.this.payload_url
  52. secret = aws_codebuild_webhook.this.secret
  53. content_type = "json"
  54. insecure_ssl = false
  55. }
  56. }