Skip to content

Commit e6b7834

Browse files
author
Om Sharma
authored
Merge pull request #29 from clouddrove/redis-1
add cloudwatch_log_group and enabled redis logs
2 parents 92d1404 + 272aa17 commit e6b7834

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

_example/redis/example.tf

+14-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module "redis" {
4949

5050
replication_enabled = true
5151
engine = "redis"
52-
engine_version = "6.x"
52+
engine_version = "6.2"
5353
parameter_group_name = "default.redis6.x"
5454
port = 6379
5555
node_type = "cache.t2.micro"
@@ -58,6 +58,19 @@ module "redis" {
5858
availability_zones = ["eu-west-1a", "eu-west-1b"]
5959
auto_minor_version_upgrade = true
6060
number_cache_clusters = 2
61+
62+
log_delivery_configuration = [
63+
{
64+
destination_type = "cloudwatch-logs"
65+
log_format = "json"
66+
log_type = "slow-log"
67+
},
68+
{
69+
destination_type = "cloudwatch-logs"
70+
log_format = "json"
71+
log_type = "engine-log"
72+
}
73+
]
6174
extra_tags = {
6275
Application = "CloudDrove"
6376
}

main.tf

+19
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ module "labels" {
2020
extra_tags = var.extra_tags
2121
}
2222

23+
resource "aws_cloudwatch_log_group" "default" {
24+
count = var.enable && length(var.log_delivery_configuration) > 0 ? 1 : 0
25+
name = format("logs-%s", module.labels.id)
26+
tags = module.labels.tags
27+
}
28+
2329
# Module : Elasticache Subnet Group
2430
# Description : Terraform module which creates Subnet Group for Elasticache.
2531
resource "aws_elasticache_subnet_group" "default" {
@@ -62,8 +68,19 @@ resource "aws_elasticache_replication_group" "default" {
6268
kms_key_id = var.kms_key_id
6369
tags = module.labels.tags
6470

71+
dynamic "log_delivery_configuration" {
72+
for_each = var.log_delivery_configuration
73+
74+
content {
75+
destination = lookup(log_delivery_configuration.value, "destination", join("", aws_cloudwatch_log_group.default.*.name))
76+
destination_type = lookup(log_delivery_configuration.value, "destination_type", null)
77+
log_format = lookup(log_delivery_configuration.value, "log_format", null)
78+
log_type = lookup(log_delivery_configuration.value, "log_type", null)
79+
}
80+
}
6581
}
6682

83+
6784
# Module : Elasticache Replication Group
6885
# Description : Terraform module which creates cluster for Elasticache Redis.
6986
resource "aws_elasticache_replication_group" "cluster" {
@@ -123,4 +140,6 @@ resource "aws_elasticache_cluster" "default" {
123140
preferred_availability_zones = slice(var.availability_zones, 0, var.num_cache_nodes)
124141
maintenance_window = var.maintenance_window
125142
tags = module.labels.tags
143+
126144
}
145+

variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,9 @@ variable "parameter_group_name" {
235235
default = "default.redis5.0"
236236
description = "The name of the parameter group to associate with this replication group. If this argument is omitted, the default cache parameter group for the specified engine is used."
237237
}
238+
239+
variable "log_delivery_configuration" {
240+
type = list(map(any))
241+
default = []
242+
description = "The log_delivery_configuration block allows the streaming of Redis SLOWLOG or Redis Engine Log to CloudWatch Logs or Kinesis Data Firehose. Max of 2 blocks."
243+
}

0 commit comments

Comments
 (0)