Skip to content

Commit 962b00d

Browse files
committed
support log group class and skip destroy config
1 parent 7811b47 commit 962b00d

File tree

5 files changed

+50
-24
lines changed

5 files changed

+50
-24
lines changed

README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,16 +256,10 @@ module "lambda" {
256256
// remove CloudWatch logs IAM permissions
257257
// cloudwatch_logs_enabled = false
258258
259-
// configure retention time for the module managed log group
259+
// configure module managed log group
260+
cloudwatch_logs_log_group_class = "STANDARD"
260261
cloudwatch_logs_retention_in_days = 7
261-
262-
cloudwatch_log_subscription_filters = {
263-
sub_1 = {
264-
// see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_subscription_filter for available arguments
265-
destination_arn = module.sub_1.arn
266-
filter_pattern = "%Lambda%"
267-
}
268-
}
262+
cloudwatch_logs_skip_destroy = false
269263
270264
// advanced logging config including a custom CloudWatch log group managed by the module
271265
logging_config = {
@@ -274,6 +268,15 @@ module "lambda" {
274268
log_group = "/custom/my_function_name"
275269
system_log_level = "WARN"
276270
}
271+
272+
// register log subscription filters for the functions log group
273+
cloudwatch_log_subscription_filters = {
274+
sub_1 = {
275+
// see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_subscription_filter for available arguments
276+
destination_arn = module.sub_1.arn
277+
filter_pattern = "%Lambda%"
278+
}
279+
}
277280
}
278281
279282
resource "aws_cloudwatch_log_group" "existing" {
@@ -433,7 +436,9 @@ No modules.
433436
| <a name="input_cloudwatch_log_subscription_filters"></a> [cloudwatch\_log\_subscription\_filters](#input\_cloudwatch\_log\_subscription\_filters) | CloudWatch Logs subscription filter resources. Currently supports only Lambda functions as destinations. | `map(any)` | `{}` | no |
434437
| <a name="input_cloudwatch_logs_enabled"></a> [cloudwatch\_logs\_enabled](#input\_cloudwatch\_logs\_enabled) | Enables your Lambda function to send logs to CloudWatch. The IAM role of this Lambda function will be enhanced with required permissions. | `bool` | `true` | no |
435438
| <a name="input_cloudwatch_logs_kms_key_id"></a> [cloudwatch\_logs\_kms\_key\_id](#input\_cloudwatch\_logs\_kms\_key\_id) | The ARN of the KMS Key to use when encrypting log data. | `string` | `null` | no |
439+
| <a name="input_cloudwatch_logs_log_group_class"></a> [cloudwatch\_logs\_log\_group\_class](#input\_cloudwatch\_logs\_log\_group\_class) | Specified the log class of the log group. Possible values are: `STANDARD`, `INFREQUENT_ACCESS`, or `DELIVERY`. | `string` | `null` | no |
436440
| <a name="input_cloudwatch_logs_retention_in_days"></a> [cloudwatch\_logs\_retention\_in\_days](#input\_cloudwatch\_logs\_retention\_in\_days) | Specifies the number of days you want to retain log events in the specified log group. Possible values are: 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653, and 0. If you select 0, the events in the log group are always retained and never expire. | `number` | `null` | no |
441+
| <a name="input_cloudwatch_logs_skip_destroy"></a> [cloudwatch\_logs\_skip\_destroy](#input\_cloudwatch\_logs\_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 |
437442
| <a name="input_create_cloudwatch_log_group"></a> [create\_cloudwatch\_log\_group](#input\_create\_cloudwatch\_log\_group) | Create and manage the CloudWatch Log Group for the Lambda function. Set to `false` to reuse an existing log group. | `bool` | `true` | no |
438443
| <a name="input_description"></a> [description](#input\_description) | Description of what your Lambda Function does. | `string` | `""` | no |
439444
| <a name="input_environment"></a> [environment](#input\_environment) | Environment (e.g. env variables) configuration for the Lambda function enable you to dynamically pass settings to your function code and libraries | <pre>object({<br/> variables = map(string)<br/> })</pre> | `null` | no |

cloudwatch_logs.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ resource "aws_cloudwatch_log_group" "lambda" {
1717
region = var.region
1818

1919
name = local.log_group_name
20+
log_group_class = var.cloudwatch_logs_log_group_class
2021
retention_in_days = var.cloudwatch_logs_retention_in_days
2122
kms_key_id = var.cloudwatch_logs_kms_key_id
23+
skip_destroy = var.cloudwatch_logs_skip_destroy
2224
tags = var.tags
2325
}
2426

examples/cloudwatch-logs/main.tf

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,25 @@ module "fixtures" {
1010
module "logs_subscription" {
1111
source = "../../"
1212

13-
cloudwatch_logs_retention_in_days = 1
14-
description = "Example usage for an AWS Lambda with CloudWatch logs subscription filters and advanced log configuration using a custom log group name."
15-
filename = module.fixtures.output_path
16-
function_name = module.fixtures.output_function_name
17-
handler = local.handler
18-
runtime = local.runtime
19-
source_code_hash = module.fixtures.output_base64sha256
13+
description = "Example usage for an AWS Lambda with CloudWatch logs subscription filters and advanced log configuration using a custom log group name."
14+
filename = module.fixtures.output_path
15+
function_name = module.fixtures.output_function_name
16+
handler = local.handler
17+
runtime = local.runtime
18+
source_code_hash = module.fixtures.output_base64sha256
19+
20+
// configure module managed log group
21+
cloudwatch_logs_log_group_class = "STANDARD"
22+
cloudwatch_logs_retention_in_days = 7
23+
cloudwatch_logs_skip_destroy = false
24+
25+
// advanced logging config including a custom CloudWatch log group managed by the module
26+
logging_config = {
27+
application_log_level = "INFO"
28+
log_format = "JSON"
29+
log_group = "/custom/${module.fixtures.output_function_name}"
30+
system_log_level = "WARN"
31+
}
2032

2133
// register log subscription filters for the functions log group
2234
cloudwatch_log_subscription_filters = {
@@ -29,14 +41,6 @@ module "logs_subscription" {
2941
destination_arn = module.sub_2.arn
3042
}
3143
}
32-
33-
// advanced logging config including a custom CloudWatch log group managed by the module
34-
logging_config = {
35-
application_log_level = "INFO"
36-
log_format = "JSON"
37-
log_group = "/custom/${module.fixtures.output_function_name}"
38-
system_log_level = "WARN"
39-
}
4044
}
4145

4246
data "archive_file" "subscription_handler" {

examples/complete/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ module "lambda" {
2626

2727
// logs, metrics and tracing
2828
cloudwatch_logs_enabled = true
29+
cloudwatch_logs_log_group_class = "STANDARD"
2930
cloudwatch_logs_retention_in_days = 7
31+
cloudwatch_logs_skip_destroy = false
3032
cloudwatch_lambda_insights_enabled = true
3133
layers = ["arn:aws:lambda:${local.region}:580247275435:layer:LambdaInsightsExtension-Arm64:23"]
3234
tracing_config_mode = "Active"

variables.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,25 @@ variable "cloudwatch_logs_kms_key_id" {
4444
default = null
4545
}
4646

47+
48+
variable "cloudwatch_logs_log_group_class" {
49+
description = "Specified the log class of the log group. Possible values are: `STANDARD`, `INFREQUENT_ACCESS`, or `DELIVERY`."
50+
default = null
51+
type = string
52+
}
53+
4754
variable "cloudwatch_logs_retention_in_days" {
4855
description = "Specifies the number of days you want to retain log events in the specified log group. Possible values are: 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653, and 0. If you select 0, the events in the log group are always retained and never expire."
4956
default = null
5057
type = number
5158
}
5259

60+
variable "cloudwatch_logs_skip_destroy" {
61+
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."
62+
type = bool
63+
default = false
64+
}
65+
5366
variable "cloudwatch_log_subscription_filters" {
5467
description = "CloudWatch Logs subscription filter resources. Currently supports only Lambda functions as destinations."
5568
default = {}

0 commit comments

Comments
 (0)