diff --git a/README.md b/README.md index dcbc37b..232b7a2 100644 --- a/README.md +++ b/README.md @@ -330,6 +330,7 @@ No modules. | [cluster\_mode](#input\_cluster\_mode) | Specifies whether cluster mode is enabled or disabled. Valid values are enabled or disabled or compatible | `string` | `null` | no | | [cluster\_mode\_enabled](#input\_cluster\_mode\_enabled) | Whether to enable Redis [cluster mode https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/Replication.Redis-RedisCluster.html] | `bool` | `false` | no | | [create](#input\_create) | Determines whether resources will be created (affects all resources) | `bool` | `true` | no | +| [create\_cloudwatch\_log\_group](#input\_create\_cloudwatch\_log\_group) | Enable ot disable cloudwatch log group | `bool` | `true` | no | | [create\_cluster](#input\_create\_cluster) | Determines whether an ElastiCache cluster will be created or not | `bool` | `false` | no | | [create\_parameter\_group](#input\_create\_parameter\_group) | Determines whether the ElastiCache parameter group will be created or not | `bool` | `false` | no | | [create\_primary\_global\_replication\_group](#input\_create\_primary\_global\_replication\_group) | Determines whether an primary ElastiCache global replication group will be created | `bool` | `false` | no | @@ -345,7 +346,7 @@ No modules. | [global\_replication\_group\_id](#input\_global\_replication\_group\_id) | The ID of the global replication group to which this replication group should belong | `string` | `null` | no | | [ip\_discovery](#input\_ip\_discovery) | The IP version to advertise in the discovery protocol. Valid values are `ipv4` or `ipv6` | `string` | `null` | no | | [kms\_key\_arn](#input\_kms\_key\_arn) | The ARN of the key that you wish to use if encrypting at rest. If not supplied, uses service managed encryption. Can be specified only if `at_rest_encryption_enabled = true` | `string` | `null` | no | -| [log\_delivery\_configuration](#input\_log\_delivery\_configuration) | (Redis only) Specifies the destination and format of Redis SLOWLOG or Redis Engine Log | `any` |
{
"slow-log": {
"destination_type": "cloudwatch-logs",
"log_format": "json"
}
}
| no | +| [log\_delivery\_configuration](#input\_log\_delivery\_configuration) | (Redis only) Specifies the destination and format of Redis SLOWLOG or Redis Engine Log | `any` |
{
"slow-log": {
"destination_type": "cloudwatch-logs",
"log_format": "json"
}
}
| no | | [maintenance\_window](#input\_maintenance\_window) | Specifies the weekly time range for when maintenance on the cache cluster is performed. The format is `ddd:hh24:mi-ddd:hh24:mi` (24H Clock UTC) | `string` | `null` | no | | [multi\_az\_enabled](#input\_multi\_az\_enabled) | Specifies whether to enable Multi-AZ Support for the replication group. If true, `automatic_failover_enabled` must also be enabled. Defaults to `false` | `bool` | `false` | no | | [network\_type](#input\_network\_type) | The IP versions for cache cluster connections. Valid values are `ipv4`, `ipv6` or `dual_stack` | `string` | `null` | no | diff --git a/main.tf b/main.tf index f78027c..bc7075d 100644 --- a/main.tf +++ b/main.tf @@ -26,10 +26,10 @@ resource "aws_elasticache_cluster" "this" { ip_discovery = var.ip_discovery dynamic "log_delivery_configuration" { - for_each = { for k, v in var.log_delivery_configuration : k => v if var.engine != "memcached" && !local.in_replication_group } + for_each = { for k, v in var.log_delivery_configuration : k => v if local.create_cloudwatch_log_group && !local.in_replication_group } content { - destination = try(log_delivery_configuration.value.create_cloudwatch_log_group, true) && log_delivery_configuration.value.destination_type == "cloudwatch-logs" ? aws_cloudwatch_log_group.this[log_delivery_configuration.key].name : log_delivery_configuration.value.destination + destination = local.create_cloudwatch_log_group && log_delivery_configuration.value.destination_type == "cloudwatch-logs" && lookup(aws_cloudwatch_log_group.this, log_delivery_configuration.key, null) != null ? aws_cloudwatch_log_group.this[log_delivery_configuration.key].name : log_delivery_configuration.value.destination destination_type = log_delivery_configuration.value.destination_type log_format = log_delivery_configuration.value.log_format log_type = try(log_delivery_configuration.value.log_type, log_delivery_configuration.key) @@ -86,10 +86,10 @@ resource "aws_elasticache_replication_group" "this" { kms_key_id = var.at_rest_encryption_enabled ? var.kms_key_arn : null dynamic "log_delivery_configuration" { - for_each = { for k, v in var.log_delivery_configuration : k => v if var.engine == "redis" } + for_each = { for k, v in var.log_delivery_configuration : k => v if local.create_cloudwatch_log_group } content { - destination = try(log_delivery_configuration.value.create_cloudwatch_log_group, true) && log_delivery_configuration.value.destination_type == "cloudwatch-logs" ? aws_cloudwatch_log_group.this[log_delivery_configuration.key].name : log_delivery_configuration.value.destination + destination = local.create_cloudwatch_log_group && log_delivery_configuration.value.destination_type == "cloudwatch-logs" && lookup(aws_cloudwatch_log_group.this, log_delivery_configuration.key, null) != null ? aws_cloudwatch_log_group.this[log_delivery_configuration.key].name : log_delivery_configuration.value.destination destination_type = log_delivery_configuration.value.destination_type log_format = log_delivery_configuration.value.log_format log_type = try(log_delivery_configuration.value.log_type, log_delivery_configuration.key) @@ -164,10 +164,10 @@ resource "aws_elasticache_replication_group" "global" { kms_key_id = var.at_rest_encryption_enabled ? var.kms_key_arn : null dynamic "log_delivery_configuration" { - for_each = { for k, v in var.log_delivery_configuration : k => v if var.engine != "memcached" } + for_each = { for k, v in var.log_delivery_configuration : k => v if local.create_cloudwatch_log_group } content { - destination = try(log_delivery_configuration.value.create_cloudwatch_log_group, true) && log_delivery_configuration.value.destination_type == "cloudwatch-logs" ? aws_cloudwatch_log_group.this[log_delivery_configuration.key].name : log_delivery_configuration.value.destination + destination = local.create_cloudwatch_log_group && log_delivery_configuration.value.destination_type == "cloudwatch-logs" && lookup(aws_cloudwatch_log_group.this, log_delivery_configuration.key, null) != null ? aws_cloudwatch_log_group.this[log_delivery_configuration.key].name : log_delivery_configuration.value.destination destination_type = log_delivery_configuration.value.destination_type log_format = log_delivery_configuration.value.log_format log_type = try(log_delivery_configuration.value.log_type, log_delivery_configuration.key) @@ -208,7 +208,7 @@ resource "aws_elasticache_replication_group" "global" { ################################################################################ locals { - create_cloudwatch_log_group = var.create && var.engine != "memcached" + create_cloudwatch_log_group = var.create && var.create_cloudwatch_log_group } resource "aws_cloudwatch_log_group" "this" { diff --git a/variables.tf b/variables.tf index 59649be..00f8f39 100644 --- a/variables.tf +++ b/variables.tf @@ -91,6 +91,12 @@ variable "log_delivery_configuration" { } } +variable "create_cloudwatch_log_group" { + description = "Enable ot disable cloudwatch log group" + type = bool + default = true +} + variable "maintenance_window" { description = "Specifies the weekly time range for when maintenance on the cache cluster is performed. The format is `ddd:hh24:mi-ddd:hh24:mi` (24H Clock UTC)" type = string