Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: LogGroup #24

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ No modules.
| <a name="input_cluster_mode"></a> [cluster\_mode](#input\_cluster\_mode) | Specifies whether cluster mode is enabled or disabled. Valid values are enabled or disabled or compatible | `string` | `null` | no |
| <a name="input_cluster_mode_enabled"></a> [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 |
| <a name="input_create"></a> [create](#input\_create) | Determines whether resources will be created (affects all resources) | `bool` | `true` | no |
| <a name="input_create_cloudwatch_log_group"></a> [create\_cloudwatch\_log\_group](#input\_create\_cloudwatch\_log\_group) | Enable ot disable cloudwatch log group | `bool` | `true` | no |
| <a name="input_create_cluster"></a> [create\_cluster](#input\_create\_cluster) | Determines whether an ElastiCache cluster will be created or not | `bool` | `false` | no |
| <a name="input_create_parameter_group"></a> [create\_parameter\_group](#input\_create\_parameter\_group) | Determines whether the ElastiCache parameter group will be created or not | `bool` | `false` | no |
| <a name="input_create_primary_global_replication_group"></a> [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 |
Expand All @@ -345,7 +346,7 @@ No modules.
| <a name="input_global_replication_group_id"></a> [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 |
| <a name="input_ip_discovery"></a> [ip\_discovery](#input\_ip\_discovery) | The IP version to advertise in the discovery protocol. Valid values are `ipv4` or `ipv6` | `string` | `null` | no |
| <a name="input_kms_key_arn"></a> [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 |
| <a name="input_log_delivery_configuration"></a> [log\_delivery\_configuration](#input\_log\_delivery\_configuration) | (Redis only) Specifies the destination and format of Redis SLOWLOG or Redis Engine Log | `any` | <pre>{<br/> "slow-log": {<br/> "destination_type": "cloudwatch-logs",<br/> "log_format": "json"<br/> }<br/>}</pre> | no |
| <a name="input_log_delivery_configuration"></a> [log\_delivery\_configuration](#input\_log\_delivery\_configuration) | (Redis only) Specifies the destination and format of Redis SLOWLOG or Redis Engine Log | `any` | <pre>{<br> "slow-log": {<br> "destination_type": "cloudwatch-logs",<br> "log_format": "json"<br> }<br>}</pre> | no |
| <a name="input_maintenance_window"></a> [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 |
| <a name="input_multi_az_enabled"></a> [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 |
| <a name="input_network_type"></a> [network\_type](#input\_network\_type) | The IP versions for cache cluster connections. Valid values are `ipv4`, `ipv6` or `dual_stack` | `string` | `null` | no |
Expand Down
14 changes: 7 additions & 7 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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" {
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down