Skip to content

Commit 5cc5efb

Browse files
feat: Support aws_cloudwatch_query_definition and add skip_destroy argument to aws_cloudwatch_log_group (#60)
Co-authored-by: Bryant Biggs <[email protected]> Co-authored-by: magreenbaum <magreenbaum>
1 parent 81f852a commit 5cc5efb

File tree

26 files changed

+345
-7
lines changed

26 files changed

+345
-7
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,30 @@ module "cis_alarms" {
120120

121121
AWS CloudTrail normally publishes logs into AWS CloudWatch Logs. This module creates log metric filters together with metric alarms according to [CIS AWS Foundations Benchmark v1.4.0 (05-28-2021)](https://www.cisecurity.org/benchmark/amazon_web_services/). Read more about [CIS AWS Foundations Controls](https://docs.aws.amazon.com/securityhub/latest/userguide/securityhub-cis-controls.html).
122122

123+
### Query Definition
124+
125+
```hcl
126+
module "query_definition" {
127+
source = "terraform-aws-modules/cloudwatch/aws//modules/query-definition"
128+
version = "~> 4.0"
129+
130+
name = "my-query-definition"
131+
log_group_names = ["my-log-group-name"]
132+
query_string = <<EOF
133+
fields @timestamp, @message
134+
| sort @timestamp desc
135+
| limit 25
136+
EOF
137+
}
138+
```
123139
## Examples
124140

125141
- [Complete Cloudwatch log metric filter and alarm](https://github.com/terraform-aws-modules/terraform-aws-cloudwatch/tree/master/examples/complete-log-metric-filter-and-alarm)
126142
- [Cloudwatch log group with log stream](https://github.com/terraform-aws-modules/terraform-aws-cloudwatch/tree/master/examples/log-group-with-log-stream)
127143
- [Cloudwatch metric alarms for AWS Lambda](https://github.com/terraform-aws-modules/terraform-aws-cloudwatch/tree/master/examples/lambda-metric-alarm)
128144
- [Cloudwatch metric alarms for AWS Lambda with multiple dimensions](https://github.com/terraform-aws-modules/terraform-aws-cloudwatch/tree/master/examples/multiple-lambda-metric-alarm)
129145
- [CIS AWS Foundations Controls: Metrics + Alarms](https://github.com/terraform-aws-modules/terraform-aws-cloudwatch/tree/master/examples/cis-alarms)
146+
- [Cloudwatch query definition](https://github.com/terraform-aws-modules/terraform-aws-cloudwatch/tree/master/examples/query-definition)
130147

131148
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
132149
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/complete-log-metric-filter-and-alarm/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Note that this example may create resources which cost money. Run `terraform des
2020
| Name | Version |
2121
|------|---------|
2222
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
23-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0 |
23+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.40 |
2424

2525
## Providers
2626

examples/complete-log-metric-filter-and-alarm/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 4.0"
7+
version = ">= 4.40"
88
}
99
}
1010
}

examples/log-group-with-log-stream/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Note that this example may create resources which cost money. Run `terraform des
2020
| Name | Version |
2121
|------|---------|
2222
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
23-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0 |
23+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.40 |
2424

2525
## Providers
2626

examples/log-group-with-log-stream/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 4.0"
7+
version = ">= 4.40"
88
}
99
}
1010
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Cloudwatch query definition example
2+
3+
Configuration in this directory creates a Cloudwatch query definition for a specific Cloudwatch log group.
4+
5+
## Usage
6+
7+
To run this example you need to execute:
8+
9+
```bash
10+
$ terraform init
11+
$ terraform plan
12+
$ terraform apply
13+
```
14+
15+
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
16+
17+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
18+
## Requirements
19+
20+
| Name | Version |
21+
|------|---------|
22+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
23+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |
24+
25+
## Providers
26+
27+
No providers.
28+
29+
## Modules
30+
31+
| Name | Source | Version |
32+
|------|--------|---------|
33+
| <a name="module_log_group"></a> [log\_group](#module\_log\_group) | ../../modules/log-group | n/a |
34+
| <a name="module_query_definition"></a> [query\_definition](#module\_query\_definition) | ../../modules/query-definition | n/a |
35+
36+
## Resources
37+
38+
No resources.
39+
40+
## Inputs
41+
42+
No inputs.
43+
44+
## Outputs
45+
46+
| Name | Description |
47+
|------|-------------|
48+
| <a name="output_cloudwatch_log_group_arn"></a> [cloudwatch\_log\_group\_arn](#output\_cloudwatch\_log\_group\_arn) | ARN of Cloudwatch log group |
49+
| <a name="output_cloudwatch_log_group_name"></a> [cloudwatch\_log\_group\_name](#output\_cloudwatch\_log\_group\_name) | Name of Cloudwatch log group |
50+
| <a name="output_cloudwatch_query_definition_id"></a> [cloudwatch\_query\_definition\_id](#output\_cloudwatch\_query\_definition\_id) | The query definition id |
51+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/query-definition/main.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
provider "aws" {
2+
region = "eu-west-1"
3+
}
4+
5+
module "log_group" {
6+
source = "../../modules/log-group"
7+
8+
name_prefix = "my-log-group-"
9+
retention_in_days = 7
10+
}
11+
12+
module "query_definition" {
13+
source = "../../modules/query-definition"
14+
15+
name = "query-example"
16+
log_group_names = [
17+
module.log_group.cloudwatch_log_group_name
18+
]
19+
query_string = <<EOF
20+
fields @timestamp, @message
21+
| sort @timestamp desc
22+
| limit 25
23+
EOF
24+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
output "cloudwatch_log_group_name" {
2+
description = "Name of Cloudwatch log group"
3+
value = module.log_group.cloudwatch_log_group_name
4+
}
5+
6+
output "cloudwatch_log_group_arn" {
7+
description = "ARN of Cloudwatch log group"
8+
value = module.log_group.cloudwatch_log_group_arn
9+
}
10+
11+
output "cloudwatch_query_definition_id" {
12+
description = "The query definition id"
13+
value = module.query_definition.cloudwatch_query_definition_id
14+
}

examples/query-definition/variables.tf

Whitespace-only changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 5.0"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)