Skip to content

Commit fd00f11

Browse files
authored
Merge pull request #6 from geekcell/kms-optional
feat: Make customer KMS encryption optional
2 parents 681cb81 + a562058 commit fd00f11

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ providing default values that should make sense for most use cases.
4242

4343
| Name | Description | Type | Default | Required |
4444
|------|-------------|------|---------|:--------:|
45+
| <a name="input_enable_customer_managed_kms"></a> [enable\_customer\_managed\_kms](#input\_enable\_customer\_managed\_kms) | Whether to enable customer managed KMS encryption for the log group. | `bool` | `false` | no |
46+
| <a name="input_kms_key_id"></a> [kms\_key\_id](#input\_kms\_key\_id) | The ARN of the KMS Key to use when encrypting log data. | `string` | `null` | no |
47+
| <a name="input_log_streams"></a> [log\_streams](#input\_log\_streams) | A list of log streams to create within the log group. | `list(string)` | `[]` | no |
4548
| <a name="input_name"></a> [name](#input\_name) | The name of the log group. | `string` | n/a | yes |
4649
| <a name="input_retention_in_days"></a> [retention\_in\_days](#input\_retention\_in\_days) | Specifies the number of days you want to retain log events in the specified log group. | `number` | `30` | no |
4750
| <a name="input_skip_destroy"></a> [skip\_destroy](#input\_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` | `false` | no |
@@ -52,6 +55,7 @@ providing default values that should make sense for most use cases.
5255
| Name | Description |
5356
|------|-------------|
5457
| <a name="output_arn"></a> [arn](#output\_arn) | The cloudwatch log group ARN |
58+
| <a name="output_customer_managed_key_arn"></a> [customer\_managed\_key\_arn](#output\_customer\_managed\_key\_arn) | The ARN of the customer KMS key used to encrypt log data if enabled. |
5559
| <a name="output_name"></a> [name](#output\_name) | The cloudwatch log group name |
5660

5761
## Providers

main.tf

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@ resource "aws_cloudwatch_log_group" "main" {
99

1010
retention_in_days = var.retention_in_days
1111
skip_destroy = var.skip_destroy
12-
kms_key_id = module.kms.key_arn
12+
kms_key_id = var.enable_customer_managed_kms ? module.kms[0].key_arn : var.kms_key_id
1313

1414
tags = var.tags
1515
}
1616

1717
resource "aws_cloudwatch_log_stream" "main" {
18-
name = var.name
18+
for_each = toset(var.log_streams)
1919

20+
name = each.value
2021
log_group_name = aws_cloudwatch_log_group.main.name
2122
}
2223

2324
module "kms" {
25+
count = var.enable_customer_managed_kms ? 1 : 0
26+
2427
source = "geekcell/kms/aws"
2528
version = ">= 1.0.0, < 2.0.0"
2629

outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ output "name" {
77
description = "The cloudwatch log group name"
88
value = aws_cloudwatch_log_group.main.name
99
}
10+
11+
output "customer_managed_key_arn" {
12+
description = "The ARN of the customer KMS key used to encrypt log data if enabled."
13+
value = var.enable_customer_managed_kms ? module.kms[0].key_arn : null
14+
}

variables.tf

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ variable "tags" {
55
type = map(any)
66
}
77

8-
# AWS Cloudwatch log groups
8+
# AWS Cloudwatch Log Group
99
variable "name" {
1010
description = "The name of the log group."
1111
type = string
@@ -22,3 +22,23 @@ variable "skip_destroy" {
2222
default = false
2323
type = bool
2424
}
25+
26+
# Log Streams
27+
variable "log_streams" {
28+
description = "A list of log streams to create within the log group."
29+
default = []
30+
type = list(string)
31+
}
32+
33+
# KMS Encryption
34+
variable "kms_key_id" {
35+
description = "The ARN of the KMS Key to use when encrypting log data."
36+
default = null
37+
type = string
38+
}
39+
40+
variable "enable_customer_managed_kms" {
41+
description = "Whether to enable customer managed KMS encryption for the log group."
42+
default = false
43+
type = bool
44+
}

0 commit comments

Comments
 (0)