-
Notifications
You must be signed in to change notification settings - Fork 81
/
config-aggregator.tf
45 lines (37 loc) · 1.23 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
#
# IAM Role
#
data "aws_iam_policy_document" "aws_config_aggregator_role_policy" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["config.amazonaws.com"]
}
effect = "Allow"
}
}
resource "aws_iam_role" "aggregator" {
count = var.aggregate_organization ? 1 : 0
name = "${var.config_name}-aggregator-role"
assume_role_policy = data.aws_iam_policy_document.aws_config_aggregator_role_policy.json
permissions_boundary = var.config_role_permissions_boundary
tags = var.tags
}
resource "aws_iam_role_policy_attachment" "aggregator" {
count = var.aggregate_organization ? 1 : 0
role = aws_iam_role.aggregator[0].name
policy_arn = format("arn:%s:iam::aws:policy/service-role/AWSConfigRoleForOrganizations", data.aws_partition.current.partition)
}
#
# Configuration Aggregator
#
resource "aws_config_configuration_aggregator" "organization" {
count = var.aggregate_organization ? 1 : 0
depends_on = [aws_iam_role_policy_attachment.aggregator]
name = var.config_aggregator_name
organization_aggregation_source {
all_regions = true
role_arn = aws_iam_role.aggregator[0].arn
}
}