-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
144 lines (125 loc) · 3.43 KB
/
main.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
## Label
module "config_label" {
source = "[email protected]:3scale-ops/tf-aws-label.git?ref=tags/0.1.2"
project = var.project
environment = var.environment
workload = var.workload
type = "config"
tf_config = var.tf_config
}
## Config bucket
module "config_bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
version = "v3.8.2"
bucket = module.config_label.id
acl = "private"
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
force_destroy = true
attach_policy = true
policy = data.aws_iam_policy_document.config_bucket_policy.json
tags = module.config_label.tags
versioning = {
enabled = true
}
}
data "aws_iam_policy_document" "config_bucket_policy" {
statement {
sid = "AWSConfigBucketPermissionsCheck"
principals {
type = "Service"
identifiers = ["config.amazonaws.com"]
}
actions = [
"s3:GetBucketAcl",
]
resources = [
"arn:aws:s3:::${module.config_label.id}",
]
}
statement {
sid = "AWSConfigBucketExistenceCheck"
principals {
type = "Service"
identifiers = ["config.amazonaws.com"]
}
actions = [
"s3:ListBucket",
]
resources = [
"arn:aws:s3:::${module.config_label.id}",
]
}
statement {
sid = "AWSConfigBucketDelivery"
principals {
type = "Service"
identifiers = ["config.amazonaws.com"]
}
actions = [
"s3:PutObject",
]
resources = [
"arn:aws:s3:::${module.config_label.id}/*",
]
condition {
test = "StringEquals"
variable = "s3:x-amz-acl"
values = [
"bucket-owner-full-control",
]
}
}
}
## SNS
#resource "aws_sns_topic" "config" {
# name = module.config_label.id
#}
#
#data "aws_iam_policy_document" "config_sns_policy" {
# statement {
# effect = "Allow"
# principals {
# type = "AWS"
# identifiers = [module.config.aws_config_role_arn]
# }
# actions = ["SNS:Publish"]
# resources = [aws_sns_topic.config.arn]
# }
#}
#
#resource "aws_sns_topic_policy" "config" {
# arn = aws_sns_topic.config.arn
# policy = data.aws_iam_policy_document.config_sns_policy.json
#}
#
#resource "aws_sns_topic_subscription" "email" {
# topic_arn = aws_sns_topic.config.arn
# protocol = "email"
# endpoint = "var.email"
#}
## Config
module "config" {
source = "trussworks/config/aws"
version = "4.3.0"
config_name = module.config_label.id
config_logs_bucket = module.config_bucket.s3_bucket_id
#config_sns_topic_arn = aws_sns_topic.config.arn
check_cloud_trail_encryption = true
check_cloud_trail_log_file_validation = true
check_multi_region_cloud_trail = true
check_guard_duty = true
check_mfa_enabled_for_iam_console_access = true
check_root_account_mfa_enabled = true
check_rds_public_access = true
check_s3_bucket_ssl_requests_only = false
tags = module.config_label.tags
}
# Delete all default rules from default SG of default VPC
resource "aws_default_vpc" "default" {
}
resource "aws_default_security_group" "default" {
vpc_id = aws_default_vpc.default.id
}