Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit d9b96d0

Browse files
committed
uses variables to templatize dns, ses resources
1 parent 4a44dbb commit d9b96d0

File tree

3 files changed

+133
-54
lines changed

3 files changed

+133
-54
lines changed

terraform/dns.tf

Lines changed: 39 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,144 +1,132 @@
1-
resource "aws_route53_zone" "speakforme-in" {
2-
name = "speakforme.in"
1+
resource "aws_route53_zone" "campaign-domain" {
2+
name = "${var.campaign-domain}"
33

4-
tags {
5-
Environment = "production"
4+
tags = {
5+
Environment = "${var.campaign-env}"
66
terraform = true
77
}
88
}
99

1010
resource "aws_route53_record" "campaign-a" {
11-
zone_id = "${aws_route53_zone.speakforme-in.id}"
12-
name = "campaign.speakforme.in"
11+
zone_id = "${aws_route53_zone.campaign-domain.id}"
12+
name = "${var.campaign-a-domain}"
1313
type = "A"
1414
ttl = "300"
15-
records = ["34.199.252.2"]
16-
}
17-
18-
locals {
19-
postal-server-ip = "18.211.250.184"
15+
records = "${var.campaign-a-ip}"
2016
}
2117

2218
resource "aws_route53_record" "postal-mx-a" {
23-
zone_id = "${aws_route53_zone.speakforme-in.id}"
19+
zone_id = "${aws_route53_zone.campaign-domain.id}"
2420
name = "mx.postal"
2521
type = "A"
2622
ttl = "300"
27-
records = ["${local.postal-server-ip}"]
23+
records = "${var.postal-server-ip}"
2824
}
2925

3026
resource "aws_route53_record" "postal-a" {
31-
zone_id = "${aws_route53_zone.speakforme-in.id}"
27+
zone_id = "${aws_route53_zone.campaign-domain.id}"
3228
name = "postal"
3329
type = "A"
3430
ttl = "300"
35-
records = ["${local.postal-server-ip}"]
31+
records = "${var.postal-server-ip}"
3632
}
3733

3834
resource "aws_route53_record" "postal-rp-a" {
39-
zone_id = "${aws_route53_zone.speakforme-in.id}"
35+
zone_id = "${aws_route53_zone.campaign-domain.id}"
4036
name = "rp.postal"
4137
type = "A"
4238
ttl = "300"
43-
records = ["${local.postal-server-ip}"]
39+
records = "${var.postal-server-ip}"
4440
}
4541

4642
resource "aws_route53_record" "postal-sf-a" {
47-
zone_id = "${aws_route53_zone.speakforme-in.id}"
43+
zone_id = "${aws_route53_zone.campaign-domain.id}"
4844
name = "sf.postal"
4945
type = "A"
5046
ttl = "300"
51-
records = ["${local.postal-server-ip}"]
47+
records = "${var.postal-server-ip}"
5248
}
5349

5450
resource "aws_route53_record" "storage-a" {
55-
zone_id = "${aws_route53_zone.speakforme-in.id}"
51+
zone_id = "${aws_route53_zone.campaign-domain.id}"
5652
name = "storage"
5753
type = "A"
5854
ttl = "300"
59-
records = ["35.153.240.239"]
55+
records = "${var.storage-a-ip}"
6056
}
6157

6258
resource "aws_route53_record" "speakforme-a" {
63-
zone_id = "${aws_route53_zone.speakforme-in.id}"
59+
zone_id = "${aws_route53_zone.campaign-domain.id}"
6460
name = "speakforme.in"
6561
type = "A"
6662
ttl = "300"
67-
records = ["104.198.14.52"]
63+
records = "${var.speakforme-a-ip}"
6864
}
6965

7066
// CNAME Records
7167

7268
resource "aws_route53_record" "beta-cname" {
73-
zone_id = "${aws_route53_zone.speakforme-in.id}"
69+
zone_id = "${aws_route53_zone.campaign-domain.id}"
7470
name = "beta"
7571
type = "CNAME"
7672
ttl = "1800"
77-
records = ["speakforme.github.io."]
73+
records = "${var.beta-cname}"
7874
}
7975

8076
resource "aws_route53_record" "netlify-cname" {
81-
zone_id = "${aws_route53_zone.speakforme-in.id}"
77+
zone_id = "${aws_route53_zone.campaign-domain.id}"
8278
name = "netlify"
8379
type = "CNAME"
8480
ttl = "1800"
85-
records = ["speakforme.netlify.com."]
81+
records = "${var.netlify-cname}"
8682
}
8783

8884
resource "aws_route53_record" "psrp-email-cname" {
89-
zone_id = "${aws_route53_zone.speakforme-in.id}"
85+
zone_id = "${aws_route53_zone.campaign-domain.id}"
9086
name = "psrp.email"
9187
type = "CNAME"
9288
ttl = "1800"
93-
records = ["rp.postal.speakforme.in."]
89+
records = "${var.psrp-email-cname}"
9490
}
9591

9692
resource "aws_route53_record" "psrp-cname" {
97-
zone_id = "${aws_route53_zone.speakforme-in.id}"
93+
zone_id = "${aws_route53_zone.campaign-domain.id}"
9894
name = "psrp"
9995
type = "CNAME"
10096
ttl = "1800"
101-
records = ["rp.postal.speakforme.in."]
97+
records = "${var.psrp-cname}"
10298
}
10399

104100
resource "aws_route53_record" "www" {
105-
zone_id = "${aws_route53_zone.speakforme-in.id}"
101+
zone_id = "${aws_route53_zone.campaign-domain.id}"
106102
name = "www"
107103
type = "CNAME"
108104
ttl = "1800"
109-
records = ["speakforme.netlify.com."]
105+
records = "${var.www-cname}"
110106
}
111107

112108
// MX Records
113109
resource "aws_route53_record" "email-mx" {
114-
zone_id = "${aws_route53_zone.speakforme-in.id}"
115-
name = "email"
110+
zone_id = "${aws_route53_zone.campaign-domain.id}"
111+
name = "${var.email-mx-name}"
116112
type = "MX"
117113
ttl = "60"
118-
119-
records = [
120-
"10 inbound-smtp.eu-west-1.amazonaws.com.",
121-
]
114+
records = "${var.email-mx-record}"
122115
}
123116

124117
resource "aws_route53_record" "routes-mx" {
125-
zone_id = "${aws_route53_zone.speakforme-in.id}"
126-
name = "routes"
118+
zone_id = "${aws_route53_zone.campaign-domain.id}"
119+
name = "${var.routes-mx-name}"
127120
type = "MX"
128121
ttl = "1800"
129-
130-
records = [
131-
"10 mx.postal.speakforme.in.",
132-
]
122+
records = "${var.routes-mx-record}"
133123
}
134124

125+
135126
resource "aws_route53_record" "speakforme-mx" {
136-
zone_id = "${aws_route53_zone.speakforme-in.id}"
137-
name = "speakforme.in"
127+
zone_id = "${aws_route53_zone.campaign-domain.id}"
128+
name = "${var.speakforme-mx-name}"
138129
type = "MX"
139130
ttl = "1800"
140-
141-
records = [
142-
"10 mx.postal.speakforme.in.",
143-
]
131+
records = "${var.speakforme-mx-record}"
144132
}

terraform/ses.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ resource "aws_ses_receipt_rule" "store-and-acknowledge" {
1010
// Emails must be bcc'd to this email address
1111
recipients = [
1212
// This supports bcc+(campaign-target-code) as well
13-
"bcc@email.speakforme.in",
13+
"bcc@${var.email-mx-name}.${var.campaign-domain}",
1414

1515
// This is just so that we can verify this in SES as a sending email address
16-
"info@email.speakforme.in",
16+
"info@${var.email-mx-name}.${var.campaign-domain}",
1717
]
1818

1919
// We don't need no AV scans
2020
scan_enabled = false
2121

2222
// Store Then Process
2323
s3_action {
24-
bucket_name = "speakforme-emails"
24+
bucket_name = "${var.email-bucket}"
2525
position = 1
2626
}
2727

terraform/vars.tf

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
variable "campaign-a-ip" {
2+
type = "list"
3+
default = ["34.199.252.2"]
4+
}
5+
6+
variable "campaign-domain" {
7+
default = "speakforme.in"
8+
}
9+
10+
variable "campaign-env" {
11+
default = "production"
12+
}
13+
14+
variable "campaign-a-domain" {
15+
default = "campaign.speakforme.in"
16+
}
17+
18+
variable "postal-server-ip" {
19+
type = "list"
20+
default = ["18.211.250.184"]
21+
}
22+
23+
variable "storage-a-ip" {
24+
type = "list"
25+
default = ["35.153.240.239"]
26+
}
27+
28+
variable "speakforme-a-ip" {
29+
type = "list"
30+
default = ["104.198.14.52"]
31+
}
32+
33+
variable "beta-cname" {
34+
type = "list"
35+
default = ["speakforme.github.io."]
36+
}
37+
38+
variable "netlify-cname" {
39+
type = "list"
40+
default = ["speakforme.netlify.com."]
41+
}
42+
43+
variable "psrp-email-cname" {
44+
type = "list"
45+
default = ["rp.postal.speakforme.in."]
46+
}
47+
48+
variable "psrp-cname" {
49+
type = "list"
50+
default = ["rp.postal.speakforme.in."]
51+
}
52+
53+
variable "www-cname" {
54+
type = "list"
55+
default = ["speakforme.netlify.com."]
56+
}
57+
58+
variable "email-mx-record" {
59+
type = "list"
60+
default = ["10 inbound-smtp.eu-west-1.amazonaws.com."]
61+
}
62+
63+
variable "email-mx-name" {
64+
default = "email"
65+
}
66+
67+
variable "routes-mx-record" {
68+
type = "list"
69+
default = ["10 mx.postal.speakforme.in."]
70+
}
71+
72+
variable "routes-mx-name" {
73+
default = "routes"
74+
}
75+
76+
variable "speakforme-mx-name" {
77+
default = "speakforme.in"
78+
}
79+
80+
variable "speakforme-mx-record" {
81+
type = "list"
82+
default = ["10 mx.postal.speakforme.in."]
83+
}
84+
85+
variable "infrastructure-bucket" {
86+
default = "speakforme-infrastructure"
87+
}
88+
89+
variable "email-bucket" {
90+
default = "speakforme-emails"
91+
}

0 commit comments

Comments
 (0)