-
Notifications
You must be signed in to change notification settings - Fork 0
/
config-aggregator.tf
56 lines (42 loc) · 1.52 KB
/
config-aggregator.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
# AWS Config aggregator
## Organization Aggregator ##
resource "aws_config_configuration_aggregator" "config_aggregator" {
name = "config-organization-aggregator"
count = var.aggregation_type == "organization" ? 1 : 0
organization_aggregation_source {
role_arn = aws_iam_role.aggregator_organization[0].arn
regions = var.aws_regions
all_regions = var.all_regions
}
}
## Account Aggregator ##
resource "aws_config_configuration_aggregator" "account_config_aggregator" {
name = "config-account-aggregator"
count = var.aggregation_type == "account" ? 1 : 0
account_aggregation_source {
account_ids = var.account_ids
regions = var.aws_regions
all_regions = var.all_regions
}
}
## IAM Role for Organization Aggregator ##
data "aws_iam_policy_document" "aggregator_assume_role" {
statement {
effect = "Allow"
principals {
type = "Service"
identifiers = ["config.amazonaws.com"]
}
actions = ["sts:AssumeRole"]
}
}
resource "aws_iam_role" "aggregator_organization" {
count = var.aggregation_type == "organization" ? 1 : 0
name = "AWSConfigAggregatorRole"
assume_role_policy = data.aws_iam_policy_document.aggregator_assume_role.json
}
resource "aws_iam_role_policy_attachment" "aggregator_organization" {
count = var.aggregation_type == "organization" ? 1 : 0
role = aws_iam_role.aggregator_organization[0].name
policy_arn = "arn:${data.aws_partition.current.partition}:iam::aws:policy/service-role/AWSConfigRoleForOrganizations"
}