Skip to content

Commit

Permalink
feat: Allowing Custom CloudWatch Log Group Name or Prefix (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
vara-bonthu authored Jul 21, 2023
1 parent 00e395f commit 1be0b5e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
3 changes: 3 additions & 0 deletions modules/virtual-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ No modules.
| <a name="input_annotations"></a> [annotations](#input\_annotations) | A map of annotations to add to all Kubernetes resources | `map(string)` | `{}` | no |
| <a name="input_cloudwatch_log_group_arn"></a> [cloudwatch\_log\_group\_arn](#input\_cloudwatch\_log\_group\_arn) | ARN of the log group to use for the cluster logs | `string` | `"arn:aws:logs:*:*:*"` | no |
| <a name="input_cloudwatch_log_group_kms_key_id"></a> [cloudwatch\_log\_group\_kms\_key\_id](#input\_cloudwatch\_log\_group\_kms\_key\_id) | If a KMS Key ARN is set, this key will be used to encrypt the corresponding log group. Please be sure that the KMS Key has an appropriate key policy (https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/encrypt-log-data-kms.html) | `string` | `null` | no |
| <a name="input_cloudwatch_log_group_name"></a> [cloudwatch\_log\_group\_name](#input\_cloudwatch\_log\_group\_name) | The name of the log group. If a name is not provided, the default name format used is: `/emr-on-eks-logs/emr-workload/<NAMESPACE>` | `string` | `null` | no |
| <a name="input_cloudwatch_log_group_retention_in_days"></a> [cloudwatch\_log\_group\_retention\_in\_days](#input\_cloudwatch\_log\_group\_retention\_in\_days) | Number of days to retain log events. Default retention - 7 days | `number` | `7` | no |
| <a name="input_cloudwatch_log_group_skip_destroy"></a> [cloudwatch\_log\_group\_skip\_destroy](#input\_cloudwatch\_log\_group\_skip\_destroy) | Set to 'true' if you do not wish the log group (and any logs it may contain) to be deleted at destroy time, and instead just remove the log group from the Terraform state | `bool` | `null` | no |
| <a name="input_cloudwatch_log_group_use_name_prefix"></a> [cloudwatch\_log\_group\_use\_name\_prefix](#input\_cloudwatch\_log\_group\_use\_name\_prefix) | Determines whether the log group name (`cloudwatch_log_group_name`) is used as a prefix | `bool` | `false` | no |
| <a name="input_create"></a> [create](#input\_create) | Controls if resources should be created (affects nearly all resources) | `bool` | `true` | no |
| <a name="input_create_cloudwatch_log_group"></a> [create\_cloudwatch\_log\_group](#input\_create\_cloudwatch\_log\_group) | Determines whether a log group is created by this module for the cluster logs. If not, AWS will automatically create one if logging is enabled | `bool` | `true` | no |
| <a name="input_create_iam_role"></a> [create\_iam\_role](#input\_create\_iam\_role) | Determines whether an IAM role is created for EMR on EKS job execution role | `bool` | `true` | no |
Expand Down
9 changes: 6 additions & 3 deletions modules/virtual-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ locals {

internal_role_name = try(coalesce(var.role_name, var.name), "")

role_name = var.create_kubernetes_role ? kubernetes_role_v1.this[0].metadata[0].name : local.internal_role_name
namespace = var.create_namespace ? kubernetes_namespace_v1.this[0].metadata[0].name : var.namespace
role_name = var.create_kubernetes_role ? kubernetes_role_v1.this[0].metadata[0].name : local.internal_role_name
namespace = var.create_namespace ? kubernetes_namespace_v1.this[0].metadata[0].name : var.namespace
cloudwatch_log_group_name = coalesce(var.cloudwatch_log_group_name, "/emr-on-eks-logs/emr-workload/${local.namespace}")

tags = merge(var.tags, { terraform-aws-modules = "emr" })
}
Expand Down Expand Up @@ -269,9 +270,11 @@ resource "aws_iam_role_policy_attachment" "additional" {
resource "aws_cloudwatch_log_group" "this" {
count = var.create && var.create_cloudwatch_log_group ? 1 : 0

name = "/emr-on-eks-logs/emr-workload/${local.namespace}"
name = var.cloudwatch_log_group_use_name_prefix ? null : local.cloudwatch_log_group_name
name_prefix = var.cloudwatch_log_group_use_name_prefix ? "${local.cloudwatch_log_group_name}-" : null
retention_in_days = var.cloudwatch_log_group_retention_in_days
kms_key_id = var.cloudwatch_log_group_kms_key_id
skip_destroy = var.cloudwatch_log_group_skip_destroy

tags = local.tags
}
18 changes: 18 additions & 0 deletions modules/virtual-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,21 @@ variable "cloudwatch_log_group_kms_key_id" {
type = string
default = null
}

variable "cloudwatch_log_group_name" {
description = "The name of the log group. If a name is not provided, the default name format used is: `/emr-on-eks-logs/emr-workload/<NAMESPACE>`"
type = string
default = null
}

variable "cloudwatch_log_group_use_name_prefix" {
description = "Determines whether the log group name (`cloudwatch_log_group_name`) is used as a prefix"
type = bool
default = false
}

variable "cloudwatch_log_group_skip_destroy" {
description = "Set to 'true' if you do not wish the log group (and any logs it may contain) to be deleted at destroy time, and instead just remove the log group from the Terraform state"
type = bool
default = null
}

0 comments on commit 1be0b5e

Please sign in to comment.