main.tf 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. data "github_repository" "this" {
  2. name = var.name
  3. }
  4. resource "aws_codebuild_project" "this" {
  5. count = var.artifact_s3_bucket=="" ? 0 : 1
  6. name = var.name
  7. description = "Project for ${var.name}"
  8. service_role = var.service_role
  9. encryption_key = var.kms_key
  10. badge_enabled = var.badge_enabled
  11. source {
  12. type = "GITHUB_ENTERPRISE"
  13. location = data.github_repository.this.http_clone_url
  14. report_build_status = true
  15. }
  16. environment {
  17. compute_type = "BUILD_GENERAL1_SMALL"
  18. image = var.codebuild_image
  19. type = "LINUX_CONTAINER"
  20. }
  21. artifacts {
  22. type = "S3"
  23. location = var.artifact_s3_bucket
  24. name = "/"
  25. path = var.name
  26. namespace_type = var.artifact_namespace_type
  27. override_artifact_name = var.override_artifact_name
  28. packaging = "NONE"
  29. }
  30. tags = merge(var.standard_tags, var.tags)
  31. }
  32. resource "aws_codebuild_webhook" "this" {
  33. project_name = var.name
  34. branch_filter = var.webhook_branch_filter
  35. depends_on = [ aws_codebuild_project.this ]
  36. }
  37. resource "github_repository_webhook" "this" {
  38. active = true
  39. events = ["push"]
  40. repository = data.github_repository.this.name
  41. configuration {
  42. url = aws_codebuild_webhook.this.payload_url
  43. secret = aws_codebuild_webhook.this.secret
  44. content_type = "json"
  45. insecure_ssl = false
  46. }
  47. }