forked from magenx/Magento-2-aws-cluster-terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws_config.tf
80 lines (75 loc) · 3.3 KB
/
aws_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
/////////////////////////////////////////////////////////[ AWS CONFIG ]///////////////////////////////////////////////////
# # ---------------------------------------------------------------------------------------------------------------------#
# Create AWS config rules
# # ---------------------------------------------------------------------------------------------------------------------#
resource "aws_config_config_rule" "this" {
depends_on = [aws_config_configuration_recorder.this]
for_each = var.aws_config_rule
name = "${local.project}-${each.key}"
description = "Evaluate your AWS resource configurations for ${each.key} rule"
source {
owner = "AWS"
source_identifier = each.key
}
dynamic "scope" {
for_each = each.value == "" ? [] : [each.value]
content {
compliance_resource_types = ["${scope.value}"]
}
}
tags = {
Name = "${local.project}-${each.key}"
}
}
# # ---------------------------------------------------------------------------------------------------------------------#
# Create AWS Config recorder
# # ---------------------------------------------------------------------------------------------------------------------#
resource "aws_config_configuration_recorder" "this" {
name = "${local.project}-recorder"
role_arn = aws_iam_role.config.arn
}
# # ---------------------------------------------------------------------------------------------------------------------#
# Create AWS Config recorder status
# # ---------------------------------------------------------------------------------------------------------------------#
resource "aws_config_configuration_recorder_status" "this" {
depends_on = [aws_config_delivery_channel.this]
name = aws_config_configuration_recorder.this.name
is_enabled = true
}
# # ---------------------------------------------------------------------------------------------------------------------#
# Create AWS Config delivery channel
# # ---------------------------------------------------------------------------------------------------------------------#
resource "aws_config_delivery_channel" "this" {
name = "${local.project}-channel"
s3_bucket_name = aws_s3_bucket.this["system"].bucket
s3_key_prefix = "aws_config"
sns_topic_arn = aws_sns_topic.default.arn
}
# # ---------------------------------------------------------------------------------------------------------------------#
# Create AWS Config role
# # ---------------------------------------------------------------------------------------------------------------------#
resource "aws_iam_role" "config" {
name = "${local.project}-aws-config"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "config.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
# # ---------------------------------------------------------------------------------------------------------------------#
# Create AWS Config role policy
# # ---------------------------------------------------------------------------------------------------------------------#
resource "aws_iam_role_policy_attachment" "config" {
role = aws_iam_role.config.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSConfigRole"
}