Skip to content

[PES-974] Allow users to specify a custom CloudWatch log group for the CodeBuild project #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.24.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.94.1 |

## Modules

Expand Down Expand Up @@ -46,6 +46,7 @@
| <a name="input_build_type"></a> [build\_type](#input\_build\_type) | Type of build environment to use for related builds. | `string` | `"LINUX_CONTAINER"` | no |
| <a name="input_buildspec"></a> [buildspec](#input\_buildspec) | The build spec declaration to use for this build project's related builds. | `string` | `""` | no |
| <a name="input_cache"></a> [cache](#input\_cache) | Cache configuration block. | <pre>object({<br> type = optional(string) # Valid values: NO_CACHE, LOCAL, S3. Defaults to NO_CACHE.<br> modes = optional(list(string)) # Required when cache type is LOCAL<br> location = optional(string) # Required when cache type is S3<br> })</pre> | `{}` | no |
| <a name="input_cloudwatch_log_group"></a> [cloudwatch\_log\_group](#input\_cloudwatch\_log\_group) | Custom log group for CodeBuild Project | `string` | `null` | no |
| <a name="input_create_service_role"></a> [create\_service\_role](#input\_create\_service\_role) | Create new IAM service role and policy if `true`. | `bool` | `true` | no |
| <a name="input_description"></a> [description](#input\_description) | Short description of the project. | `string` | n/a | yes |
| <a name="input_encryption_key_arn"></a> [encryption\_key\_arn](#input\_encryption\_key\_arn) | AWS Key Management Service (AWS KMS) customer master key (CMK) to be used for encrypting the build project's build output artifacts. | `string` | `null` | no |
Expand Down
2 changes: 2 additions & 0 deletions iam.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module "codebuild_service_role" {
#checkov:skip=CKV_TF_1:Ensure Terraform module sources use a commit hash
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role"
version = "~> 5.2.0"

Expand All @@ -17,6 +18,7 @@ module "codebuild_service_role" {
}

module "codebuild_service_role_policy" {
#checkov:skip=CKV_TF_1:Ensure Terraform module sources use a commit hash
source = "terraform-aws-modules/iam/aws//modules/iam-policy"
version = "~> 5.2.0"

Expand Down
7 changes: 7 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,11 @@ resource "aws_codebuild_project" "this" {
location = var.source_location
report_build_status = var.report_build_status
}

logs_config {
cloudwatch_logs {
group_name = var.cloudwatch_log_group != null && var.cloudwatch_log_group != "" ? var.cloudwatch_log_group : null
status = "ENABLED"
}
}
}
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,9 @@ variable "additional_iam" {
type = list(any)
default = []
}

variable "cloudwatch_log_group" {
description = "Custom log group for CodeBuild Project"
type = string
default = null
}
Loading