main.tf 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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(local.standard_tags, var.tags)
  31. # Govcloud incompatible with "project visibility"
  32. # See https://github.com/hashicorp/terraform-provider-aws/issues/22473#issuecomment-1081187035
  33. lifecycle { ignore_changes = [project_visibility] }
  34. }
  35. resource "aws_codebuild_webhook" "this" {
  36. project_name = var.name
  37. branch_filter = var.webhook_branch_filter
  38. depends_on = [aws_codebuild_project.this]
  39. }
  40. resource "github_repository_webhook" "this" {
  41. active = true
  42. events = ["push"]
  43. repository = data.github_repository.this.name
  44. configuration {
  45. url = aws_codebuild_webhook.this.payload_url
  46. secret = aws_codebuild_webhook.this.secret
  47. content_type = "json"
  48. insecure_ssl = false
  49. }
  50. }