-
Notifications
You must be signed in to change notification settings - Fork 16
/
trail.tf
84 lines (71 loc) · 2.22 KB
/
trail.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
data "aws_caller_identity" "current" {}
resource "aws_cloudtrail" "ggcanary_trail" { # ggignore-iac: GG_IAC_0027
name = "${var.global_prefix}-trail"
s3_bucket_name = aws_s3_bucket.ggcanary_bucket.id
s3_key_prefix = "ggcanary"
include_global_service_events = true
is_multi_region_trail = true
enable_log_file_validation = true
event_selector {
read_write_type = "All"
include_management_events = true
data_resource {
type = "AWS::S3::Object"
values = ["arn:aws:s3:::"]
}
}
# https://github.com/hashicorp/terraform/issues/6388
depends_on = [aws_s3_bucket_policy.ggcanary_bucket_policy]
}
data "aws_iam_policy_document" "ggcanary_bucket" {
statement {
effect = "Allow"
actions = [
"s3:GetBucketAcl"
]
resources = ["arn:aws:s3:::${var.global_prefix}-bucket"]
principals {
type = "Service"
identifiers = ["cloudtrail.amazonaws.com"]
}
}
statement {
effect = "Allow"
actions = [
"s3:PutObject"
]
resources = ["arn:aws:s3:::${var.global_prefix}-bucket/ggcanary/AWSLogs/${data.aws_caller_identity.current.account_id}/*"]
principals {
type = "Service"
identifiers = ["cloudtrail.amazonaws.com"]
}
condition {
test = "StringEquals"
values = ["bucket-owner-full-control"]
variable = "s3:x-amz-acl"
}
}
}
resource "aws_s3_bucket" "ggcanary_bucket" {
bucket = "${var.global_prefix}-bucket"
force_destroy = true
}
resource "aws_s3_bucket_policy" "ggcanary_bucket_policy" {
bucket = aws_s3_bucket.ggcanary_bucket.id
policy = data.aws_iam_policy_document.ggcanary_bucket.json
}
resource "aws_s3_bucket_public_access_block" "ggcanary_bucket_public_access" {
bucket = aws_s3_bucket.ggcanary_bucket.id
block_public_acls = true
block_public_policy = true
restrict_public_buckets = true
ignore_public_acls = true
}
resource "aws_s3_bucket_server_side_encryption_configuration" "ggcanary_bucket_server_side_encryption_configuration" {
bucket = aws_s3_bucket.ggcanary_bucket.id
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "aws:kms"
}
}
}