codebuild.tf 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. resource "aws_codebuild_project" "this" {
  2. name = var.name
  3. description = "Container for ${var.name}"
  4. service_role = var.codebuild_assume_role_arn
  5. #encryption_key = var.kms_key
  6. #badge_enabled = var.badge_enabled
  7. source {
  8. type = "GITHUB_ENTERPRISE"
  9. #location = data.github_repository.this.http_clone_url
  10. location = var.github_clone_url
  11. report_build_status = true
  12. git_clone_depth = 1
  13. buildspec = var.buildspec
  14. }
  15. source_version = var.source_version
  16. environment {
  17. compute_type = "BUILD_GENERAL1_SMALL"
  18. image = "aws/codebuild/amazonlinux2-x86_64-standard:3.0"
  19. type = "LINUX_CONTAINER"
  20. privileged_mode = true
  21. dynamic "environment_variable" {
  22. for_each = var.env_vars
  23. iterator = each
  24. content {
  25. name = each.key
  26. value = each.value["value"]
  27. type = try(each.value["type"], "PLAINTEXT")
  28. }
  29. }
  30. }
  31. artifacts {
  32. type = "NO_ARTIFACTS"
  33. }
  34. tags = merge(var.standard_tags, var.tags)
  35. # Govcloud incompatible with "project visibility"
  36. # See https://github.com/hashicorp/terraform-provider-aws/issues/22473#issuecomment-1081187035
  37. lifecycle { ignore_changes = [project_visibility] }
  38. }
  39. resource "aws_cloudwatch_event_rule" "schedule_rule" {
  40. count = var.schedule_expression == "" ? 0 : 1
  41. name = "scheduled_build-${var.name}"
  42. schedule_expression = var.schedule_expression
  43. }
  44. resource "aws_cloudwatch_event_target" "trigger_build" {
  45. count = var.schedule_expression == "" ? 0 : 1
  46. target_id = "trigger_build"
  47. rule = aws_cloudwatch_event_rule.schedule_rule[count.index].name
  48. arn = aws_codebuild_project.this.id
  49. role_arn = var.codebuild_assume_role_arn
  50. }