Skip to content

Commit 1be0b5e

Browse files
authored
feat: Allowing Custom CloudWatch Log Group Name or Prefix (#13)
1 parent 00e395f commit 1be0b5e

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

modules/virtual-cluster/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ No modules.
121121
| <a name="input_annotations"></a> [annotations](#input\_annotations) | A map of annotations to add to all Kubernetes resources | `map(string)` | `{}` | no |
122122
| <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 |
123123
| <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 |
124+
| <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 |
124125
| <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 |
126+
| <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 |
127+
| <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 |
125128
| <a name="input_create"></a> [create](#input\_create) | Controls if resources should be created (affects nearly all resources) | `bool` | `true` | no |
126129
| <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 |
127130
| <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 |

modules/virtual-cluster/main.tf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ locals {
66

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

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

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

272-
name = "/emr-on-eks-logs/emr-workload/${local.namespace}"
273+
name = var.cloudwatch_log_group_use_name_prefix ? null : local.cloudwatch_log_group_name
274+
name_prefix = var.cloudwatch_log_group_use_name_prefix ? "${local.cloudwatch_log_group_name}-" : null
273275
retention_in_days = var.cloudwatch_log_group_retention_in_days
274276
kms_key_id = var.cloudwatch_log_group_kms_key_id
277+
skip_destroy = var.cloudwatch_log_group_skip_destroy
275278

276279
tags = local.tags
277280
}

modules/virtual-cluster/variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,21 @@ variable "cloudwatch_log_group_kms_key_id" {
145145
type = string
146146
default = null
147147
}
148+
149+
variable "cloudwatch_log_group_name" {
150+
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>`"
151+
type = string
152+
default = null
153+
}
154+
155+
variable "cloudwatch_log_group_use_name_prefix" {
156+
description = "Determines whether the log group name (`cloudwatch_log_group_name`) is used as a prefix"
157+
type = bool
158+
default = false
159+
}
160+
161+
variable "cloudwatch_log_group_skip_destroy" {
162+
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"
163+
type = bool
164+
default = null
165+
}

0 commit comments

Comments
 (0)