This repository has been archived by the owner on May 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
181 lines (144 loc) · 3.88 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
data "aws_caller_identity" "current" {}
// data "aws_iam_account_alias" "current" {}
// data "aws_partition" "current" {}
provider "aws" {
alias = "ses_region"
region = var.ses_region
}
#
# SES Ruleset
#
resource "aws_ses_receipt_rule_set" "main" {
count = var.enable_incoming_email ? 1 : 0
provider = aws.ses_region
rule_set_name = var.rule_set_name
}
resource "aws_ses_active_receipt_rule_set" "main" {
count = var.enable_incoming_email ? 1 : 0
provider = aws.ses_region
rule_set_name = aws_ses_receipt_rule_set.main[0].rule_set_name
}
#
# S3 bucket for receiving bounces
#
data "aws_iam_policy_document" "s3_allow_ses_puts" {
statement {
sid = "allow-ses-put"
effect = "Allow"
principals {
type = "Service"
identifiers = ["ses.amazonaws.com"]
}
actions = [
"s3:PutObject",
]
resources = [
"arn:aws:s3:::${var.ses_bucket}/*",
]
condition {
test = "StringEquals"
variable = "aws:Referer"
values = [data.aws_caller_identity.current.account_id]
}
}
statement {
sid = "https-only"
principals {
type = "*"
identifiers = ["*"]
}
effect = "Deny"
actions = [
"s3:*",
]
resources = [
"arn:aws:s3:::${var.ses_bucket}",
"arn:aws:s3:::${var.ses_bucket}/*",
]
condition {
test = "Bool"
variable = "aws:SecureTransport"
values = [false]
}
}
}
resource "aws_s3_bucket" "bucket" {
count = var.enable_incoming_email ? 1 : 0
bucket = var.ses_bucket
server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
acl = "private"
force_destroy = true
policy = data.aws_iam_policy_document.s3_allow_ses_puts.json
logging {
target_bucket = var.access_log_bucket
target_prefix = "s3/${var.ses_bucket}/"
}
# When objects are overwritten don't preserve the earlier versions just in case
versioning {
enabled = true
}
# Never expire/delete anything from these buckets
lifecycle_rule {
prefix = ""
enabled = false
# Move old reports to cheaper storage after they are not needed
transition {
# 5 years
days = 1825
storage_class = "GLACIER"
}
noncurrent_version_transition {
# 5 years
days = 1825
storage_class = "GLACIER"
}
}
}
resource "aws_s3_bucket_public_access_block" "public_access_block" {
count = var.enable_incoming_email ? 1 : 0
bucket = aws_s3_bucket.bucket[0].id
# Block new public ACLs and uploading public objects
block_public_acls = true
# Retroactively remove public access granted through public ACLs
ignore_public_acls = true
# Block new public bucket policies
block_public_policy = true
# Retroactivley block public and cross-account access if bucket has public policies
restrict_public_buckets = true
}
#
# Route53
#
data "aws_route53_zone" "selected" {
name = var.route53_domain_name
private_zone = var.private_zone
}
#
# SES Domain
#
module "ses_domain" {
providers = {
aws = aws.ses_region
}
source = "trussworks/ses-domain/aws"
version = "3.2.3"
enable_incoming_email = var.enable_incoming_email
domain_name = var.email_domain_name
route53_zone_id = data.aws_route53_zone.selected.zone_id
enable_verification = var.enable_verification
from_addresses = var.from_addresses
mail_from_domain = var.mail_from_domain
dmarc_p = var.dmarc_p
dmarc_rua = var.dmarc_rua
receive_s3_bucket = var.enable_incoming_email ? aws_s3_bucket.bucket[0].id : ""
receive_s3_prefix = var.receive_s3_prefix
enable_spf_record = var.enable_spf_record
extra_ses_records = var.extra_ses_records
ses_rule_set = var.enable_incoming_email ? aws_ses_receipt_rule_set.main[0].rule_set_name : ""
}