This repository has been archived by the owner on Feb 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudtrails-bucket.tf
81 lines (66 loc) · 2.03 KB
/
cloudtrails-bucket.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
# Account Identity
module "identity" {
source = "git::[email protected]:sagansystems/tf_account.git?ref=tags/0.5.0"
}
module "s3_bucket" {
source = "git::https://github.com/cloudposse/tf_log_storage.git?ref=tags/0.7.0"
attributes = var.attributes
delimiter = var.delimiter
name = var.name
namespace = var.namespace
stage = var.stage
tags = var.tags
acl = var.acl
region = var.region
force_destroy = var.force_destroy
lifecycle_rule_enabled = var.lifecycle_rule_enabled
versioning_enabled = var.versioning_enabled
noncurrent_version_expiration_days = var.noncurrent_version_expiration_days
noncurrent_version_transition_days = var.noncurrent_version_transition_days
standard_transition_days = var.standard_transition_days
glacier_transition_days = var.glacier_transition_days
expiration_days = var.expiration_days
}
resource "aws_s3_bucket_policy" "bucket_policy" {
bucket = module.s3_bucket.bucket_id
policy = data.aws_iam_policy_document.cloudtrails.json
}
locals {
bucket_path = join("/", compact([var.prefix, "AWSLogs"]))
account_list = sort(compact(concat([module.identity.account_id], var.accounts)))
}
data "aws_iam_policy_document" "cloudtrails" {
statement {
actions = [
"s3:GetBucketAcl",
]
effect = "Allow"
principals {
type = "Service"
identifiers = ["cloudtrail.amazonaws.com"]
}
resources = [
module.s3_bucket.bucket_arn,
]
}
statement {
actions = [
"s3:PutObject",
]
effect = "Allow"
principals {
type = "Service"
identifiers = ["cloudtrail.amazonaws.com"]
}
resources = formatlist(
"%s/%s/%s/*", module.s3_bucket.bucket_arn, local.bucket_path, local.account_list
)
condition {
test = "StringEquals"
variable = "s3:x-amz-acl"
values = [
"bucket-owner-full-control",
]
}
}
}