-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Log Anomaly Detection Support (#74)
- Loading branch information
1 parent
bf575e0
commit e62a3b7
Showing
72 changed files
with
502 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ terraform { | |
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 5.58" | ||
version = ">= 5.81" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ terraform { | |
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 5.58" | ||
version = ">= 5.81" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ terraform { | |
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 5.58" | ||
version = ">= 5.81" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ terraform { | |
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 5.58" | ||
version = ">= 5.81" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Complete Log Anomaly Detector | ||
|
||
<!-- BEGIN_TF_DOCS --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 | | ||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.81 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.81 | | ||
|
||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| <a name="module_kms"></a> [kms](#module\_kms) | terraform-aws-modules/kms/aws | ~> 1.0 | | ||
| <a name="module_log_anomaly_detector"></a> [log\_anomaly\_detector](#module\_log\_anomaly\_detector) | ../../modules/log-anomaly-detector | n/a | | ||
| <a name="module_log_group"></a> [log\_group](#module\_log\_group) | ../../modules/log-group | n/a | | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source | | ||
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source | | ||
|
||
## Inputs | ||
|
||
No inputs. | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_cloudwatch_log_anomaly_arn"></a> [cloudwatch\_log\_anomaly\_arn](#output\_cloudwatch\_log\_anomaly\_arn) | The ARN of the anomaly detector. | | ||
<!-- END_TF_DOCS --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
provider "aws" { | ||
region = "eu-west-1" | ||
} | ||
|
||
locals { | ||
name = "ex-${basename(path.cwd)}" | ||
} | ||
|
||
module "log_group" { | ||
source = "../../modules/log-group" | ||
|
||
name = local.name | ||
retention_in_days = 7 | ||
kms_key_id = module.kms.key_arn | ||
} | ||
|
||
module "log_anomaly_detector" { | ||
source = "../../modules/log-anomaly-detector" | ||
|
||
detector_name = local.name | ||
log_group_arns = [module.log_group.cloudwatch_log_group_arn] | ||
anomaly_visibility_time = 7 | ||
enabled = true | ||
evaluation_frequency = "FIVE_MIN" | ||
filter_pattern = "%test%" | ||
kms_key_id = module.kms.key_arn | ||
} | ||
|
||
################################################################################ | ||
# Supporting Resources | ||
################################################################################ | ||
|
||
data "aws_caller_identity" "current" {} | ||
data "aws_region" "current" {} | ||
|
||
module "kms" { | ||
source = "terraform-aws-modules/kms/aws" | ||
version = "~> 1.0" | ||
description = "KMS key for log anomaly detection" | ||
|
||
key_owners = [data.aws_caller_identity.current.arn] | ||
key_statements = [ | ||
{ | ||
sid = "CloudWatchLogs" | ||
actions = [ | ||
"kms:Encrypt*", | ||
"kms:Decrypt*", | ||
"kms:ReEncrypt*", | ||
"kms:GenerateDataKey*", | ||
"kms:Describe*" | ||
] | ||
resources = ["*"] | ||
|
||
principals = [ | ||
{ | ||
type = "Service" | ||
identifiers = ["logs.${data.aws_region.current.name}.amazonaws.com"] | ||
} | ||
] | ||
|
||
conditions = [ | ||
{ | ||
test = "ArnLike" | ||
variable = "kms:EncryptionContext:aws:logs:arn" | ||
values = [ | ||
"arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:${local.name}", | ||
"arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:anomaly-detector:*" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
actions = [ | ||
"kms:Encrypt*", | ||
"kms:Decrypt*", | ||
"kms:ReEncrypt*", | ||
"kms:GenerateDataKey*", | ||
"kms:Describe*" | ||
] | ||
resources = ["*"] | ||
|
||
principals = [ | ||
{ | ||
type = "Service" | ||
identifiers = ["logs.${data.aws_region.current.name}.amazonaws.com"] | ||
} | ||
] | ||
|
||
conditions = [ | ||
{ | ||
test = "ArnLike" | ||
variable = "kms:EncryptionContext:aws-crypto-ec:aws:logs:arn" | ||
values = [ | ||
"arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:anomaly-detector:*" | ||
] | ||
} | ||
] | ||
} | ||
] | ||
tags = { | ||
terraform = true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
output "cloudwatch_log_anomaly_arn" { | ||
description = "The ARN of the anomaly detector." | ||
value = module.log_anomaly_detector.arn | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
terraform { | ||
required_version = ">= 1.0" | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 5.81" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ terraform { | |
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 5.58" | ||
version = ">= 5.81" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ terraform { | |
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 5.58" | ||
version = ">= 5.81" | ||
} | ||
} | ||
} |
Oops, something went wrong.