Skip to content

Commit 3be9a25

Browse files
committed
CAT-23836 Added log_delivery_configuration
1 parent e6efddf commit 3be9a25

18 files changed

+362
-0
lines changed

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+
}

main.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,15 @@ resource "aws_elasticache_replication_group" "replication_group" {
2929
transit_encryption_enabled = var.transit_encryption_enabled
3030
user_group_ids = var.user_group_ids
3131

32+
dynamic "log_delivery_configuration" {
33+
for_each = local.create_log_group ? [1] : []
34+
content {
35+
destination = local.log_destination
36+
destination_type = var.log_destination_type
37+
log_format = var.log_format
38+
log_type = var.log_type
39+
}
40+
}
41+
3242
tags = local.tags
3343
}

optional-logs.tf

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
variable "create_log_group" {
2+
description = "Flag for creating a CloudWatch log group."
3+
default = false
4+
type = bool
5+
}
6+
7+
variable "service_name" {
8+
description = "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"
9+
default = null
10+
type = string
11+
}
12+
13+
variable "log_group_class" {
14+
description = "Log class of the log group. Possible values are: STANDARD or INFREQUENT_ACCESS."
15+
default = "INFREQUENT_ACCESS"
16+
type = string
17+
}
18+
19+
variable "retention_in_days" {
20+
description = "Log retention in days"
21+
default = 7
22+
type = number
23+
}
24+
25+
variable "log_destination" {
26+
description = "Name of externally created CloudWatch Logs LogGroup or Kinesis Data Firehose resource. If any specified, create_log_group will be ignored."
27+
default = null
28+
type = string
29+
}
30+
31+
variable "log_destination_type" {
32+
description = "For CloudWatch Logs use cloudwatch-logs or for Kinesis Data Firehose use kinesis-firehose."
33+
default = "cloudwatch-logs"
34+
type = string
35+
}
36+
37+
variable "log_format" {
38+
description = "Log format with valid values of json or text."
39+
default = "text"
40+
type = string
41+
}
42+
43+
variable "log_type" {
44+
description = "Log type with valid values of slow-log or engine-log."
45+
default = "slow-log"
46+
type = string
47+
}

0 commit comments

Comments
 (0)