-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
301 lines (257 loc) · 7.12 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "~> 2.46"
}
cloudflare = {
source = "cloudflare/cloudflare"
version = "5.0.0-rc1"
}
namecheap = {
source = "namecheap/namecheap"
version = "~> 2.2"
}
}
}
provider "digitalocean" {
token = var.do_token
}
provider "cloudflare" {
email = var.cloudflare_email_address
api_key = var.cloudflare_api_token
}
provider "namecheap" {
user_name = "LukeDavia"
api_user = "LukeDavia"
api_key = var.namecheap_api_key
client_ip = var.namecheap_static_ip
}
# DigitalOcean Compute
import {
to = digitalocean_ssh_key.lukesEd25519SshKey
id = "40810713"
}
resource "digitalocean_ssh_key" "lukesEd25519SshKey" {
name = "Luke's Ed25519 SSH Key"
public_key = file("./resources/id_ed25519.pub")
}
import {
to = digitalocean_droplet.lukeify
id = "398099896"
}
# Imported resource. These details should be manually amended when an upgrade needs to be performed:
# 1. The droplet currently runs Ubuntu 22.04 (x64)—but the image ID is custom from the OpenTofu import.
# 2. The SSH key should be manually specified here using the ssh_keys property when the resource is recreated.
resource "digitalocean_droplet" "lukeify" {
image = "129211873"
monitoring = true
name = "lukeify"
region = "syd1"
size = "s-1vcpu-512mb-10gb"
tags = ["lukeify"]
}
# It's easier to recreate this in OpenTofu rather than importing it.
resource "digitalocean_firewall" "lukeifyFirewall" {
name = "LukeifyFirewall"
droplet_ids = [digitalocean_droplet.lukeify.id]
# Allow SSH
inbound_rule {
protocol = "tcp"
port_range = "22"
source_addresses = ["0.0.0.0/0", "::/0"]
}
# Allow HTTP
inbound_rule {
protocol = "tcp"
port_range = "80"
source_addresses = ["0.0.0.0/0", "::/0"]
}
# Allow HTTPS
inbound_rule {
protocol = "tcp"
port_range = "443"
source_addresses = ["0.0.0.0/0", "::/0"]
}
# Allow UDP (for HTTP/3 access)
inbound_rule {
protocol = "udp"
port_range = "443"
source_addresses = ["0.0.0.0/0", "::/0"]
}
# Allow TCP egress on all ports
outbound_rule {
protocol = "tcp"
port_range = "1-65535"
destination_addresses = ["0.0.0.0/0", "::/0"]
}
# Allow UDP egress on all ports
outbound_rule {
protocol = "udp"
port_range = "1-65535"
destination_addresses = ["0.0.0.0/0", "::/0"]
}
}
# Namecheap
# My primary site.
resource "namecheap_domain_records" "lukeDotKiwi" {
domain = "luke.kiwi"
# We let CloudFlare handle DNS records for luke.kiwi, thus there are no records here.
nameservers = [
"dave.ns.cloudflare.com",
"naya.ns.cloudflare.com"
]
}
# Redirects to luke.kiwi.
resource "namecheap_domain_records" "lukeifyDotCom" {
domain = "lukeify.com"
# URL redirect record via 301 Moved Permanently. Internally this is handled by pointing an A record at NameCheap's
# servers, which handles the redirection process.
record {
hostname = "@"
type = "URL301"
address = "https://luke.kiwi"
}
}
# Domain for email addresses. A parking page is used for this domain to ensure registration is possible on sites
# which check for the presence of an A record (yes, this happens).
resource "namecheap_domain_records" "hiddenDomain07bed711" {
domain = var.hidden_domain_07bed711
email_type = "MX"
mode = "OVERWRITE"
# This domain is used by SimpleLogin and DNS records are managed by NameCheap.
record {
hostname = "dkim._domainkey"
type = "CNAME"
address = "dkim._domainkey.simplelogin.co."
}
record {
hostname = "dkim02._domainkey"
type = "CNAME"
address = "dkim02._domainkey.simplelogin.co."
}
record {
hostname = "dkim03._domainkey"
type = "CNAME"
address = "dkim03._domainkey.simplelogin.co."
}
record {
hostname = "www"
type = "CNAME"
address = "parkingpage.namecheap.com."
}
record {
hostname = "@"
type = "TXT"
address = "v=spf1 include:simplelogin.co ~all"
}
record {
hostname = "_dmarc"
type = "TXT"
address = "v=DMARC1; p=quarantine; pct=100; adkim=s; aspf=s"
}
record {
hostname = "@"
type = "MX"
address = "mx1.simplelogin.co."
mx_pref = 10
}
record {
hostname = "@"
type = "MX"
address = "mx2.simplelogin.co."
mx_pref = 20
}
}
# Alternate domain for email addresses. Not currently used as such though—a redirect is in place to the primary email
# address domain.
resource "namecheap_domain_records" "hiddenDomain22c5fdd4" {
domain = var.hidden_domain_22c5fdd4
record {
hostname = "@"
type = "URL301"
address = "http://${var.hidden_domain_07bed711}"
}
}
# Project domain. Nothing here yet.
resource "namecheap_domain_records" "hiddenDomaine891f9e5" {
domain = var.hidden_domain_e891f9e5
}
# CloudFlare
import {
to = cloudflare_account.cf_account
id = "ad114eed4b21db1288538f9267525b0a"
}
resource "cloudflare_account" "cf_account" {
name = "${var.cloudflare_email_address}'s Account"
type = "standard"
}
import {
to = cloudflare_zone.lukeDotKiwiZone
id = "6d6fb052dbc4e7172304403a026cf478"
}
resource "cloudflare_zone" "lukeDotKiwiZone" {
account = {
id = cloudflare_account.cf_account.id
}
name = "luke.kiwi"
type = "full"
}
resource "cloudflare_zone_dnssec" "lukeDotKiwiDnssecConfiguration" {
zone_id = cloudflare_zone.lukeDotKiwiZone.id
dnssec_multi_signer = true
status = "active"
}
# A record
resource "cloudflare_dns_record" "lukeDotKiwiARecord" {
zone_id = cloudflare_zone.lukeDotKiwiZone.id
name = "@"
content = digitalocean_droplet.lukeify.ipv4_address
type = "A"
ttl = 1
proxied = true
}
# www.luke.kiwi CNAME Record
resource "cloudflare_dns_record" "lukeDotKiwiHsCnameRecord" {
zone_id = cloudflare_zone.lukeDotKiwiZone.id
name = "hs"
content = "luke.kiwi"
type = "CNAME"
ttl = 1
proxied = true
}
# hs.luke.kiwi CNAME Record
resource "cloudflare_dns_record" "lukeDotKiwiWwwCnameRecord" {
zone_id = cloudflare_zone.lukeDotKiwiZone.id
name = "www"
content = "luke.kiwi"
type = "CNAME"
ttl = 1
proxied = true
}
# direct.luke.kiwi CNAME Record
resource "cloudflare_dns_record" "lukeDotKiwiDirectCnameRecord" {
zone_id = cloudflare_zone.lukeDotKiwiZone.id
name = "direct"
content = "luke.kiwi"
type = "CNAME"
ttl = 1
proxied = false
}
module "simplelogin_luke_dot_kiwi_records" {
source = "./modules/simplelogin_email_dns_records"
zone_id = cloudflare_zone.lukeDotKiwiZone.id
domain = "luke.kiwi"
}
module "simplelogin_jobs_dot_luke_dot_kiwi_records" {
source = "./modules/simplelogin_email_dns_records"
zone_id = cloudflare_zone.lukeDotKiwiZone.id
domain = "luke.kiwi"
subdomain = "jobs"
}
module "simplelogin_acme_dot_luke_dot_kiwi_records" {
source = "./modules/simplelogin_email_dns_records"
zone_id = cloudflare_zone.lukeDotKiwiZone.id
domain = "luke.kiwi"
subdomain = "acme"
}