-
-
Notifications
You must be signed in to change notification settings - Fork 72
/
main.tf
89 lines (72 loc) · 2.51 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
provider "aws" {
region = var.region
}
## Everything after this is standard cloudtrail setup
data "aws_caller_identity" "current" {}
module "cloudtrail_s3_bucket" {
source = "cloudposse/cloudtrail-s3-bucket/aws"
version = "0.26.0"
force_destroy = true
context = module.this.context
}
resource "aws_cloudwatch_log_group" "default" {
name = module.this.id
tags = module.this.tags
retention_in_days = 90
}
data "aws_iam_policy_document" "log_policy" {
statement {
effect = "Allow"
actions = ["logs:CreateLogStream", "logs:PutLogEvents"]
resources = [
"arn:aws:logs:${var.region}:${data.aws_caller_identity.current.account_id}:log-group:${aws_cloudwatch_log_group.default.name}:log-stream:*"
]
}
}
data "aws_iam_policy_document" "assume_policy" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
identifiers = ["cloudtrail.amazonaws.com"]
type = "Service"
}
}
}
resource "aws_iam_role" "cloudtrail_cloudwatch_events_role" {
name = lower(join(module.this.delimiter, [module.this.id, "role"]))
assume_role_policy = data.aws_iam_policy_document.assume_policy.json
tags = module.this.tags
}
resource "aws_iam_role_policy" "policy" {
name = lower(join(module.this.delimiter, [module.this.id, "policy"]))
policy = data.aws_iam_policy_document.log_policy.json
role = aws_iam_role.cloudtrail_cloudwatch_events_role.id
}
module "metric_configs" {
source = "cloudposse/config/yaml"
version = "0.7.0"
map_config_local_base_path = path.module
map_config_paths = var.metrics_paths
context = module.this.context
}
module "cloudtrail" {
source = "cloudposse/cloudtrail/aws"
version = "0.17.0"
enable_log_file_validation = true
include_global_service_events = true
is_multi_region_trail = true
enable_logging = true
# TODO: Add event_selector
s3_bucket_name = module.cloudtrail_s3_bucket.bucket_id
# https://github.com/terraform-providers/terraform-provider-aws/issues/14557#issuecomment-671975672
cloud_watch_logs_group_arn = "${aws_cloudwatch_log_group.default.arn}:*"
cloud_watch_logs_role_arn = aws_iam_role.cloudtrail_cloudwatch_events_role.arn
context = module.this.context
}
## This is the module being used
module "cis_alarms" {
source = "../../"
log_group_name = aws_cloudwatch_log_group.default.name
metrics = module.metric_configs.map_configs
}