Skip to content

Commit dc3f5ae

Browse files
committed
feat: Add options to manage log group RDSOSMetrics
Usually RDSOSMetrics is created by a DB instance itself when enhanced monitoring is enabled. The new options allow make this log group managed so that: - non-default retention could be configured (AWS default is 30 days) - tags could be assigned (tags are not propagated from the DB instance) - the log group is removed if not used
1 parent 4481ddd commit dc3f5ae

File tree

7 files changed

+46
-1
lines changed

7 files changed

+46
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,13 @@ No resources.
246246
| <a name="input_character_set_name"></a> [character\_set\_name](#input\_character\_set\_name) | The character set name to use for DB encoding in Oracle instances. This can't be changed. See Oracle Character Sets Supported in Amazon RDS and Collations and Character Sets for Microsoft SQL Server for more information. This can only be set on creation | `string` | `null` | no |
247247
| <a name="input_cloudwatch_log_group_class"></a> [cloudwatch\_log\_group\_class](#input\_cloudwatch\_log\_group\_class) | Specified the log class of the log group. Possible values are: STANDARD or INFREQUENT\_ACCESS | `string` | `null` | no |
248248
| <a name="input_cloudwatch_log_group_kms_key_id"></a> [cloudwatch\_log\_group\_kms\_key\_id](#input\_cloudwatch\_log\_group\_kms\_key\_id) | The ARN of the KMS Key to use when encrypting log data | `string` | `null` | no |
249+
| <a name="input_cloudwatch_log_group_rdsosmetrics_retention_in_days"></a> [cloudwatch\_log\_group\_rdsosmetrics\_retention\_in\_days](#input\_cloudwatch\_log\_group\_rdsosmetrics\_retention\_in\_days) | The number of days to retain CloudWatch logs for RDSOSMetrics log group | `number` | `30` | no |
249250
| <a name="input_cloudwatch_log_group_retention_in_days"></a> [cloudwatch\_log\_group\_retention\_in\_days](#input\_cloudwatch\_log\_group\_retention\_in\_days) | The number of days to retain CloudWatch logs for the DB instance | `number` | `7` | no |
250251
| <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 |
251252
| <a name="input_cloudwatch_log_group_tags"></a> [cloudwatch\_log\_group\_tags](#input\_cloudwatch\_log\_group\_tags) | Additional tags for the CloudWatch log group(s) | `map(string)` | `{}` | no |
252253
| <a name="input_copy_tags_to_snapshot"></a> [copy\_tags\_to\_snapshot](#input\_copy\_tags\_to\_snapshot) | On delete, copy all Instance tags to the final snapshot | `bool` | `false` | no |
253254
| <a name="input_create_cloudwatch_log_group"></a> [create\_cloudwatch\_log\_group](#input\_create\_cloudwatch\_log\_group) | Determines whether a CloudWatch log group is created for each `enabled_cloudwatch_logs_exports` | `bool` | `false` | no |
255+
| <a name="input_create_cloudwatch_log_group_rdsosmetrics"></a> [create\_cloudwatch\_log\_group\_rdsosmetrics](#input\_create\_cloudwatch\_log\_group\_rdsosmetrics) | Determines whether a RDSOSMetrics CloudWatch log group is created by and managed by Terraform (otherwise it's created by RDS). This is useful only if monitoring\_interval > 0 | `bool` | `false` | no |
254256
| <a name="input_create_db_instance"></a> [create\_db\_instance](#input\_create\_db\_instance) | Whether to create a database instance | `bool` | `true` | no |
255257
| <a name="input_create_db_option_group"></a> [create\_db\_option\_group](#input\_create\_db\_option\_group) | Create a database option group | `bool` | `true` | no |
256258
| <a name="input_create_db_parameter_group"></a> [create\_db\_parameter\_group](#input\_create\_db\_parameter\_group) | Whether to create a database parameter group | `bool` | `true` | no |

examples/enhanced-monitoring/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ module "db" {
5757
monitoring_interval = 30
5858
monitoring_role_arn = aws_iam_role.rds_enhanced_monitoring.arn
5959

60+
create_cloudwatch_log_group_rdsosmetrics = true
61+
6062
performance_insights_enabled = true
6163
performance_insights_retention_period = 7
6264
create_monitoring_role = true

main.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ module "db_instance" {
139139
create_monitoring_role = var.create_monitoring_role
140140
monitoring_role_permissions_boundary = var.monitoring_role_permissions_boundary
141141

142+
create_cloudwatch_log_group_rdsosmetrics = var.create_cloudwatch_log_group_rdsosmetrics
143+
cloudwatch_log_group_rdsosmetrics_retention_in_days = var.cloudwatch_log_group_rdsosmetrics_retention_in_days
144+
142145
character_set_name = var.character_set_name
143146
nchar_character_set_name = var.nchar_character_set_name
144147
timezone = var.timezone

modules/db_instance/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ No modules.
4949
| <a name="input_character_set_name"></a> [character\_set\_name](#input\_character\_set\_name) | The character set name to use for DB encoding in Oracle instances. This can't be changed. See Oracle Character Sets Supported in Amazon RDS and Collations and Character Sets for Microsoft SQL Server for more information. This can only be set on creation. | `string` | `null` | no |
5050
| <a name="input_cloudwatch_log_group_class"></a> [cloudwatch\_log\_group\_class](#input\_cloudwatch\_log\_group\_class) | Specified the log class of the log group. Possible values are: STANDARD or INFREQUENT\_ACCESS | `string` | `null` | no |
5151
| <a name="input_cloudwatch_log_group_kms_key_id"></a> [cloudwatch\_log\_group\_kms\_key\_id](#input\_cloudwatch\_log\_group\_kms\_key\_id) | The ARN of the KMS Key to use when encrypting log data | `string` | `null` | no |
52+
| <a name="input_cloudwatch_log_group_rdsosmetrics_retention_in_days"></a> [cloudwatch\_log\_group\_rdsosmetrics\_retention\_in\_days](#input\_cloudwatch\_log\_group\_rdsosmetrics\_retention\_in\_days) | The number of days to retain CloudWatch logs for RDSOSMetrics log group | `number` | `30` | no |
5253
| <a name="input_cloudwatch_log_group_retention_in_days"></a> [cloudwatch\_log\_group\_retention\_in\_days](#input\_cloudwatch\_log\_group\_retention\_in\_days) | The number of days to retain CloudWatch logs for the DB instance | `number` | `7` | no |
5354
| <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 |
5455
| <a name="input_cloudwatch_log_group_tags"></a> [cloudwatch\_log\_group\_tags](#input\_cloudwatch\_log\_group\_tags) | Additional tags for the CloudWatch log group(s) | `map(string)` | `{}` | no |
5556
| <a name="input_copy_tags_to_snapshot"></a> [copy\_tags\_to\_snapshot](#input\_copy\_tags\_to\_snapshot) | On delete, copy all Instance tags to the final snapshot | `bool` | `false` | no |
5657
| <a name="input_create"></a> [create](#input\_create) | Whether to create this resource or not? | `bool` | `true` | no |
5758
| <a name="input_create_cloudwatch_log_group"></a> [create\_cloudwatch\_log\_group](#input\_create\_cloudwatch\_log\_group) | Determines whether a CloudWatch log group is created for each `enabled_cloudwatch_logs_exports` | `bool` | `false` | no |
59+
| <a name="input_create_cloudwatch_log_group_rdsosmetrics"></a> [create\_cloudwatch\_log\_group\_rdsosmetrics](#input\_create\_cloudwatch\_log\_group\_rdsosmetrics) | Determines whether a RDSOSMetrics CloudWatch log group is created by and managed by Terraform (otherwise it's created by RDS). This is useful only if monitoring\_interval > 0 | `bool` | `false` | no |
5860
| <a name="input_create_monitoring_role"></a> [create\_monitoring\_role](#input\_create\_monitoring\_role) | Create IAM role with a defined name that permits RDS to send enhanced monitoring metrics to CloudWatch Logs. | `bool` | `false` | no |
5961
| <a name="input_custom_iam_instance_profile"></a> [custom\_iam\_instance\_profile](#input\_custom\_iam\_instance\_profile) | RDS custom iam instance profile | `string` | `null` | no |
6062
| <a name="input_db_instance_tags"></a> [db\_instance\_tags](#input\_db\_instance\_tags) | A map of additional tags for the DB instance | `map(string)` | `{}` | no |

modules/db_instance/main.tf

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ resource "aws_db_instance" "this" {
137137

138138
tags = merge(var.tags, var.db_instance_tags)
139139

140-
depends_on = [aws_cloudwatch_log_group.this]
140+
depends_on = [
141+
aws_cloudwatch_log_group.this,
142+
aws_cloudwatch_log_group.rdsosmetrics,
143+
]
141144

142145
timeouts {
143146
create = lookup(var.timeouts, "create", null)
@@ -223,3 +226,12 @@ resource "aws_secretsmanager_secret_rotation" "this" {
223226
schedule_expression = var.master_user_password_rotation_schedule_expression
224227
}
225228
}
229+
230+
resource "aws_cloudwatch_log_group" "rdsosmetrics" {
231+
count = var.create_cloudwatch_log_group_rdsosmetrics ? 1 : 0
232+
233+
name = "RDSOSMetrics"
234+
retention_in_days = var.cloudwatch_log_group_rdsosmetrics_retention_in_days
235+
236+
tags = var.tags
237+
}

modules/db_instance/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,18 @@ variable "upgrade_storage_config" {
444444
default = null
445445
}
446446

447+
variable "create_cloudwatch_log_group_rdsosmetrics" {
448+
description = "Determines whether a RDSOSMetrics CloudWatch log group is created by and managed by Terraform (otherwise it's created by RDS). This is useful only if monitoring_interval > 0"
449+
type = bool
450+
default = false
451+
}
452+
453+
variable "cloudwatch_log_group_rdsosmetrics_retention_in_days" {
454+
description = "The number of days to retain CloudWatch logs for RDSOSMetrics log group"
455+
type = number
456+
default = 30
457+
}
458+
447459
################################################################################
448460
# CloudWatch Log Group
449461
################################################################################

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,18 @@ variable "upgrade_storage_config" {
571571
default = null
572572
}
573573

574+
variable "create_cloudwatch_log_group_rdsosmetrics" {
575+
description = "Determines whether a RDSOSMetrics CloudWatch log group is created by and managed by Terraform (otherwise it's created by RDS). This is useful only if monitoring_interval > 0"
576+
type = bool
577+
default = false
578+
}
579+
580+
variable "cloudwatch_log_group_rdsosmetrics_retention_in_days" {
581+
description = "The number of days to retain CloudWatch logs for RDSOSMetrics log group"
582+
type = number
583+
default = 30
584+
}
585+
574586
################################################################################
575587
# CloudWatch Log Group
576588
################################################################################

0 commit comments

Comments
 (0)