codebuild.tf 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. resource "aws_codebuild_project" "this" {
  2. name = var.name
  3. description = "Container for ${var.name}"
  4. service_role = var.service_role
  5. encryption_key = var.kms_key
  6. #badge_enabled = var.badge_enabled
  7. source {
  8. type = "GITHUB_ENTERPRISE"
  9. location = var.github_clone_url
  10. report_build_status = true
  11. git_clone_depth = 1
  12. buildspec = var.buildspec
  13. }
  14. source_version = var.source_version
  15. dynamic secondary_sources {
  16. for_each = var.secondary_sources
  17. iterator = each
  18. content {
  19. type = "GITHUB_ENTERPRISE"
  20. location = each.value["secondary_github_clone_url"]
  21. report_build_status = true
  22. git_clone_depth = 1
  23. source_identifier = each.value["secondary_source_identifier"]
  24. }
  25. }
  26. dynamic secondary_source_version {
  27. for_each = var.secondary_sources
  28. iterator = each
  29. content {
  30. source_identifier = each.value["secondary_source_identifier"]
  31. source_version = each.value["secondary_source_version"]
  32. }
  33. }
  34. environment {
  35. compute_type = "BUILD_GENERAL1_SMALL"
  36. image = var.image
  37. type = "LINUX_CONTAINER"
  38. privileged_mode = var.privileged_mode
  39. dynamic "environment_variable" {
  40. for_each = var.env_vars
  41. iterator = each
  42. content {
  43. name = each.key
  44. value = each.value["value"]
  45. type = try(each.value["type"], "PLAINTEXT")
  46. }
  47. }
  48. }
  49. artifacts {
  50. type = "NO_ARTIFACTS"
  51. }
  52. tags = merge(local.standard_tags, var.tags)
  53. # Govcloud incompatible with "project visibility"
  54. # See https://github.com/hashicorp/terraform-provider-aws/issues/22473#issuecomment-1081187035
  55. lifecycle { ignore_changes = [project_visibility] }
  56. }
  57. # Only build the cloudwatch trigger if it's needed
  58. resource "aws_cloudwatch_event_rule" "schedule_rule" {
  59. count = var.schedule_expression == "" ? 0 : 1
  60. name = "scheduled_build-${var.name}"
  61. schedule_expression = var.schedule_expression
  62. }
  63. resource "aws_cloudwatch_event_target" "trigger_build" {
  64. count = var.schedule_expression == "" ? 0 : 1
  65. target_id = "trigger_build"
  66. rule = aws_cloudwatch_event_rule.schedule_rule[count.index].name
  67. arn = aws_codebuild_project.this.id
  68. role_arn = var.service_role
  69. }
  70. resource "aws_codebuild_webhook" "this" {
  71. count = var.enable_webhook == true ? 1 : 0
  72. project_name = var.name
  73. branch_filter = var.webhook_branch_filter
  74. depends_on = [aws_codebuild_project.this]
  75. }