-
Notifications
You must be signed in to change notification settings - Fork 9
/
config.tf
96 lines (75 loc) · 2.47 KB
/
config.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
90
91
92
93
94
95
96
# 2.5 – Ensure AWS Config is enabled
data "aws_iam_policy_document" "recorder_assume_role_policy" {
statement {
principals {
type = "Service"
identifiers = ["config.amazonaws.com"]
}
actions = ["sts:AssumeRole"]
}
}
resource "aws_iam_role" "recorder" {
name = "${var.resource_name_prefix}-config-role"
assume_role_policy = data.aws_iam_policy_document.recorder_assume_role_policy.json
tags = var.tags
}
#https://docs.aws.amazon.com/config/latest/developerguide/iamrole-permissions.html
data "aws_iam_policy_document" "recorder_publish_policy" {
depends_on = [aws_s3_bucket.audit[0]]
statement {
actions = ["s3:PutObject"]
resources = ["${aws_s3_bucket.audit[0].arn}/config/AWSLogs/${var.aws_account_id}/*"]
condition {
test = "StringLike"
variable = "s3:x-amz-acl"
values = ["bucket-owner-full-control"]
}
}
statement {
actions = ["s3:GetBucketAcl"]
resources = [aws_s3_bucket.audit[0].arn]
}
statement {
actions = ["sns:Publish"]
resources = [var.sns_arn]
}
}
resource "aws_iam_role_policy" "recorder_publish_policy" {
name = "${var.resource_name_prefix}-config-policy"
role = aws_iam_role.recorder.id
policy = data.aws_iam_policy_document.recorder_publish_policy.json
}
resource "aws_iam_role_policy_attachment" "recorder_read_policy" {
role = aws_iam_role.recorder.id
policy_arn = "arn:aws:iam::aws:policy/service-role/AWS_ConfigRole"
}
resource "aws_config_configuration_recorder" "recorder" {
count = var.config_enabled ? 1 : 0
name = var.resource_name_prefix
role_arn = aws_iam_role.recorder.arn
recording_group {
all_supported = true
include_global_resource_types = var.include_global_resource_types
}
}
resource "aws_config_delivery_channel" "bucket" {
count = var.config_enabled ? 1 : 0
name = var.resource_name_prefix
s3_bucket_name = aws_s3_bucket.audit[0].id
s3_key_prefix = "config"
sns_topic_arn = var.sns_arn
snapshot_delivery_properties {
delivery_frequency = "One_Hour"
}
depends_on = [
aws_config_configuration_recorder.recorder[0],
aws_s3_bucket_policy.audit_log[0],
aws_s3_bucket_public_access_block.audit[0]
]
}
resource "aws_config_configuration_recorder_status" "recorder" {
count = var.config_enabled ? 1 : 0
name = aws_config_configuration_recorder.recorder[0].id
is_enabled = true
depends_on = [aws_config_delivery_channel.bucket[0]]
}