main.tf 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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(local.standard_tags, var.tags)
  41. # Govcloud incompatible with "project visibility"
  42. # See https://github.com/hashicorp/terraform-provider-aws/issues/22473#issuecomment-1081187035
  43. lifecycle { ignore_changes = [project_visibility] }
  44. }
  45. resource "aws_codebuild_webhook" "this" {
  46. project_name = var.name
  47. filter_group {
  48. filter {
  49. type = "EVENT"
  50. pattern = "PUSH"
  51. }
  52. filter {
  53. type = "HEAD_REF"
  54. pattern = var.webhook_filter_pattern
  55. }
  56. }
  57. depends_on = [aws_codebuild_project.this]
  58. }
  59. resource "github_repository_webhook" "this" {
  60. active = true
  61. events = ["push"]
  62. repository = data.github_repository.this.name
  63. configuration {
  64. url = aws_codebuild_webhook.this.payload_url
  65. secret = aws_codebuild_webhook.this.secret
  66. content_type = "json"
  67. insecure_ssl = false
  68. }
  69. }