Skip to content

Commit 08f45c9

Browse files
Merge pull request #19 from hbarros-caylent/CA-93-cw-logs
CA-93 cloudwatch logs integration
2 parents ac67e01 + b7b6303 commit 08f45c9

File tree

14 files changed

+168
-8
lines changed

14 files changed

+168
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Tamr Terraform AWS Elasticsearch Repo
22

3+
## v3.1.0 - November 15th 2021
4+
* Adds variables `logs_retention_in_days` and `log_types` that enables the publishing of ElasticSearch Logs into CloudWatch
5+
36
## v3.0.0 - August 9th 2021
47
* Requires ES service role to be created as a prerequisite to using this module (see README)
58
* Removes input variables `linked_service_role` and `create_new_service_role`

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ No provider.
6565
| instance\_count | Number of instances to launch in the ES domain | `number` | `2` | no |
6666
| instance\_type | Instance type of data nodes in the domain | `string` | `"c5.large.elasticsearch"` | no |
6767
| kms\_key\_id | The KMS key id to encrypt the Elasticsearch domain with.<br> If not specified then it defaults to using the aws/es service KMS key | `string` | `null` | no |
68+
| log\_retention\_in\_days | Specifies the number of days you want to retain log events.<br> Possible values are: 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653, and 0.<br> If you select 0, the events in the log group are always retained and never expire. | `number` | `0` | no |
69+
| log\_types | A list of log types that will be published to CloudWatch. Valid values are SEARCH\_SLOW\_LOGS, INDEX\_SLOW\_LOGS, ES\_APPLICATION\_LOGS and AUDIT\_LOGS. | `list(string)` | <pre>[<br> "ES_APPLICATION_LOGS",<br> "SEARCH_SLOW_LOGS",<br> "INDEX_SLOW_LOGS"<br>]</pre> | no |
6870
| node\_to\_node\_encryption\_enabled | Whether to enable node-to-node encryption | `bool` | `true` | no |
6971
| revoke\_rules\_on\_delete | Whether to revoke rules from the SG upon deletion | `bool` | `true` | no |
7072
| security\_group\_ids | List of security group IDs to be applied to the ES domain | `list(string)` | `[]` | no |

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.0
1+
3.1.0

examples/minimal/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ No requirements.
1515
|------|-------------|------|---------|:--------:|
1616
| name-prefix | A string to prepend to names of resources created by this example | `any` | n/a | yes |
1717
| create\_new\_service\_role | Whether to create a new IAM service linked role for ES. This only needs to happen once per account. If false, linked\_service\_role is required | `bool` | `false` | no |
18+
| log\_retention\_in\_days | Specifies the number of days you want to retain log events.<br> Possible values are: 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653, and 0.<br> If you select 0, the events in the log group are always retained and never expire. | `number` | `0` | no |
19+
| log\_types | A list of log types that will be published to CloudWatch. Valid values are SEARCH\_SLOW\_LOGS, INDEX\_SLOW\_LOGS, ES\_APPLICATION\_LOGS and AUDIT\_LOGS. | `list(string)` | <pre>[<br> "ES_APPLICATION_LOGS",<br> "SEARCH_SLOW_LOGS",<br> "INDEX_SLOW_LOGS"<br>]</pre> | no |
1820
| tags | A map of tags to add to all resources created by this example. | `map(string)` | <pre>{<br> "Author": "Tamr",<br> "Environment": "Example"<br>}</pre> | no |
1921

2022
## Outputs

examples/minimal/main.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ resource "aws_iam_service_linked_role" "es" {
3434
}
3535

3636
module "tamr-es-cluster" {
37-
depends_on = [aws_iam_service_linked_role.es]
38-
source = "../../"
39-
vpc_id = aws_vpc.es_vpc.id
40-
domain_name = format("%s-elasticsearch", var.name-prefix)
41-
subnet_ids = [aws_subnet.es_subnet.id]
42-
security_group_ids = module.aws-sg.security_group_ids
43-
tags = var.tags
37+
depends_on = [aws_iam_service_linked_role.es]
38+
source = "../../"
39+
vpc_id = aws_vpc.es_vpc.id
40+
domain_name = format("%s-elasticsearch", var.name-prefix)
41+
subnet_ids = [aws_subnet.es_subnet.id]
42+
security_group_ids = module.aws-sg.security_group_ids
43+
tags = var.tags
4444
}

main.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,18 @@ module "tamr-es-cluster" {
2222
tls_security_policy = var.tls_security_policy
2323
node_to_node_encryption_enabled = var.node_to_node_encryption_enabled
2424
arn_partition = var.arn_partition
25+
log_publishing_options = module.tamr-es-coudwatch-log-groups.log_publishing_options
26+
27+
depends_on = [
28+
module.tamr-es-coudwatch-log-groups
29+
]
30+
}
31+
32+
module "tamr-es-coudwatch-log-groups" {
33+
source = "./modules/cloudwatch-logs"
34+
35+
domain_name = var.domain_name
36+
tags = local.effective_tags
37+
log_types = var.log_types
38+
log_retention_in_days = var.log_retention_in_days
2539
}

modules/aws-es/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ This modules creates:
4848
| instance\_count | Number of instances to launch in the ES domain | `number` | `2` | no |
4949
| instance\_type | Instance type of data nodes in the domain | `string` | `"c5.large.elasticsearch"` | no |
5050
| kms\_key\_id | The KMS key id to encrypt the Elasticsearch domain with.<br> If not specified then it defaults to using the aws/es service KMS key | `string` | `null` | no |
51+
| log\_publishing\_options | Set of objects containing values for publishing logs to cloudwatch | <pre>list(object({<br> log_group_arn = string<br> log_type = string<br> }))</pre> | `[]` | no |
5152
| node\_to\_node\_encryption\_enabled | Whether to enable node-to-node encryption | `bool` | `true` | no |
5253
| security\_group\_ids | List of security group IDs to be applied to the ES domain | `list(string)` | `[]` | no |
5354
| snapshot\_start\_hour | Hour when an automated daily snapshot of the indices is taken | `number` | `0` | no |

modules/aws-es/main.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#tfsec:ignore:aws-elastic-search-enable-domain-logging tfsec:ignore:aws-elastic-search-enable-logging
12
resource "aws_elasticsearch_domain" "tamr-es-cluster" {
23
domain_name = var.domain_name
34
elasticsearch_version = var.es_version
@@ -38,6 +39,15 @@ resource "aws_elasticsearch_domain" "tamr-es-cluster" {
3839
enabled = var.node_to_node_encryption_enabled
3940
}
4041

42+
dynamic "log_publishing_options" {
43+
for_each = var.log_publishing_options
44+
content {
45+
cloudwatch_log_group_arn = log_publishing_options.value["log_group_arn"]
46+
enabled = true
47+
log_type = log_publishing_options.value["log_type"]
48+
}
49+
}
50+
4151
tags = var.tags
4252
}
4353

modules/aws-es/variables.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,12 @@ variable "arn_partition" {
118118
EOF
119119
default = "aws"
120120
}
121+
122+
variable "log_publishing_options" {
123+
type = list(object({
124+
log_group_arn = string
125+
log_type = string
126+
}))
127+
description = "Set of objects containing values for publishing logs to cloudwatch"
128+
default = []
129+
}

modules/cloudwatch-logs/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
2+
## Requirements
3+
4+
No requirements.
5+
6+
## Providers
7+
8+
| Name | Version |
9+
|------|---------|
10+
| aws | n/a |
11+
| random | n/a |
12+
13+
## Inputs
14+
15+
| Name | Description | Type | Default | Required |
16+
|------|-------------|------|---------|:--------:|
17+
| domain\_name | The name to give to the ES domain | `string` | `"tamr-es-cluster"` | no |
18+
| log\_retention\_in\_days | Specifies the number of days you want to retain log events.<br> Possible values are: 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653, and 0.<br> If you select 0, the events in the log group are always retained and never expire. | `number` | `0` | no |
19+
| log\_types | A list of log types that will be published to CloudWatch. Valid values are SEARCH\_SLOW\_LOGS, INDEX\_SLOW\_LOGS, ES\_APPLICATION\_LOGS and AUDIT\_LOGS. | `list(string)` | <pre>[<br> "ES_APPLICATION_LOGS",<br> "SEARCH_SLOW_LOGS",<br> "INDEX_SLOW_LOGS"<br>]</pre> | no |
20+
| tags | A map of tags to add to CloudWatch resources. | `map(string)` | `{}` | no |
21+
22+
## Outputs
23+
24+
| Name | Description |
25+
|------|-------------|
26+
| log\_publishing\_options | n/a |
27+
28+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
29+
30+
# References
31+
This repo is based on:
32+
* [terraform standard module structure](https://www.terraform.io/docs/modules/index.html#standard-module-structure)
33+
* [templated terraform module](https://github.com/tmknom/template-terraform-module)
34+
35+
# License
36+
Apache 2 Licensed. See LICENSE for full details.

0 commit comments

Comments
 (0)