Skip to content

Commit a30e81a

Browse files
authored
Merge pull request #55 from pbs/CAT-23836
CAT-23836 Added log_delivery_configuration
2 parents e6efddf + 9479b59 commit a30e81a

19 files changed

+374
-3
lines changed

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Use this URL for the source of the module. See the usage examples below for more details.
88

99
```hcl
10-
github.com/pbs/terraform-aws-elasticache-redis-standalone-module?ref=1.0.24
10+
github.com/pbs/terraform-aws-elasticache-redis-standalone-module?ref=x.y.z
1111
```
1212

1313
### Alternative Installation Methods
@@ -28,7 +28,7 @@ Integrate this module like so:
2828

2929
```hcl
3030
module "redis" {
31-
source = "github.com/pbs/terraform-aws-elasticache-redis-standalone-module?ref=1.0.24"
31+
source = "github.com/pbs/terraform-aws-elasticache-redis-standalone-module?ref=x.y.z"
3232
3333
# Tagging Parameters
3434
organization = var.organization
@@ -44,7 +44,7 @@ module "redis" {
4444

4545
If this repo is added as a subtree, then the version of the module should be close to the version shown here:
4646

47-
`1.0.24`
47+
`x.y.z`
4848

4949
Note, however that subtrees can be altered as desired within repositories.
5050

@@ -77,6 +77,7 @@ No modules.
7777

7878
| Name | Type |
7979
|------|------|
80+
| [aws_cloudwatch_log_group.logs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) | resource |
8081
| [aws_elasticache_replication_group.replication_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_replication_group) | resource |
8182
| [aws_elasticache_subnet_group.subnet_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_subnet_group) | resource |
8283
| [aws_route53_record.primary_endpoint](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
@@ -103,6 +104,7 @@ No modules.
103104
| <a name="input_automatic_failover_enabled"></a> [automatic\_failover\_enabled](#input\_automatic\_failover\_enabled) | Specifies whether a read-only replica will be automatically promoted to read/write primary if the existing primary fails. If null, will be enabled if `nodes` > 1. If true, `nodes` must be greater than 1. | `bool` | `null` | no |
104105
| <a name="input_cname"></a> [cname](#input\_cname) | The value to use for the CNAME record if `create_dns` is true. The primary endpoint will be <cname>.<private\_hosted\_zone>, and the reader endpoint will be <cname>-ro.<private\_hosted\_zone>. If null, the name variable will be used instead. | `string` | `null` | no |
105106
| <a name="input_create_dns"></a> [create\_dns](#input\_create\_dns) | Whether to create DNS records for the primary and reader endpoints. | `bool` | `true` | no |
107+
| <a name="input_create_log_group"></a> [create\_log\_group](#input\_create\_log\_group) | Flag for creating a CloudWatch log group. | `bool` | `false` | no |
106108
| <a name="input_data_tiering_enabled"></a> [data\_tiering\_enabled](#input\_data\_tiering\_enabled) | Enables data tiering. Data tiering is only supported for replication groups using the r6gd node type. This parameter must be set to true when using r6gd nodes. | `bool` | `false` | no |
107109
| <a name="input_dns_ttl"></a> [dns\_ttl](#input\_dns\_ttl) | TTL for DNS records. | `number` | `300` | no |
108110
| <a name="input_egress_cidr_blocks"></a> [egress\_cidr\_blocks](#input\_egress\_cidr\_blocks) | List of CIDR blocks to assign to the egress rule of the security group. If null, `egress_security_group_ids` must be used. | `list(string)` | <pre>[<br> "10.0.0.0/8"<br>]</pre> | no |
@@ -111,6 +113,11 @@ No modules.
111113
| <a name="input_final_snapshot_identifier"></a> [final\_snapshot\_identifier](#input\_final\_snapshot\_identifier) | Name of your final cluster snapshot. If omitted, no final snapshot will be made. | `string` | `null` | no |
112114
| <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. If this parameter is specified, the replication group is added to the specified global replication group as a secondary replication group; otherwise, the replication group is not part of any global replication group. If global\_replication\_group\_id is set, the num\_node\_groups parameter cannot be set. | `string` | `null` | no |
113115
| <a name="input_kms_key_id"></a> [kms\_key\_id](#input\_kms\_key\_id) | 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 |
116+
| <a name="input_log_destination"></a> [log\_destination](#input\_log\_destination) | Name of externally created CloudWatch Logs LogGroup or Kinesis Data Firehose resource. If any specified, create\_log\_group will be ignored. | `string` | `null` | no |
117+
| <a name="input_log_destination_type"></a> [log\_destination\_type](#input\_log\_destination\_type) | For CloudWatch Logs use cloudwatch-logs or for Kinesis Data Firehose use kinesis-firehose. | `string` | `"cloudwatch-logs"` | no |
118+
| <a name="input_log_format"></a> [log\_format](#input\_log\_format) | Log format with valid values of json or text. | `string` | `"text"` | no |
119+
| <a name="input_log_group_class"></a> [log\_group\_class](#input\_log\_group\_class) | Log class of the log group. Possible values are: STANDARD or INFREQUENT\_ACCESS. | `string` | `"INFREQUENT_ACCESS"` | no |
120+
| <a name="input_log_type"></a> [log\_type](#input\_log\_type) | Log type with valid values of slow-log or engine-log. | `string` | `"slow-log"` | no |
114121
| <a name="input_maintenance_window"></a> [maintenance\_window](#input\_maintenance\_window) | Specifies the weekly time range for when maintenance on the cluster is performed. The format is ddd:hh24:mi-ddd:hh24:mi (24H Clock UTC). The minimum maintenance window is a 60 minute period. Example: sun:05:00-sun:09:00. | `string` | `"mon:07:00-mon:08:00"` | no |
115122
| <a name="input_multi_az_enabled"></a> [multi\_az\_enabled](#input\_multi\_az\_enabled) | Whether to enable Multi-AZ. If Multi-AZ is enabled, the value of nodes must be at least 2. | `bool` | `false` | no |
116123
| <a name="input_name"></a> [name](#input\_name) | Name of the ElastiCache Redis instance. If null, will default to product. | `string` | `null` | no |
@@ -123,7 +130,9 @@ No modules.
123130
| <a name="input_private_hosted_zone"></a> [private\_hosted\_zone](#input\_private\_hosted\_zone) | Private hosted zone to create DNS records in. If null, `create_dns` must be set to false. | `string` | `null` | no |
124131
| <a name="input_replication_group_description"></a> [replication\_group\_description](#input\_replication\_group\_description) | Description of the replication group to be created. If null, one will be generated using the name of the nodes. | `string` | `null` | no |
125132
| <a name="input_replication_group_id"></a> [replication\_group\_id](#input\_replication\_group\_id) | Replication group identifier. This parameter is stored as a lowercase string. If null, the name of the nodes will be used. | `string` | `null` | no |
133+
| <a name="input_retention_in_days"></a> [retention\_in\_days](#input\_retention\_in\_days) | Log retention in days | `number` | `7` | no |
126134
| <a name="input_security_group_ids"></a> [security\_group\_ids](#input\_security\_group\_ids) | One or more VPC security groups associated with the nodes. If null, use the one provided by this module. | `list(string)` | `null` | no |
135+
| <a name="input_service_name"></a> [service\_name](#input\_service\_name) | Name of the service running this task. Only important here because the AWS console defaults to `/ecs/service_name` when displaying logs for a service | `string` | `null` | no |
127136
| <a name="input_sg_name"></a> [sg\_name](#input\_sg\_name) | Name of the security group to be created. If null, will use the name of the nodes. | `string` | `null` | no |
128137
| <a name="input_snapshot_arns"></a> [snapshot\_arns](#input\_snapshot\_arns) | Single-element string list containing an Amazon Resource Name (ARN) of a Redis RDB snapshot file stored in Amazon S3. The object name cannot contain any commas. Changing snapshot\_arns forces a new resource. | `list(string)` | `null` | no |
129138
| <a name="input_snapshot_retention_limit"></a> [snapshot\_retention\_limit](#input\_snapshot\_retention\_limit) | Number of days for which ElastiCache will retain automatic cluster snapshots before deleting them. For example, if you set SnapshotRetentionLimit to 5, then a snapshot that was taken today will be retained for 5 days before being deleted. If the value of SnapshotRetentionLimit is set to zero (0), backups are turned off. Please note that setting a snapshot\_retention\_limit is not supported on cache.t1.micro cache nodes. | `number` | `null` | no |

examples/logs-cloudwatch/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
backend.tf
2+
provider.tf

examples/logs-cloudwatch/.terraform.lock.hcl

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/logs-cloudwatch/main.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module "redis" {
2+
source = "../.."
3+
4+
create_dns = false
5+
create_log_group = true
6+
7+
organization = var.organization
8+
environment = var.environment
9+
product = var.product
10+
repo = var.repo
11+
}

examples/logs-cloudwatch/outputs.tf

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
output "name" {
2+
description = "The name of the ElastiCache replication group"
3+
value = module.redis.name
4+
}
5+
6+
output "arn" {
7+
description = "The ARN of the ElastiCache replication group"
8+
value = module.redis.arn
9+
}
10+
11+
output "sg_ids" {
12+
description = "The security group ids"
13+
value = module.redis.sg_ids
14+
}
15+
16+
output "engine_version_actual" {
17+
description = "Because ElastiCache pulls the latest minor or patch for a version, this attribute returns the running version of the cache engine."
18+
value = module.redis.engine_version_actual
19+
}
20+
21+
output "member_clusters" {
22+
description = "Identifiers of all the nodes that are part of this replication group."
23+
value = module.redis.member_clusters
24+
}
25+
26+
output "primary_endpoint_address" {
27+
description = "Address of the endpoint for the primary node in the replication group."
28+
value = module.redis.primary_endpoint_address
29+
}
30+
31+
output "reader_endpoint_address" {
32+
description = "Address of the endpoint for the reader node in the replication group."
33+
value = module.redis.reader_endpoint_address
34+
}
35+
36+
output "tags" {
37+
description = "The tags"
38+
value = module.redis.tags
39+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# terraform {
2+
# backend "s3" {
3+
# bucket = "my-bucket-tfstate"
4+
# key = "example-terraform-aws-elasticache-redis-standalone-no-dns"
5+
# profile = "my-profile"
6+
# region = "us-east-1"
7+
# dynamodb_table = "terraform-lock"
8+
# }
9+
# }
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# provider "aws" {
2+
# region = "us-east-1"
3+
# profile = "my-profile"
4+
# default_tags {
5+
# tags = {
6+
# product = var.product
7+
# environment = var.environment
8+
# repo = var.repo
9+
# organization = var.organization
10+
# }
11+
# }
12+
# }

examples/logs-cloudwatch/tags.tf

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
variable "environment" {
2+
description = "Environment (sharedtools, dev, staging, prod)"
3+
type = string
4+
5+
default = "sharedtools"
6+
7+
validation {
8+
condition = contains(["sharedtools", "dev", "staging", "prod"], var.environment)
9+
error_message = "The environment variable must be one of [sharedtools, dev, staging, prod]."
10+
}
11+
}
12+
13+
variable "product" {
14+
description = "Tag used to group resources according to application"
15+
16+
default = "ex-tf-redis-no-dns"
17+
18+
validation {
19+
condition = can(regex("[a-z\\-]+", var.product))
20+
error_message = "The product variable violates approved regex."
21+
}
22+
}
23+
24+
variable "repo" {
25+
description = "Tag used to point to the repo using this module"
26+
27+
default = "https://github.com/pbs/terraform-elasticache-redis-standalone-module.git"
28+
29+
validation {
30+
condition = can(regex("(?:git|ssh|https?|git@[-\\w.]+):(\\/\\/)?(.*?)(\\.git)(\\/?|\\#[-\\d\\w._]+?)$", var.repo))
31+
error_message = "The repo variable violates approved regex."
32+
}
33+
}
34+
35+
variable "organization" {
36+
description = "Organization using this module. Used to prefix tags so that they are easily identified as being from your organization"
37+
type = string
38+
39+
default = "example"
40+
41+
validation {
42+
condition = can(regex("[a-z\\-]+", var.organization))
43+
error_message = "The organization variable violates approved regex."
44+
}
45+
}

examples/logs-kinesis/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
backend.tf
2+
provider.tf

examples/logs-kinesis/.terraform.lock.hcl

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/logs-kinesis/main.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module "redis" {
2+
source = "../.."
3+
4+
create_dns = false
5+
log_destination = "some-kinesis-stream-name"
6+
log_destination_type = "kinesis-firehose"
7+
log_format = "json"
8+
log_type = "engine-log"
9+
10+
organization = var.organization
11+
environment = var.environment
12+
product = var.product
13+
repo = var.repo
14+
}

examples/logs-kinesis/outputs.tf

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
output "name" {
2+
description = "The name of the ElastiCache replication group"
3+
value = module.redis.name
4+
}
5+
6+
output "arn" {
7+
description = "The ARN of the ElastiCache replication group"
8+
value = module.redis.arn
9+
}
10+
11+
output "sg_ids" {
12+
description = "The security group ids"
13+
value = module.redis.sg_ids
14+
}
15+
16+
output "engine_version_actual" {
17+
description = "Because ElastiCache pulls the latest minor or patch for a version, this attribute returns the running version of the cache engine."
18+
value = module.redis.engine_version_actual
19+
}
20+
21+
output "member_clusters" {
22+
description = "Identifiers of all the nodes that are part of this replication group."
23+
value = module.redis.member_clusters
24+
}
25+
26+
output "primary_endpoint_address" {
27+
description = "Address of the endpoint for the primary node in the replication group."
28+
value = module.redis.primary_endpoint_address
29+
}
30+
31+
output "reader_endpoint_address" {
32+
description = "Address of the endpoint for the reader node in the replication group."
33+
value = module.redis.reader_endpoint_address
34+
}
35+
36+
output "tags" {
37+
description = "The tags"
38+
value = module.redis.tags
39+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# terraform {
2+
# backend "s3" {
3+
# bucket = "my-bucket-tfstate"
4+
# key = "example-terraform-aws-elasticache-redis-standalone-no-dns"
5+
# profile = "my-profile"
6+
# region = "us-east-1"
7+
# dynamodb_table = "terraform-lock"
8+
# }
9+
# }
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# provider "aws" {
2+
# region = "us-east-1"
3+
# profile = "my-profile"
4+
# default_tags {
5+
# tags = {
6+
# product = var.product
7+
# environment = var.environment
8+
# repo = var.repo
9+
# organization = var.organization
10+
# }
11+
# }
12+
# }

examples/logs-kinesis/tags.tf

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
variable "environment" {
2+
description = "Environment (sharedtools, dev, staging, prod)"
3+
type = string
4+
5+
default = "sharedtools"
6+
7+
validation {
8+
condition = contains(["sharedtools", "dev", "staging", "prod"], var.environment)
9+
error_message = "The environment variable must be one of [sharedtools, dev, staging, prod]."
10+
}
11+
}
12+
13+
variable "product" {
14+
description = "Tag used to group resources according to application"
15+
16+
default = "ex-tf-redis-no-dns"
17+
18+
validation {
19+
condition = can(regex("[a-z\\-]+", var.product))
20+
error_message = "The product variable violates approved regex."
21+
}
22+
}
23+
24+
variable "repo" {
25+
description = "Tag used to point to the repo using this module"
26+
27+
default = "https://github.com/pbs/terraform-elasticache-redis-standalone-module.git"
28+
29+
validation {
30+
condition = can(regex("(?:git|ssh|https?|git@[-\\w.]+):(\\/\\/)?(.*?)(\\.git)(\\/?|\\#[-\\d\\w._]+?)$", var.repo))
31+
error_message = "The repo variable violates approved regex."
32+
}
33+
}
34+
35+
variable "organization" {
36+
description = "Organization using this module. Used to prefix tags so that they are easily identified as being from your organization"
37+
type = string
38+
39+
default = "example"
40+
41+
validation {
42+
condition = can(regex("[a-z\\-]+", var.organization))
43+
error_message = "The organization variable violates approved regex."
44+
}
45+
}

locals.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
locals {
22
name = var.name != null ? var.name : var.product
3+
service_name = var.service_name != null ? var.service_name : local.name
34
security_group_ids = var.security_group_ids != null ? var.security_group_ids : [aws_security_group.sg.id]
45
subnet_group_name = var.subnet_group_name != null ? var.subnet_group_name : aws_elasticache_subnet_group.subnet_group.id
56
vpc_id = var.vpc_id != null ? var.vpc_id : data.aws_vpc.vpc[0].id
67
subnets = var.subnets != null ? var.subnets : data.aws_subnets.private_subnets[0].ids
78
cname = var.cname != null ? var.cname : "${local.name}-cache"
89
private_hosted_zone = var.create_dns ? data.aws_route53_zone.private_hosted_zone[0].zone_id : null
910

11+
log_destination = var.log_destination != null ? var.log_destination : "/ecs/${local.service_name}"
12+
create_log_group = var.log_destination == null ? var.create_log_group : false
13+
1014
vpc_data_lookup_tags = var.vpc_data_lookup_tags != null ? var.vpc_data_lookup_tags : {
1115
"environment" : var.environment
1216
}

logs.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
resource "aws_cloudwatch_log_group" "logs" {
2+
count = local.create_log_group == true ? 1 : 0
3+
4+
name = local.log_destination
5+
6+
retention_in_days = var.retention_in_days
7+
8+
log_group_class = var.log_group_class
9+
10+
tags = {
11+
Name = "${local.service_name} Log Group"
12+
application = var.product
13+
environment = var.environment
14+
creator = local.creator
15+
}
16+
}

0 commit comments

Comments
 (0)